langur

lists

List literals are built with square brackets that are clearly not an indexing operator.

Lists may contain any other langur data structures, and they may be mixed freely.

Lists may be appended with the concatenation operator (tilde) or with the more() function. Like concatenation, the more() function creates a new list and does not modify the original.

[1, 2, 3] ~ [4, 5, 6, 7] == [1, 2, 3, 4, 5, 6, 7] # true

free word lists

As a semantic convience, string lists may use a shortened syntax, beginning with a letter fw (interpreting escape codes) or FW (not interpreting escape codes). Quote mark pairs allowed are the same as for string and regex literals.

A free word list uses spacing to separate word strings. This is similar to the qw() construct used in Perl.

fw/1 2 3 you know/ == ["1", "2", "3", "you", "know"]

fw/1 2 3 you\x20know/ == ["1", "2", "3", "you know"]

FW/1 2 3 you\x20know/ == ["1", "2", "3", "you\\x20know"]

You can use blockquotes for free word lists (see strings).

A free word list not using a blockquote cannot include line returns.

Allowed characters are the same as for string literals.

Interpolation is not valid, so there is no $fw// or $FW// literal.

list no-op token

You can use an list of functions and no-ops with the map() function, as in the following example.

val .isbn13checkdigit = fn(var .s) { .s = replace(.s, RE/[\- ]/) matching(re/^[0-9]{13}$/, .s) and fold(fn{+}, map([_, fn{*3}], map(fn{-'0'}, s2cp .s))) rem 10 == 0 }

list generation

Besides using square brackets to generate an list, you can use the built-in arr() function. This will generate an list with a specified number of elements. Optionally, you can include a value to set each element to (default null).

You can also use list multiplication.

[1, 2, 3, 4] * 3 == [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4]

A negative number on list multiplication acts like 0 and does not throw an exception.