slashbinbash.de / Sikkel / Built-In Modules

Built-In Modules
List
Math
String

List

(require list)

Create 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)

Retrieve list length

(empty? (list 1 2 3 4))
    => false
(empty? (list))
    => true

(length (list 1 2 3 4 5 6))
    => 6

Retrieve list elements

(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)

Iterate over all elements

(for-each (lambda (n) (print n))
          (list 1 2 3 4))
    => 1
       2
       3
       4

Sort

(sort (list 5 3 7 2 1 4 6))
    => (1 2 3 4 5 6 7)

Reverse

(reverse (list 1 2 3 4 5 6))
    => (6 5 4 3 2 1)

Filter

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)

Map

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

(group (list 1 1 1 2 3 3 4 5 5))
    => (1 2 3 4 5)

Reduce

(reduce + 0 (list 1 2 3 4 5 6))
    => 21

Partition

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"))

Sets

[WIP]

Math

(require math)

(abs (- 8))
    => 8
(min 3 8)
    => 3
(max 3 8)
    => 8

String

(require string)

(string-append "Foo" "Bar")
    => "FooBar"
(string-length "FooBar")
    => 6
(string-lower "FooBar")
    => "foobar"
(string-upper "FooBar")
    => "FOOBAR"

Substring

(substring "FooBar" 3)
    => "Bar"
(substring "FooBar" 2 5)
    => "oBa"