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

I drafted a long comment with examples of how you could, perhaps, seriously make s-expressions more readable by not using nested parens.. but decided to see if anyone else had given it a go, and found this: http://readable.sourceforge.net/

It includes both significant whitespace and a special in-fix notation so a factorial function could look like:

    define factorial(n)
      if {n <= 1}
        1
        {n * factorial{n - 1}}


While I suspect most Lispers are shaking their heads and muttering, I actually like this. Seems to preserve the benefits of homoiconicity while reading more like natural language.

I would try it if there were a Clojure-compatible flavor (the {} conflicts with hashmap syntax) with a Leiningen plugin to convert it to regular Clojure when building. Kind of a CoffeeScript to Clojure's JS.

Edit:

Wait a sec, how does it know to prepend an open paren to the second line (the if) but not to the third line (body of the if)? Each one is indented. Does it have special, hardcoded knowledge of the 'if' form?

This looks a little problematic to me because the preprocessing isn't following an obvious rule. It brings to mind the big downside of CoffeeScript — the cleverness required to allow such natural-looking code can also lead to unexpected results in edge cases.


Rule is straightforward – if there is stuff one indentation level deeper, prepend parens.


That doesn't explain the third line. Your rule would result in

    (if condition
      (1)
      (else-clause))
trying to call 1 as a function, which is an error.


No, there is nothing one indentation level deeper than 1, so it should have no parens according to the rule.


Ah, your wording was ambiguous. I thought you meant, in this situation:

    ...
      X
        Y
    ...
since Y is one indentation level deeper than X, prepend parens to Y. But you meant "since there exists Y such that Y is one indentation level deeper than X, prepend parens to X".


I think everyone comes up with some sort of alternative whitespace syntax when they first see a Lisp. I know I did. Unfortunately, you lose Lisp's most powerful property--homoiconicity.




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

Search: