> (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?
11–20 of 46 posts
> (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?
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.
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?
Why the quick dismissal? I find s-expressions much easier to work with than JSON.
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.
Parsing S-expressions is easy: Dijkstra solved it in a really nice way with the Shunting Yard Algorithm.
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?
'(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!
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") ...)
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.
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...If you, too, think this would be awesome, check out extensible data notation: https://github.com/edn-format/edn.