Splitting¶
You can split strings.
Here we might write a function to get the first letters of each word:
str := "hello world"
define (foo s) {
map (function (w) {
w.0
}) s.split-string
}
printf "%s\n" str.foo ; (#\h #\w)
printf "%s\n" str.foo.2 ; w
Here, there is a cascade of implied calls:
str.fooisstrbeing “indexed” byfoowhich is a function and therefore is actuallyfoo strfoocalls map with:s.split-stringwhich issbeing “indexed” by split-string and is thereforesplit-string ssplit-stringuses IFS which defaults to" \t\n"that splits the original string into words
the anonymous function given to
mapreturnsw.0which iswindexed by0Here,
wis a string, each word fromstr.split-string, and we are returning the first code point from that word
Note
The .2 in the str.foo.2 is accessing the second element of
a list. Strings and array are indexed from 0 (zero) but lists from
their first element.
Last built at 2026-01-04T22:40:02Z+0000 from da47fd3 (dev)