Comment by shaftway
7 years ago
Lisp syntax in a nutshell is:
"(" {function} [" " {argument}...] ")"
If you don't want to actually run a function, like you just want a list of values, you put a single quote before it:
"'(" [{item} [" " {item}...]] ")"
So if you want to do `(1 + 2) * 3` it'd be `(* (+ 1 2))`. Parentheses abound.
On top of that everything is a function, including if statements, assignment, and even how you define a new function. So factorial in lisp is:
(defun factorial (x)
(if (<= x 0)
1
(* x (factorial (- x 1)))
) )
You'll notice that it ended with 5 close-parentheses. Different people have different strategies for managing that along with indents and newlines.
No comments yet
Contribute on Hacker News ↗