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

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.




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

Search: