Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It’s just like C or JS but the first paren goes to the left of the function name.


With function calls, yes.

What makes it different is that syntactic constructs are also expressed with the same syntax and there is no special syntax, so control flow constructs use a syntax similar to function calls.

This is particularly exuberant in Arc where what in many languages would be:

    if        (<cond1>) {
      <then expr1>
    } else if (<cond2>) {
      <then expr2>
    } else if (<cond3>) {
      <then expr3>
    } else {
      <else expr>
    }
Would instead be:

    (if
      <cond1> <then expr1>
      <cond2> <then expr2>
      <cond3> <then expr3>
      <else expr>)
Note the complete lack of syntax beyond a keyword having 7 arguments in order, which many find nonconsecutive to reading, and also error prone as accidentally making a typo can completely change the meaning of the program.

It is thus that most Lisps have somewhat more redundant syntax:

    (cond
      [<cond1> <then expr1>]
      [<cond2> <then expr2>]
      [<cond3> <then expr3>]
      (else    <else expr>))
Personally, I wouldn't mind that a mandatory `->` be required in between the conditions and the expression to further guard against accidental typos. I find that redundancy in syntax guards against accidental mistakes, though I have nothing against the parentheses and in fact favor them.


Pattern matching in rust:

  match x {
      <cond1> => <expr1>,
      <cond2> => <expr2>,
      <cond3> => <expr3>,
      _ => <expr>,
  } 

  let message = match maybe_digit {
      Some(x) if x < 10 => process_digit(x),
      Some(x) => process_other(x),
      None => panic!(),
  };
Seems useful. Python's getting match soon too!

https://doc.rust-lang.org/reference/expressions/match-expr.h...


Clojure specifically doesn't have the bracket wrapper around condition-expression pairs but syntax highlighting/ formatting considers it and aligns stuff nicely. I don't think, it is a problem that it basically is a list or function call with arguments. I do think, adding `->` just like that would be a problem because it would be very inconsistent with the syntax of Clojure.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: