Skip to content

Commit

Permalink
Guide: formaly introduce map and vector literals
Browse files Browse the repository at this point in the history
This addresses issue 452.
  • Loading branch information
asarhaddon authored and kanaka committed May 31, 2021
1 parent b89a93a commit 2bbec8a
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions process/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -473,15 +473,26 @@ and each step will give progressively more bang for the buck.
a similar prefixed translation anyways).
* vector: a vector can be implemented with same underlying
type as a list as long as there is some mechanism to keep track of
the difference. You can use the same reader function for both
the difference.
Vector literals are similar to lists, but use bracket as
delimiters instead of parenthesis.
For example, `[]` constructs an empty vector and `[1 "a"]` a
vector with two elements.
You can use the same reader function for both
lists and vectors by adding parameters for the starting and ending
tokens.
* hash-map: a hash-map is an associative data structure that maps
strings to other mal values. If you implement keywords as prefixed
strings, then you only need a native associative data structure
which supports string keys. Clojure allows any value to be a hash
map key, but the base functionality in mal is to support strings
and keyword keys. Because of the representation of hash-maps as
and keyword keys.
Hash-map literals are constructed with braces delimiters.
For example,
`{}` constructs an empty map,
`{"a" 1 :b "whatever"}` associates the `a` key to an integer value
and the `:b` key to a string value.
Because of the representation of hash-maps as
an alternating sequence of keys and values, you can probably use
the same reader function for hash-maps as lists and vectors with
parameters to indicate the starting and ending tokens. The odd
Expand Down

0 comments on commit 2bbec8a

Please sign in to comment.