Created
October 11, 2018 05:35
-
-
Save jasonrobot/86a2c792e64c41433fa60222d617799e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; General form | |
;;; CL has two fundamental pieces of syntax: ATOM and S-EXPRESSION. | |
;;; Typically, grouped S-expressions are called `forms`. | |
10 ; an atom; it evaluates to itself | |
:thing ; another atom; evaluating to the symbol :thing | |
t ; another atom, denoting true | |
(+ 1 2 3 4) ; an s-expression | |
'(4 :foo t) ; another s-expression | |
;;; Function application are written as (f x y z ...) where f is a function and | |
;;; x, y, z, ... are the arguments. | |
(+ 1 2) ; => 3 | |
;;; If you want to create literal data, use QUOTE to prevent it from being | |
;;; evaluated | |
(quote (+ 1 2)) ; => (+ 1 2) | |
(quote a) ; => A | |
;;; The shorthand for QUOTE is ' | |
'(+ 1 2) ; => (+ 1 2) | |
'a ; => A | |
;;; Variables aren't used the same way as other languages. Lisp is more about data flow than setting up a bunch of state. | |
;;; Use 'let to set some local variables | |
(let ((x 5) | |
(y 10)) | |
(+ x y)) ; => 15 | |
;;; There is no return statement in lisp (there are no statements at all - everything is an expression | |
;;; S-expressions evaluate to the value of their last form | |
(progn | |
(+ 1 2) | |
(+ 2 3) | |
10) ; => 10 | |
(defun return-x (x) | |
x) | |
(return-x 10) ; => 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment