std/lists
Phrases
lists.Size [l: list of value]
Number of items
- Gives
- number
- Contexts
- node, main, check, look
- Kind
- phrase, native
- Source
- lists/lists.synod:3
- Examples
- lists/build, lists/pick
lists.Append [x: value] to [l: list of value]
A copy of l with x added at the end
- Gives
- same as `l`
- Contexts
- node, main, check, look
- Kind
- phrase, native
- Source
- lists/lists.synod:6
- Examples
- lists/build
lists.Extend [a: list of value] with [b: list of value]
A copy of a followed by every item of b
- Gives
- same as `a`
- Contexts
- node, main, check, look
- Kind
- phrase, native
- Source
- lists/lists.synod:9
- Examples
- lists/build
lists.Without [x: value] from [l: list of value]
A copy without any item equal to x
- Gives
- same as `l`
- Contexts
- node, main, check, look
- Kind
- phrase, native
- Source
- lists/lists.synod:12
- Examples
- lists/build
lists.Take [n: number] from [l: list of value]
The first n items (fewer if the list is shorter)
- Gives
- same as `l`
- Contexts
- node, main, check, look
- Kind
- phrase, native
- Source
- lists/lists.synod:15
- Examples
- lists/pick
lists.Range [a: number] to [b: number]
Whole numbers from a to b, inclusive; empty when a is more than b
- Gives
- list of number
- Contexts
- node, main, check, look
- Kind
- phrase, native
- Source
- lists/lists.synod:18
- Examples
- lists/pick
lists.Sort [l: list of value]
Ascending; items must all be numbers, all times or all text
- Gives
- same as `l`
- Contexts
- node, main, check, look
- Kind
- phrase, native
- Source
- lists/lists.synod:21
- Examples
- lists/pick
Examples
build
Shows lists.Append, lists.Extend, lists.Without and lists.Size: each gives a new list
# package main
# Shows lists.Append, lists.Extend, lists.Without and lists.Size: each gives a new list
use std/lesson
use std/lists
use std/sim
use std/text
define main
set base to {"a", "b"}
set longer to (lists.Append "c" to base)
set both to (lists.Extend longer with {"d", "e"})
set fewer to (lists.Without "b" from both)
lesson.Note (text.Join {"base ", (text.From (lists.Size base)), ", longer ", (text.From (lists.Size longer)), ", both ", (text.From (lists.Size both)), ", fewer ", (text.From (lists.Size fewer))})
sim.StopAt 1s
pick
Shows lists.Range, lists.Take and lists.Sort: build a list of numbers, sort a list, keep the first items
# package main
# Shows lists.Range, lists.Take and lists.Sort: build a list of numbers, sort a list, keep the first items
use std/lesson
use std/lists
use std/sim
use std/text
define main
set days to (lists.Range 1 to 7)
set firstThree to (lists.Take 3 from days)
set sorted to (lists.Sort {"pear", "apple", "fig"})
lesson.Note (text.Join {"days ", (text.From (lists.Size days)), ", first ", (text.From (item 2 of firstThree))})
lesson.Note (text.Join {"sorted: ", (item 0 of sorted), " ", (item 1 of sorted), " ", (item 2 of sorted)})
sim.StopAt 1s