Why do we use it?
Basic syntax can be found here in:
There are 2 fundamental pieces in Lisp.
basically just element
99999999999 ; interger
#b111 ; binary number that is 7
#x111 ; hexadecimal that is 273
3.14159s0 ; a single precision floatiing point number
3.14159d0. ; double precision floating point
1/2 ; ratios
#C(1 2) ; complex number, the first being the real part and the second the imaginary part
simple, elegant operations performs on atoms
Basic arithmetic operations
(+ 1 1) ; => 2
(* 10 2) ; => 20
(expt 2 3) ; => 8
(/ 1 3) ; => 1/3
(+ #C(1 2) #(6 -4)) ; => #C(7 -2)
; booleans and equality
; and: read until nil and return nil, if exhausted the list, return the last
; or: read until not nil and return it, else return nil
(not nil) ; => T
(and 0 t) ; => T (0 is not nil, so it's true)
(or 0 nil) ; => 0
(and 1 ()) ; => nil
; compare numbers, = can only used within numbers
(= 3 3.0) ; => T
(= 2 1) ; => NIL
; compare object identity
(eql 3 3) ; => T
(eql 3 3.0) ; => NIL
(eql (list 3) (list 3)) ; => NIL
(eql 'a 'a). ; => T
; compare lists, strings
(equal (list 'a 'b) (list 'a 'b)) ; => T
(equal (list 'a 'b) (list 'b 'a)) ; => NIL
String
(concatenate 'string "Hello," "world!" ) ;=> "Hello,world!"
(format nil "Hello, ~a" "Alice") ; returns "Hello, Alice"
; ^ nil means the result will not go to stdout
; ~a is replace with the a with the second arg
(format t "Hello, ~a" "Alice") ; returns nil and formatted string goes to stdout
(print "hello") ; value is returned and printed to stdout
(+ 1 (print 2)) ; prints 2. return 3
Variables
()".'
;#|\`