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

Dunno if I'm in the minority, but I just can't warm to [], either in lieu of or augmenting, () in SEXPRs. Just never felt they were necessary and, if anything, I find them distracting. Likely because I'm not used to them (baby duck syndrome and all), but the regularity of Lisp syntax, to me, is a boon, and the [] just mess that up for me.


Reader macros/literals allow for explicitly differentiating between built-in data types, and provide semantic meaning to otherwise indistinguishable forms. For example, defining a function:

In Racket, you write `(define (foo arg1 arg2) (+ arg1 arg2))`. Why isn’t `(foo arg1 arg2)` evaluated as a function? It’s a list and it isn’t quoted, so it should be evaluated. However, `define` is a macro (I think, might be a special form), so that list isn’t evaluated and doesn’t have to be quoted. That violates the basic tenant of “unquoted forms wrapped in a list are evaluated as fiction calls.”

In Clojure, you write `(defn foo [arg1 arg1] (+ arg1 arg2))`. The [] is a reader macro, a vector literal. It communicates that it’s not a function call but simply data (in this case, a vector containing two symbols).

Maybe I’m just used to it but I find this stuff really helpful.


I would agree more with this view if there was also an explicit indicator for lazyness: in (define (foo arg1 arg2) (+ arg1 arg2)) the two parts (foo arg1 arg2) and (+ arg1 arg2) are both interpreted specially; the former as a data structure and the latter as code with delayed execution.


It was in Scheme so that the defined function form looks like a function call. It's a feature.


Agreed.

Using square brackets in place of some parens is something some of the Racket professors started doing. I assumed it was because they thought it would be helpful to teach high school students in http://htdp.org/ . I defer to them on teaching, but I think it looks ugly, is harder to type, and seems like it's more confusing in code examples (people thinking it's significant, when it's not).

One thing I did do is make an Emacs mode, https://www.neilvandyke.org/quack/ , in which typing square brackets instead inserts parentheses when appropriate. This is helpful on US keyboards, on which parens require a multi-key press but square brackets do not.


square brackets was already used in Scheme and even in Interlisp...


Yeah, in R6RS square brackets are considered to be perfectly interchangeable with regular parentheses. That decision was reversed for R7RS-small, though.


It's much older. Here is a (legendary) paper on Lisp using Scheme with square brackets from 1983.

https://dl.acm.org/doi/pdf/10.1145/800017.800513

Interlisp used it in the 70 already.


I find them very useful in the way Racket uses them, which is by convention only. In Racket, `[<expression>]` is identical to `(<expression>)`. But Racket uses them in a conventional sense, for example, in `let` bindings:

    (define test
      (let ([a 1]
            [b 2])
        (+ a b)))


Same here. It obscures the notion of code is data, data is code.


[] as a quoted list shows up occasionally. [foo bar] vs '(foo bar). I think I prefer that but it's hard to be sure.




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

Search: