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.foo is str being “indexed” by foo which is a function and therefore is actually foo str

  • foo calls map with:

    • s.split-string which is s being “indexed” by split-string and is therefore split-string s

      • split-string uses IFS which defaults to " \t\n"

        that splits the original string into words

    • the anonymous function given to map returns w.0 which is w indexed by 0

      Here, w is a string, each word from str.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)