Built-In Modules |
---|
List |
Math |
String |
(require list)
(list 1 2 3 4 5 6)
=> (1 2 3 4 5 6)
(append (list 1 2 3) (list 4 5 6))
=> (1 2 3 4 5 6)
(empty? (list 1 2 3 4))
=> false
(empty? (list))
=> true
(length (list 1 2 3 4 5 6))
=> 6
(first (list 1 2 3 4 5 6))
=> 1
(last (list 1 2 3 4 5 6))
=> 6
(third (list 1 2 3 4 5 6))
=> 3
(nth 4 (list 1 2 3 4 5 6))
=> 5
(head (list 1 2 3 4))
=> 1
(tail (list 1 2 3 4))
=> (2 3 4)
(sublist (list 6 5 4 3 2 1) 3)
=> (3 2 1)
(sublist (list 6 5 4 3 2 1) 1 4)
=> (5 4 3)
(for-each (lambda (n) (print n))
(list 1 2 3 4))
=> 1
2
3
4
(sort (list 5 3 7 2 1 4 6))
=> (1 2 3 4 5 6 7)
(reverse (list 1 2 3 4 5 6))
=> (6 5 4 3 2 1)
Accepts any function object that evaluates to a boolean value.
(defun even? (n) (= (mod n 2) 0))
(filter even? (list 1 2 3 4 5 6))
=> (2 4 6)
(filter (lambda (n) (> n 3))
(list 1 2 3 4 5 6))
=> (4 5 6)
(filter integer? (list 1 "A" true 2 3 "B"))
=> (1 2 3)
Accepts any function object.
(defun add1 (n) (+ n 1))
(map add1 (list 1 2 3 4 5 6))
=> (2 3 4 5 6 7)
(group (list 1 1 1 2 3 3 4 5 5))
=> (1 2 3 4 5)
(reduce + 0 (list 1 2 3 4 5 6))
=> 21
Accepts any function object that evaluates to a boolean value.
(partition number? (list 1 "A" true 2 3 "B"))
=> ((1 2 3) ("A" true "B"))
[WIP]
(require math)
(abs (- 8))
=> 8
(min 3 8)
=> 3
(max 3 8)
=> 8
(require string)
(string-append "Foo" "Bar")
=> "FooBar"
(string-length "FooBar")
=> 6
(string-lower "FooBar")
=> "foobar"
(string-upper "FooBar")
=> "FOOBAR"
(substring "FooBar" 3)
=> "Bar"
(substring "FooBar" 2 5)
=> "oBa"