Live data from Hacker News

S-expressions

igor.io

11–20 of 46 posts

Re: S-expressions

#11
Why are the keywords written with a quote?

> (keywords '(useless microframework academic swag))

Shouldn't it be a list with strings or something? What if the keywords were complex structures not just strings?

Re: S-expressions

#12
post #7

Was the use of dict and list necessary? This is an actual question, not a rhetorical criticism. I have recently been trying to learn common lisp.

Using dict and list here preserves the dynamic nature of JSON. If you have some sort of schema - which in reality you probably would have, even using JSON - that implies dict and list you wouldn't need to use those.

Re: S-expressions

#13

Why are the keywords written with a quote? > (keywords '(useless microframework academic swag)) Shouldn't it be a list with strings or something? What if the keywords were complex structures not just strings?

if it's not quoted the list will be treated as an expression, and evaluate "Useless", which is probably not what you want.

Re: S-expressions

#14
> Side note: Wouldn't it be awesome if composer supported composer.sexpr files natively, so that we would no longer have to write JSON? No, not really.

Why the quick dismissal? I find s-expressions much easier to work with than JSON.

Re: S-expressions

#15
post #13

Why are the keywords written with a quote? > (keywords '(useless microframework academic swag)) Shouldn't it be a list with strings or something? What if the keywords were complex structures not just strings?

if it's not quoted the list will be treated as an expression, and evaluate "Useless", which is probably not what you want.

Right so instead you'd write: keywords (list "a" "b") ? Which would let you also do complex things like (list (person "bob") ...)

Re: S-expressions

#17

Why are the keywords written with a quote? > (keywords '(useless microframework academic swag)) Shouldn't it be a list with strings or something? What if the keywords were complex structures not just strings?

The only Lisp I know is Racket (basically Scheme), so take the following with a grain of salt.

'(foo bar baz) is almost the same thing as (list foo bar baz). However, ' also makes the contents of the list into symbols, not variable references. Basically, '(foo bar baz) returns (list 'foo 'bar 'baz), not a list containing the values of the variables foo, bar, and baz.

Symbols aren't much like strings. They're immutable, and actually just refer to a unique number, not characters. I hope that sort of makes sense!

Re: S-expressions

#18
post #13

Earlier quoted context omitted.

if it's not quoted the list will be treated as an expression, and evaluate "Useless", which is probably not what you want.

Right so instead you'd write: keywords (list "a" "b") ? Which would let you also do complex things like (list (person "bob") ...)

[deleted]

Re: S-expressions

#19
post #7

Was the use of dict and list necessary? This is an actual question, not a rhetorical criticism. I have recently been trying to learn common lisp.

It is if you want to differentiate between a list of lists and a map. Maps are not natively supported in s-expressions.

So there is a need to create a sub-language to handle special data structures.

I have done this as well. But I use a special namespace '#dict' for example. So it would be

    (#dict (k1 v1) (k2 v2))
This way there is less of a chance of collision between data and this sub-language. It also allows for extension, so for example instead of dict you can use #classname to say persist a perticular object of a given class name (json doesn't allow this, there would have to add a '__classname__' key to the object for example.

Another way of doing it is using a flat list and just using an alternation with keys being prefixed by some special character:

   (:k1 v1 :k2 v2)
I think Clojure and some lisps do that...
Post reply on HN