←back to thread

185 points todsacerdoti | 6 comments | | HN request time: 0.001s | source | bottom
Show context
userbinator ◴[] No.44506358[source]
Somewhat less frequently, I also hear "invoke" or "execute", which is more verbose but also more generic.

Incidentally, I find strange misuses of "call" ("calling a command", "calling a button") one of the more grating phrases used by ESL CS students.

replies(7): >>44506396 #>>44506421 #>>44506500 #>>44506580 #>>44510160 #>>44510878 #>>44511635 #
pansa2 ◴[] No.44506396[source]
> strange misuses of "call"

My favourite (least favourite?) is using “call” with “return”. On more than one occasion I’ve heard:

“When we call the return keyword, the function ends.”

replies(4): >>44506779 #>>44506910 #>>44506977 #>>44511912 #
jamesfinlayson ◴[] No.44506779[source]
I remember someone in university talking about the if function (which ostensibly takes one boolean argument).
replies(6): >>44506886 #>>44506915 #>>44507329 #>>44508128 #>>44509940 #>>44512872 #
Zambyte ◴[] No.44509940[source]
If takes two or three arguments, but never one. The condition is the one made syntactically obvious in most languages, the consequent is another required argument, and the alternative is optional.
replies(1): >>44510291 #
dylan604 ◴[] No.44510291[source]
Huh? if (true) {} takes precisely one argument.
replies(1): >>44510378 #
1. mjburgess ◴[] No.44510378[source]
That's an application of `if` with one of the arguments empty.

The semantics of `if` requrie at least, `if(cond, clause)`, though more generally, `if(cond, clause, else-clause)`

replies(1): >>44510682 #
2. devnullbrain ◴[] No.44510682[source]
You and Zambyte are both doing the same thing the top level comment is complaining about.

e.g. in C:

https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3220.pdf

    (6.8.5.1) selection-statement:
      if ( expression ) secondary-block
      if ( expression ) secondary-block else secondary-block
in C++:

https://eel.is/c++draft/gram.stmt

    selection-statement:
      if constexpropt ( init-statementopt condition ) statement
      if constexpropt ( init-statementopt condition ) statement else statement
      if !opt consteval compound-statement
      if !opt consteval compound-statement else statement
where

    condition:
      expression
      attribute-specifier-seqopt decl-specifier-seq declarator brace-or-equal-initializer
      structured-binding-declaration initializer 
More examples:

https://docs.python.org/3/reference/grammar.html

https://doc.rust-lang.org/reference/expressions/if-expr.html...

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

expression != argument

replies(1): >>44510881 #
3. smilliken ◴[] No.44510881[source]
They aren't talking about C and its descendants in particular, but more generally. For example in Haskell and Scheme there is only an if function and no if statement. And you're welcome to create an if function in any language you like and use it instead of the native syntax. I like to use an if function in PostgreSQL because it's less cumbersome than a case expression.

So in the abstract, if is a ternary function. I think the original comment was reflecting on how "if (true) ... " looks like a function call of one argument but that's obviously wrong.

replies(2): >>44511305 #>>44511773 #
4. devnullbrain ◴[] No.44511305{3}[source]
Arguments are expressions in Haskell. In abstract, it uses expressions.
5. disconcision ◴[] No.44511773{3}[source]
this is not quite right. haskell and scheme have if expressions, not if statements. that's not the same as if being a function. if is not, and cannot be, a function in scheme, as it does not have scheme function semantics. specifically, it is not strict, as it does not evaluate all its subexpressions before executing. since haskell is non-strict, if can be implemented as a function, and iirc it is
replies(1): >>44512138 #
6. trealira ◴[] No.44512138{4}[source]
> since haskell is non-strict, if can be implemented as a function, and iirc it is

"If" can be implemented as a function in Haskell, but it's not a function. You can't pass it as a higher-order function and it uses the "then" and "else" keywords, too. But you could implement it as a function if you wanted:

  if' :: Bool -> a -> a
  if' True x _ = x
  if' False _ y = y
Then instead of writing something like this:

  max x y = if x > y then x else y
You'd write this:

  max x y = if' (x > y) x y
But the "then" and "else" remove the need for parentheses around the expressions.