lifp

☯️ A Lisp dialect and toolchain. All in one binary.

View the Project on GitHub shikaan/lifp

lifp - v0.6.0 (e0415ec)

math.floor

Returns the floor of a number.

(math.floor 1.9) ; 1

math.ceil

Returns the ceiling of a number.

(math.ceil 1.1) ; 2

math.max

Returns the maximum value in a list of numbers.

(math.max (1 2 3)) ; 3

math.min

Returns the minimum value in a list of numbers.

(math.min (1 2 3)) ; 1

math.random

Returns a random number between 0 (inclusive) and 1 (exclusive).

(math.random) ; 0.123456

string.length

Returns the length of a string.

(string.length "hello") ; 5

string.join

Joins a list of strings with a separator.

(string.join "," ("foo" "bar")) ; "foo,bar"

string.slice

Returns a substring from start to end indices.

(string.slice "hello" 1 4) ; "ell"

string.includes

Checks if a string contains a substring.

(string.includes "hello" "ell") ; true

string.trim

Trims whitespace from both ends of a string.

(string.trim "  hello  ") ; "hello"

flow.sleep

Sleeps for the given number of milliseconds.

(flow.sleep 1000) ; sleeps for ~1 second

list.count

Counts elements in a list.

(list.count (1 2)) ; 2

list.map

Maps a lambda over a list.

(list.map (fn* (item idx) (+ item idx)) (1 2 3)) ; (1 3 5)

list.each

Applies a lambda to each element in a list (for side effects).

(list.each (fn* (item idx) (print item)) (1 2 3)) ; nil

list.from

Creates a list from the given arguments.

(list.from 1 2 3) ; (1 2 3)

list.times

Creates a list by repeatedly calling a lambda.

(list.times (fn* (idx) idx) 3) ; (0 1 2)

list.nth

Returns the nth element of a list, or nil if out of bounds.

(list.nth 1 (10 20 30)) ; 20

list.filter

Filters a list using a lambda predicate.

(list.filter (fn* (item idx) (> item 0)) (-1 0 1 2)) ; (1 2)

+

Adds numbers together.

(+ 1 2 3) ; 6

-

Subtracts numbers from the first argument.

(- 5 2 1) ; 2

*

Multiplies numbers together.

(* 2 3 4) ; 24

/

Divides the first argument by the rest.

(/ 8 2 2) ; 2

%

Performs division with modulo.

(% 4 2) ; 0

=

Checks if two values are equal.

(= 1 1) ; true

<

Checks if the first value is less than the second.

(< 1 2) ; true

>

Checks if the first value is greater than the second.

(> 2 1) ; true

!=

Checks if two values are not equal.

(!= 1 2) ; true

<=

Checks if the first value is less than or equal to the second.

(<= 1 2) ; true

>=

Checks if the first value is greater than or equal to the second.

(>= 2 1) ; true

and

Logical AND for two boolean values.

(and true false) ; false

or

Logical OR for two boolean values.

(or true false) ; true

io.stdout

Stringifies an atom and writes it to stdout. Use io.print to format output.

(io.stdout "hello")

io.stderr

Stringifies an atom and writes it to stderr.

(io.stderr "error")

io.printf

Writes a formatted string to stdout. Specifiers:

(io.printf "hello %s %d" ("world" 42))

io.readline

Writes the question on stdout and waits for user input.

(io.readline "What is your favorite food? ") ; "USER_TYPED_CONTENT"

io.clear

Clear the console output.

(io.clear)