on 6d45ede help sign in
40 lines 1.4 kB history raw
1---
2navhome: /docs
3sort: 3
4comments: true
5---
7# Lists
9In the following exercises, let `l` be `` `(list @t)`['u' 'r' 'b'
10'i' 't' ~]``
121. A list is a null-terminated tuple of values. For example,
13 `[1 2 3 ~]` is a list of three integers, and
14 `['a' 'b' 'c' ~]` is a list of three cords. Try casting
15 `['a' 'b' 'c' ~]` to `(list @t)` and to `(list @)`. Lists
16 are parameterized with the type of the values.
181. `++flop` takes a list and produces its reverse. Use it to
19 reverse `l`.
211. Repeat the above exercise without using `++flop`.
231. `++sort` takes a list and a comparison function to sort a
24 list. The function must take two elements of the list and
25 produce true if the first element is "less than" the other.
26 Sort `l` alphabetically. Sort it reverse alphabetically.
281. `++turn` takes a list and a function and applies the function
29 to each element in the list, forming a new list of the
30 results. This is called "map" in many functional languages.
31 The function must accept an element of the list. Use the
32 fact that subtracting 32 from a lowercase letter gives the
33 equivalent uppercase letter (i.e. `(sub 'a' 'A')` is 32) to
34 change every character in `l` to uppercase.
361. `++welp` concatentates two lists. Concatenate `l` with the
37 reverse of `l`.
391. `++snag` takes a number `n` and a list and produces the
40 element at index `n`. Pull out the `'i'` in `l`.