3 ms·
TL;DR: Because it uses a minimal representation for data (S expressions). This makes it much easier to write representations of data (compared to XML, or even
by AnimalMuppet 5y ago
TL;DR: Because it uses a minimal representation for data (S expressions). This makes it much easier to write representations of data (compared to XML, or even JSON). This makes it easier to represent code as data, and that opens up the whole world.
- chmaynard 5y agoYes, but read the post anyway.
- AnimalMuppet 5y agoAgreed. It's worth reading. My TL;DR was not meant to imply that it wasn't.
- kazinator 5y agoPlus, that can be in addition to having JSON too. This is the TXR Lisp interactive listener of TXR 271. Quit with :quit or Ctrl-D on an empty line. Ctrl-X ? for cheatsheet. 1> '#J{"foo":[1,2,3,"bar"]} #J{"foo":[1,2,3,"bar"]} What is that literal syntax? 2> (typeof '#J{"foo":[1,2,3,"bar"]}) cons cons-cell based object under the hood. 3> (car '#J{"foo":[1,2,3,"bar"]}) json 4> (cadr '#J{"foo":[1,2,3,"bar"]}) quote It has a (json quote ...) structure. 5> (caddr '#J{"foo":[1,2,3,"bar"]}) #H(() ("foo" #(1.0 2.0 3.0 "bar"))) Followed by a hash table object. We can convert that to a vector to see it all: 6> (vec-list '#J{"foo":[1,2,3,"bar"]}) #(json quote #H(() ("foo" #(1.0 2.0 3.0 "bar")))) Now actually eval it instead of quoting 7> #J{"foo":[1,2,3,"bar"]} #H(() ("foo" #(1.0 2.0 3.0 "bar"))) The embedded hash table denoted by the literal is regurgitated. We can quasiquote JSON: ;; ^ is quasiquote in this dialect not ` 1> ^(,(+ 2 2) ,(list 1 2 3)) (4 (1 2 3)) ;; cannot use , in JSON for unquoting, so ~ is used: 2> ^#J["foo", ~(+ 2 2.0)] #J["foo",4] The quasiquote can be pattern-matched: 3> (match ^#J[~x, ~y] #(1.0 "foo") (list x y)) (1.0 "foo") Or, using JSON syntax on the right side, which produces the same vector: 4> (match ^#J[~x, ~y] #J[1.0, "foo"] (list x y)) (1.0 "foo")
- throw10920 5y agoExactly - it's not about whether it's possible to represent code as data (gcc is written in C, after all), it's about how easy it is. That's why Rust macros still don't come close to Lisp ones.