Skip to content

Latest commit

 

History

History
45 lines (38 loc) · 970 Bytes

04-pairs-lists-and-dicts.md

File metadata and controls

45 lines (38 loc) · 970 Bytes

→ README, → prev: Primitive Data Types, → next: Functions

Pairs, Lists & Dicts

NB: list literals have the head on the left.

>>> :answer 42 =>                 ; key/value pair
:answer 42 =>
>>> ,dup
>>> .key                          ; field access
:answer
>>> ,drop
>>> .value
42
>>> answer: 42                    ; syntactic sugar
:answer 42 =>

>>> ( 1 2 :foo 4 )                ; linked list (parentheses)
( 1 2 :foo 4 )
>>> ,dup
>>> len
4
>>> ,drop
>>> 2 get^                        ; indexing
:foo
>>> () empty?
#t

>>> { x: 42, :y 99 1 + => }       ; dict: key/value map (curly brackets)
{ :x 42 =>, :y 100 => }
>>> ,dup
>>> len
2
>>> ,drop
>>> :x get^                       ; indexing
42