☯️ A Lisp dialect and toolchain. All in one binary.
Special forms for the lifp language. These are core language constructs that control binding, scope, and conditional execution.
Conditional branching. Evaluates the first true condition's form, or the last form if none match.
(cond ((< x 0) "negative") ((= x 0) "zero") ("positive"))
Binds a value to a symbol in the current environment.
(def! answer 42)
(def! sum (fn (a b) (+ a b)))
Creates a function (closure) with given arguments and body.
(fn (a b) (+ a b))
Binds local variables for the scope of a body expression.
(let ((x 1) (y 2)) (+ x y)) ; returns 3
Core lifp operators. For all intents and purposes, these should be thought as language keywords.
(and true false) ; returns false
Performs a modulo division.
(% 6 3) ; returns 0
Multiplies arguments.
(* 1 2 3) ; returns 6
Sums arguments.
(+ 1 2 3) ; returns 6
Subtracts arguments from the first argument.
(- 6 3 2) ; returns 1
Divides the first argument by the rest.
(/ 6 3 2) ; returns 1
Checks if the first argument is less than the second. otherwise.
(< 1 6) ; returns true
Checks if the first argument is less than or equal to the second. second, false otherwise.
(<= 1 6) ; returns true
Checks if two arguments are not equal.
(<> 6 6) ; returns false
Checks if two arguments are equal.
(= 6 6) ; returns true
Checks if the first argument is greater than the second. false otherwise.
(> 1 6) ; returns false
Checks if the first argument is greater than or equal to the second. second, false otherwise.
(>= 6 1) ; returns true
Logical AND operation on boolean arguments.
(and true false) ; returns false
Logical OR operation on boolean arguments.
(or true false) ; returns true
Flow control utilities for lifp. These functions provide basic control over program execution, such as pausing execution for a specified duration.
(flow:sleep! 1000) ; pauses execution for ~1 second
Suspends execution for a given number of milliseconds.
(flow:sleep! 1000) ; pauses for ~1 second
Input/output utilities for lifp. These functions provide basic console IO.
(io:stdout! "hello") ; prints to stdout
(io:stderr! "error") ; prints to stderr
(io:printf! "Hello, {}!" ["world"]) ; prints formatted string
(io:readline! "Enter your name: ") ; reads a line from stdin
(io:clear!) ; clears the terminal
Clears the terminal screen.
(io:clear!)
Prints a formatted string to standard output, replacing each '{}' in the format string with the corresponding value from the list.
(io:printf! "Hello, {}!" ("world")) ; prints "Hello, world!"
Prints a prompt and returns the answer as a string.
(io:readline! "What's your name?") ; returns user input
Prints a value to standard error.
(io:stderr! "error")
Prints an argument to standard output.
(io:stdout! "hello")
List manipulation operators for lifp. These functions provide core list operations such as counting, creating, accessing, mapping, filtering, and iterating over lists.
(list:count (list:from 1 2 3)) ; returns 3
(list:nth 1 (list:from 10 20 30)) ; returns 20
(list:map (fn (x i) (* x 2)) (list:from 1 2 3)) ; returns (2 4 6)
Counts the number of elements in a list.
(list:count (1 2 3)) ; returns 3
Applies a function to each element of a list for side effects. The function receives each element and its index.
(list:each (fn (x i) (print x)) (1 2 3))
Filters a list using a predicate function. The function receives each element and its index, and should return a boolean. true.
(list:filter (fn (x i) (> x 1)) (1 2 3)) ; returns (2 3)
Creates a list from the given arguments.
(list:from 1 2 3) ; returns (1 2 3)
Maps a function over a list, returning a new list of results. The function receives each element and its index.
(list:map (fn (x i) (* x 2)) (1 2 3)) ; returns (2 4 6)
Returns the nth element of a list, or nil if out of bounds.
(list:nth 1 (10 20 30)) ; returns 20
Reduces a list to a single value by repeatedly applying a reducer function. The function receives the accumulated value, the current element, and its index.
(list:reduce (fn (p c i) (+ p c)) 0 (1 2 3)) ; returns 6
Calls a function a given number of times, collecting the results in a list. The function receives the current index.
(list:times (fn (i) (* i 2)) 3) ; returns (0 2 4)
Math operators for lifp. Provides mathematical utilities such as min, max, random, ceil, and floor for working with numbers and lists of numbers.
(math:max (list:from 1 2 3)) ; returns 3
(math:min (list:from 1 2 3)) ; returns 1
(math:random!) ; returns a random number between 0 and 1
(math:ceil 2.3) ; returns 3
(math:floor 2.7) ; returns 2
Returns the smallest integer greater than or equal to the argument.
(math:ceil 2.3) ; returns 3
Returns the largest integer less than or equal to the argument.
(math:floor 2.7) ; returns 2
Returns the maximum of the arguments.
(math:max 1 2 3) ; returns 3
Returns the minimum of the arguments.
(math:min 1 2 3) ; returns 1
Returns a random number between 0 and 1.
(math:random!) ; returns a random number between 0 and 1
String manipulation functions for lifp.
(str:length "hello") ; returns 5
(str:join "," ("a" "b" "c")) ; returns "a,b,c"
(str:slice "abcdef" 1 4) ; returns "bcde"
(str:include "hello world" "world") ; returns true
(str:trimLeft " foo") ; returns "foo"
(str:trimRight "foo ") ; returns "foo"
Checks if a string contains a substring.
(str:include? "hello world" "world") ; returns true
Joins a list of strings using a separator.
(str:join "," ("a" "b" "c")) ; returns "a,b,c"
Returns the length of a string.
(str:length "hello") ; returns 5
Returns a substring from start to end (end not inclusive). Negative indices count from the end of the string.
(str:slice "abcdef" 1 4) ; returns "bcde"
(str:slice "abcdef" 2) ; returns "cdef"
Removes whitespace from the start of a string.
(str:trimLeft " foo") ; returns "foo"
Removes whitespace from the end of a string.
(str:trimRight "foo ") ; returns "foo"