3 ms·
You simply know that: ("jane" "jim") is a list, because that's the overwhelming convention in Lisp dialects. A common notation for vectors, used in Scheme a
by kazinator 10y ago
You simply know that:
("jane" "jim")
is a list, because that's the overwhelming convention in Lisp dialects. A common notation for vectors, used in Scheme and Common Lisp, is the hash-left-paren:
#(1 2 3) ;; unambiguously a vector
#() ;; empty vector
There is no standard for notating a hash table; it is dialect specific.
For instance, in the Racket language, they use #hash, #hasheq and #hasheqv prefixes: http://docs.racket-lang.org/reference/reader.html#%28part._parse-hashtable%29 http://docs.racket-lang.org/reference/reader.html#%28part._p...
The hash contents are using the same syntax as an association list (list of dotted pairs).
In TXR Lisp, I invented a different notation: a #H prefix which is followed by a compound S-expression. The first element of the S-expression is a list of optional attributes of the hash, and the remaining elements are the key-value pairs. For example:
#H((:equal-based) ("jane" "jim") ("alice" "bob"))
#H(() (:jane 3) (:jim 5) (:alice 7))
equal-based is needed if the keys are aggregate objects like strings, lists and vectors.
In Racket these would be:
#hash(("jane" . "jim") ("alice" . "bob"))
#hasheq((#:jane . 3) (#:jim . 5) (#:alice . 7)) ;; keywords are #: in Racket
If you want interoperable S-exps that include literals for associative arrays, you have to pick the way some dialect does it, or roll your own, and customize the reader accordingly.
Or else, a decent, portable solution for general data exchange is just to use association lists, like this, which use a notation that is common to many Lisp dialects:
(("jane" . "jim") ("alice" . "bob"))
Though it is not denote an optimized associative array structure, the syntax (at least when it is not empty) clearly conveys that it is associative. The software which processes this can convert it to a hash table, knowing that an associative list is expected for that datum in that position of the syntax. That is to say, we use the representation of an inefficient association list (which, if used "as is" the way it comes out of the parser implies linear searching for keys) and let the applications optimize that as they see fit.