-
Notifications
You must be signed in to change notification settings - Fork 0
Code Reference
Joshua Maxwell edited this page Nov 4, 2021
·
3 revisions
| Name | Description | Example |
|---|---|---|
quote |
returns a literal of its parameter |
(quote Hello) => Hello
|
atom |
returns t if the parameter is atomic (not a list) |
(atom '(a b c d)) => ()
|
eq |
returns t if both parameters are equal |
(eq 'hi 'hi) => t
|
car |
returns the head of the list |
(car '(a b c d)) => a
|
cdr |
returns the tail of the list |
(cdr '(a b c d)) => (b c d)
|
cons |
prepends the first parameter to the second |
(cons 'w '(x y z)) => (w x y z)
|
cond |
returns first true statement |
(cond ('() 'no) ('t 'yes)) => yes
|
lambda |
returns a lambda function |
((lambda (x) (+ x 1)) 2) => 3
|
defun |
defines a function |
(defun add1 (x) (+ x 1)) (add1 5) => 6
|
set |
defines a constant |
(set apple 'sauce) (print apple) => sauce
|
setq |
defines a quoted constant |
(setq fancy pants) (print fancy) => pants
|
print |
prints a value |
(print "Hello, world!") => Hello, World!
|
read |
gets user input and prints parameter | (read "What's your name? ") |
import |
imports an eLispsis file (path is relative to main.js) | (import library/stdlib.el) |
meta |
returns the result of a NodeJS statement |
(print (meta "4 + 5")) => 9
|
| Operator | Description | Example |
|---|---|---|
+ |
Returns the sum of the list |
(+ 1 2 3 4 5) => 15
|
- |
Returns the difference of the list |
(- 50 30 10 7) => 3
|
* |
Returns the product of the list |
(* 1 2 3 4 5) => 120
|
/ |
Returns the quotient of the list |
(/ 144 12 3) => 4
|
% |
Returns the modulo of the list |
(% 6 4) => 2
|
^ |
Returns the exponentiation of the list |
(^ 2 2 3) => 64
|
& |
Returns the string concatenation of the list |
(& "This is a" " string") => "This is a string"
|
< |
Returns t if the list is strictly in ascending order |
(< 10 11 13) => t
|
> |
Returns t if the list is strictly in descending order |
(> 10 8) => t
|
<= |
Returns t if the list is loosely in ascending order |
(<= 10 10 12) => t
|
>= |
Returns t if the list is loosely in descending order |
(>= 14 4 4 3) => t
|
The Ellipsis (...) operator is a special operator that allows you to execute multiple lines of unrelated
code in a single expression. This allows users to define sub-functions and constants within functions/lambdas.
While it would be nice to reserve this operator for the most central function of the language, it can be hard
to gauge what is the most central or powerful.
Example usage:
(defun overlyComplicatedHelloWorld ()
(... (setq hi "Hello, world!")
(print hi)))
(overlyComplicatedHelloWorld) ;;This would simply print "Hello, world!"