Reference¶
Basic reference manual of functions supported.
Boolean¶
-
(bool? v)
Check if value is boolean
> (bool? #t) #t > (bool? 1) #f
-
(eq v1 v2)
Compare equality between two values
> (eq 1 2) #f > (eq 1 1) #t > (eq 1 #t) #f
-
(ne v1 v2)
Compare inequality between two values
> (ne 1 2) #t > (ne 1 1) #f > (ne 1 #t) #t
-
(not v)
Inverse of boolean value
> (not #t) #f > (not #f) #t > (not 1) Error: Wrong argument type. Got: Number, Expected: Boolean
-
(and v1 v2)
Logical and operation
> (and #t #t) #t > (and #f #t) #f > (and #t 1) Error: Wrong argument type. Got: Number, Expected: Boolean
-
(or v1 v2)
Logical or operation
> (or #t #t) #t > (or #f #f) #f > (or #t 1) Error: Wrong argument type. Got: Number, Expected: Boolean
-
(xor v1 v2)
Logical xor operation
> (xor #t #t) #f > (xor #t #f) #t > (xor #t 1) Error: Wrong argument type. Got: Number, Expected: Boolean
-
(nand v1 v2)
Logical nand operation
> (nand #t #t) #f > (nand #f #f) #t > (nand #t 1) Error: Wrong argument type. Got: Number, Expected: Boolean
-
(nor v1 v2)
Logical nor operation
> (nor #t #t) #f > (nor #f #f) #t > (nor #t 1) Error: Wrong argument type. Got: Number, Expected: Boolean
Error¶
-
(error? v)
Check if the value is an error
> (error? (error "Some error")) #t > (error? #t) #f
-
(error message)
Create error object
> (error "Some error") Error: Some error > (error 1) Error: Wrong argument type. Got: Number, Expected: String
Input/Output¶
-
(display t)
Display info about type
> (display 1) Number -> 1 > (display [1 2 3 4]) List -> [1 2 3 4]
-
(print t)
Print type value
> (print 1) 1 > (print [1 2 3 4]) [1 2 3 4] > (print +) <builtin>
-
(load file)
Load clisp script
> (load "stl/prelude.clisp") > (pi) 3.1415
List¶
-
(list? v)
Check if value is a list
> (list? [1 2 3 4]) #t > (list? 1) #f
-
(list e1 ...)
Create a list of elements
> (list 1 2 3 4 5) [1 2 3 4 5]
-
(head xs)
Get the first element of a list
> (head [1 2 3 4 5]) 1 > (head 1) Error: Wrong argument type. Got: Number, Expected: List
-
(tail xs)
Discard the first element of a list
> (tail [1 2 3 4]) [2 3 4] > (tail 1) Error: Wrong argument type. Got: Number, Expected: List
-
(append xs el)
Append an element in the list
> (append [1 2 3 4] 5) [1 2 3 4 5] > (append 1 1) Error: Wrong argument type. Got: Number, Expected: List
-
(length xs)
Get the number of elements in the list
> (length [1 3 4]) 3 > (length 1) Error: Wrong argument type. Got: Number, Expected: List
-
(empty? xs)
Check if the list is empty
> (empty? []) #t > (empty? [1]) #f > (empty? 1) Error: Wrong argument type. Got: Number, Expected: List
-
(cons el xs)
Get two elements and create one list
> (cons 1 2) [1 2] > (cons 1 [2 3]) [1 2 3]
Number¶
-
(number? v)
Check if value is number
> (number? 1) #t > (number? #t) #f
-
(zero? v)
Check if value is equal to zero
> (zero? 0) #t > (zero? 1) #f > (zero? #t) Error: Wrong argument type. Got: Boolean, Expected: Number
-
(positive? v)
Check if value is positive
> (positive? -1) #f > (positive? 1) #t > (positive? #t) Error: Wrong argument type. Got: Boolean, Expected: Number
-
(negative? v)
Check if value is negative
> (negative? 1) #f > (negative? -1) #t > (negative? #t) Error: Wrong argument type. Got: Boolean, Expected: Number
-
(even? v)
Check if value is even
> (even? 1) #f > (even? 2) #t > (even? #t) Error: Wrong argument type. Got: Boolean, Expected: Number
-
(odd? v)
Check if value is odd
> (odd? 1) #t > (odd? 2) #f > (odd? #t) Error: Wrong argument type. Got: Boolean, Expected: Number
-
(> v1 v2)
Check if v1 is greater than v2
> (> 1 2) #f > (> 2 1) #t > (> 1 #t) Error: Wrong argument type. Got: Boolean, Expected: Number
-
(>= v1 v2)
Check if v1 is greater or equal v2
> (>= 1 2) #f > (>= 2 2) #t > (>= 1 #t) Error: Wrong argument type. Got: Boolean, Expected: Number
-
(< v1 v2)
Check if v1 is lesser than v2
> (< 1 2) #t > (< 2 2) #f > (< 1 #t) Error: Wrong argument type. Got: Boolean, Expected: Number
-
(<= v1 v2)
Check if v1 is lesser or equal v2
> (<= 1 2) #t > (<= 2 2) #t > (<= 1 #t) Error: Wrong argument type. Got: Boolean, Expected: Number
Math¶
-
(+ v1 v2)
Sum two numbers
> (+ 1 2) 3 > (+ 1 #t) Error: Wrong argument type. Got: Boolean, Expected: Number
-
(- v1 v2)
Subtract two numbers
> (- 2 1) 1 > (- 1 #t) Error: Wrong argument type. Got: Boolean, Expected: Number
-
(* v1 v2)
Multiply two numbers
> (* 2 1) 2 > (* 1 #t) Error: Wrong argument type. Got: Boolean, Expected: Number
-
(/ v1 v2)
Divide two numbers
> (/ 2 1) 2 > (/ 1 #t) Error: Wrong argument type. Got: Boolean, Expected: Number
-
(% v1 v2)
Rest of division
> (% 10 3) 1 > (% 1 #t) Error: Wrong argument type. Got: Boolean, Expected: Number
-
(^ v1 v2)
Power of a number
> (^ 10 3) 1000 > (^ 1 #t) Error: Wrong argument type. Got: Boolean, Expected: Number
-
(ceil v)
Round number to ceiling
> (ceil 2.1) 3 > (ceil #t) Error: Wrong argument type. Got: Boolean, Expected: Number
-
(floor v)
Round number to floor
> (floor 2.9) 2 > (floor #t) Error: Wrong argument type. Got: Boolean, Expected: Number
-
(round v)
Round number
> (round 2.3) 2 > (round 2.7) 3 > (round #t) Error: Wrong argument type. Got: Boolean, Expected: Number
-
(sqrt v)
Square root
> (sqrt 4) 2 > (sqrt #t) Error: Wrong argument type. Got: Boolean, Expected: Number
-
(log10 v)
Logarithm base 10
> (log10 1000) 3 > (log10 #t) Error: Wrong argument type. Got: Boolean, Expected: Number
-
(log v)
Natural logarithm
> (log 1) 0 > (log #t) Error: Wrong argument type. Got: Boolean, Expected: Number
-
(sin v)
Sine of a radian
> (sin 3.1415) 0 > (sin #t) Error: Wrong argument type. Got: Boolean, Expected: Number
-
(cos v)
Cosine of a radian
> (cos 3.1415) 1 > (cos #t) Error: Wrong argument type. Got: Boolean, Expected: Number
-
(tan v)
Tangent of a radian
> (tan 0.7854) 1 > (tan #t) Error: Wrong argument type. Got: Boolean, Expected: Number
-
(abs v)
Absolute value of a number
> (abs -1) 1 > (abs 1) 1 > (abs #t) Error: Wrong argument type. Got: Boolean, Expected: Number
String¶
-
(string? v)
Check if value is a string
> (string? "Value") #t > (string? 1) #f
-
(string->upper v)
Transform all characters in uppercase
> (string->upper "Value") VALUE > (string->upper 1) Error: Wrong argument type. Got: Number, Expected: String
-
(string->lower v)
Transform all characters in lowercase
> (string->lower "Value") value > (string->lower 1) Error: Wrong argument type. Got: Number, Expected: String
-
(string->split v s)
Split a phrase in a list of words separated by element
> (string->split "Hello World" " ") ["Hello" "World"] > (string->split 1 " ") Error: Wrong argument type. Got: Number, Expected: String
-
(string->concat el ...)
Concat all elements in a single string
> (string->concat "Hello " "World" " ...") "Hello World ..." > (string->concat 1 " ") Error: Wrong argument type. Got: Number, Expected: String
-
(string->length str)
Count the number of characters in the string
> (string->length "Hello World") 11 > (string->length 1) Error: Wrong argument type. Got: Number, Expected: String
Syntactic¶
-
(if c e1 e2)
Conditional that executes first expression if conditional is true, else it executes second expression
> (if (> 2 1) "foo" "bar") foo > (if (< 2 1) "foo" "bar") bar > (if 1 "foo" "bar") Error: Wrong argument type. Got: Number, Expected: Boolean
-
(cond expr1 ...)
Cond clause test expression by expression and execute if condition is true
> (cond ((> 2 1) "foo") (#t 2)) foo > (cond ((< 2 1) "foo") (#t "bar")) bar
-
(for it command)
Iterate over a list and execute the command
> (for (i [1 2 3]) (print i)) 1 2 3 > (for i (print i)) Error: Wrong argument type. Got: Symbol, Expected: Expression
-
(def (name p1 ..) body)
Define a function
> (def (add1 x) (+ x 1)) > (add1 1) 2
-
(fn args body)
Create a lambda function to pass as parameter
> (filter (fn (a) (> a 4)) [3 4 5 6]) [5 6]
-
(when expr1 ...)
Execute all expressions that conditional is true
> (when (#t (print "foo")) (#f (print "foo")) (#t (print "bar"))) foo bar
-
(unless expr1 ...)
Execute all expressions that conditional is false
> (unless (#t (print "foo")) (#f (print "foo")) (#t (print "bar"))) foo
-
(type v)
Show the type of value
> (type 1) Number