List operations

Submitted by Phaul on Wed, 2006-08-09 13:01.
::
The most important type in OML is the list. You can use list where you are used to use arrays, structs or any kind of compound storages. There are a few list operation but they give you great flexibility in storing data. These are list, join, nth and length. The list operation produces a list from its arguments. Don't mix (list 1) with (list (list 1)), the former is a list containing an integer while the latter is a list containing a list. Join's arguments are always lists!
(join
    (list 1)
    (list "apple" 0.3)
); ok - produces (list  1 "apple" 0.3)

(join
    (list 1)
    (list 1 (list 2))
); ok -produces (list 1 1 (list 2))

(join
    (list 1)
    2   ; error 2 is not a list
)
Nth is a name for two different operation : one gives you always a list (or nil could be considered as empty list here), the other could give you anything. The first takes 3 arguments : start and end indexes and the list, it gives you the sublist corresponding the indexes you gave. In second case Nth gives you the nth element of a list if you gave only one index. This also could be a list but could be anything else as well.
;this gives (list 2 3)
(nth 2 8 (list 1 2 3))

;this gives (list 2) !! and not 2
(nth 2 2 (list 1 2 3))

; this gives (list 1 2)
(nth -10 2 (list 1 2 3))

;this gives 2
(nth 2 (list 1 2 3))