Lists, Maps, and Sets¶
Quick Start: Spice it up with twists.
Lists, maps, and sets all ride bracketed values and live happily in flags. The one-line forms live in the cheatsheet (maps, sets).
Lists¶
Lists are bracketed values like [a, b] and live happily in flags:
<gflag:nums,[1, 2, 3]> stores one, <gflag:nums> reads it back.
Items split on top-level commas, so nested lists and quoted commas
survive. Positions start at 0, and out-of-range reads yield null:
| Tag | Meaning |
|---|---|
<len:[a,b]> |
2. |
<list.get:[a,b],1> |
b. |
<list.set:[a,b],0,z> |
[z, b] (position size appends). |
<list.append:[a],b> |
[a, b]. |
<list.remove:[a,b],a> |
[b] (first match only). |
<list.contains:[a,b],b> |
true. |
<list.pop:[a,b]> |
b, the last item. |
<list.shuffle:[a,b]> |
The items in random order. |
<list.clear:[a,b]> |
[]. |
<list.filter:[a,b],cond> |
Items whose condition resolves to true. |
<list.reverse:[a,b]> |
[b, a]. |
<list.join:[a,b],-> |
a-b. |
<list.slice:[a,b,c],1,3> |
[b, c]. |
<list.first:[a,b]> |
a (null when empty). |
<list.last:[a,b]> |
b (null when empty). |
<range:5> |
[0, 1, 2, 3, 4]; <range:1,5> starts at 1, and <range:5,0,-1> counts down. |
<l.*> |
Every op above also answers to its l.* shorthand (<l.get>, <l.append>, ...). |
Every list.* op also answers to its l.* shorthand (<l.get>,
<l.append>, ...): same implementation, same write-back, and misuse
warns name the canonical list.* op.
<range> follows Python: start inclusive, stop exclusive, step 1
unless given. Ranges past 20000 items keep the first twenty thousand
with a warning (the same cap as the loop step budget); a zero
step or a non-number warns and yields null.
The mutating ops (append, set, remove, clear, pop,
shuffle) write back when their list is a verbatim flag reference:
<list.append:<gflag:nums>,4> grows the stored flag and leaves
nothing behind. Anything else (literals, other expressions) applies
purely and returns the new list.
<list.filter:list,condition> keeps the items whose condition
resolves to true (case-blind, nothing else counts), with each
item behind <i> in turn:
<list.filter:[a,bb,abc],<str.contains:<i>,b>> is [bb, abc].
The condition re-resolves per item like a loop body and must hold
no top-level commas, so quote-free tag expressions work best; each
item spends one shared line step like a loop iteration. A non-list
warns and yields null.
<list.slice:list,start,end> follows Python: start inclusive, end
exclusive, negatives count from the end, out-of-range bounds clamp.
Non-integer bounds warn and yield null. <list.reverse> returns
a reversed copy, <list.first> and <list.last> read the ends
(null when empty), and <list.join:list,separator> joins with
the separator verbatim (it may be empty). Joining a non-list warns
and yields null.
Nested triples read inside out: with a card stored as
[[id, desc, kind], ...],
<list.get:<list.get:<lf:card>,<i>>,2> takes field 2 (kind) of slot
<i>. Bingo deals cards as [taskid, desc, kind] triples and
indexes each field positionally the same way.
Maps¶
A map is an association list [[k, v], ...] in insertion order.
Every map.* op also answers to its m.* shorthand. Keys match
verbatim and case-sensitively; a missing key reads a silent null.
| Tag | Meaning |
|---|---|
<map.get:map,key> |
Value for the key, null when missing. |
<map.add:map,key,value> |
Upsert the key, store back, empty. |
<map.set:map,key,value> |
Upsert the key, store back, empty. |
<map.remove:map,key> |
Drop the key, true/false. |
<map.contains:map,key> |
true when the key exists. |
<map.keys:map> |
Keys in order. |
<map.values:map> |
Values in order. |
<map.size:map> |
Entry count (same as <len>). |
<map.clear:map> |
Empty the map, store back. |
<m.*> |
Every op above also answers to its m.* shorthand (<m.get>, <m.set>, ...). |
add and set are identical twins: an existing key swaps its
value in place, else the pair appends. The mutating ops (add,
set, remove, clear) write back when their map is a
verbatim flag reference. Malformed pairs skip silently on reads
and survive writes in place.
Sets¶
A set rides a plain list and reads deduped in first-occurrence order. Sets carry no token alias. Membership matches verbatim and case-sensitively.
| Tag | Meaning |
|---|---|
<set.add:set,x> |
Add the member, store back, empty (dupes no-op). |
<set.remove:set,x> |
Drop the member, true/false. |
<set.contains:set,x> |
true when x is a member. |
<set.size:set> |
Member count. |
<set.clear:set> |
Empty the set, store back. |
<set.tolist:set> |
Members in order. |