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

There's a library for lisp called readable lisp. It has three features (http://readable.sourceforge.net/)

1: Indentation instead of parentheses

  (defn [a b]
    (+ a b)
  )
Becomes

  defn add [a b]
    + a b
2: Function names before the parens instead of after

  (add 3 5)
Becomes

  add(3 5)
3: Infix operations

  (+ 3 5 6)
Becomes

  {3 + 5 + 6}
(Note the curly braces instead of parens)

These combined make Lisp code a whole lot more readable:

  (define (factorial n)
    (if (<= n 1)
      1
      (* n (factorial (- n 1)))))
Becomes

  define factorial(n)
    if {n <= 1}
      1
      {n * factorial{n - 1}}
To me, this made common-lisp python-like readable. Now to get it working in Clojure


> Now to get it working in Clojure

Perhaps you've seen the macro for infix operators in Clojure: http://data-sorcery.org/2010/05/14/infix-math/

Use that and all you'd need to implement for infix ops is a parser that translates {...} to ($= ...) for any sequence ... of tokens.


Except it doesn't stop at 3. Then you have (copying from http://sourceforge.net/p/readable/wiki/Solution):

4. A \\ (aka SPLIT) starts a new line at the current indentation. If it's immediately after indentation (aka GROUP in that case), it represents no symbol at all (at that indentation) - this is useful for lists of lists.

5. A $ (aka SUBLIST) in the middle of list restarts list processing; the right-hand-side (including its sub-blocks) is the last parameter of the left-hand side (of just that line). If there's no left-hand-side, the right-hand-side is put in a list. This useful abbreviation from Haskell simplifies many common cases.

6. A leading traditional abbreviation (quote, comma, backquote, or comma-at) or datum comment "#;", at the beginning of a sweet-expression line, and followed by space or tab or end-of-line, is that operator applied to the following sweet-expression. Otherwise, it applies to the next neoteric-expression.

7. The markers “<∗” and “∗>” surround a collecting list, and MUST accept a list of 0 or more un-indented sweet-expressions. The “<∗” and “∗>” represent opening and closing parentheses, but restart indentation processing at the beginning of the line. A collecting list is only terminated by its matching “∗>” and not by a blank line. These are valuable for defining libraries and for short let-style constructs.

8. The marker “$$$” is reserved for future use.

Got all that? I sure didn't. I spent some time on the mailing list a couple of years ago and grew frustrated with this gradual creep of operators, which led to absurd code like this (from http://srfi.schemers.org/srfi-110/srfi-110.html):

  let
    \\
      c $ cos a
      s $ sin a
    body...
I mean, would it hurt to add a couple of parens here and there?! Even Java has a few of them.

(My competing proposal, which wasn't hampered by all the bending-over-backwards to preserve backwards compatibility and get merged upstream that did them in: http://akkartik.name/post/wart. The final straw that pushed me to find my own syntax was this example from SICP: http://arclanguage.org/item?id=16699)




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

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

Search: