These are notes I’m taking in my Cognitive Science Seminar. Right now we’re learning the basics of the LISP Computer Language, so these notes are probably profoundly uninteresting. Still, code is kinda fun to look at cause it doesn’t make any sense at the same time that it means something. It’s, like, mysterious.
Computer languages are so simple that they’re inhumanly difficult. All we did today was learn how to perform basic arithmetic, assign variables, and create lists like (1 2 3 4 5). But it’s confusing. Once you practice you get used to it, but it’s unnaturally abstract.
( * ( + a b ) (+ a c ) )
multiply (a plus b) times (a plus c)
don’t need to define intermediate variables d= (a+b), e=(a+c), f=(d*e).
If you want to define intermediate variables use let or setq command.
(let ((var1 form1)
The result of the computation form1 gets stored in var1, the result of computation form2 gets stored in var2. Let creates local variables which are destroyed as soon as the processor finishes the let command. setq sets a global variable which lasts as long as the code is running.
(setq h (*2 4) —- set the variable h to equal 2 * 4.
(defun f (a b c)
(let ((d (float (/ a b))))
(+ d(* c d))))
(f2 3 4 5)
(defun f (3 4 5)
(let ((d (float (/ 3 4)))) —- so, d = 3/4, converted to floating point= 0.75
(+ .75(* 5 0.75)))) —– so, 0.75 times (5 times 0.75)
which equals 4.5
All it’s doing is using variables to store the results of computations.
Procedure for building lists:
(cons obj1 obj2) — takes two arguments and makes a list outta them
(setq list1 (cons ‘a nil)), adds a to the nil (null) list
list1 = (a)
(setq list1 (cons ‘b list1))
now list1 = (b a)
(setq list1 (cons ‘(1 2) list1)
now list1 = ((1 2) b a )
This is a nested list, which looks like a 2-dimensional array in Java.
So, how do I access lists?
car or first – first
cdr or rest– rest
say you have a list named fuckingA which contains (1 2 3 4 5)
first (1 2 3 4 5) returns (1)
rest (1 2 3 4 5) returns (2 3 4 5)
car and cdr do let you move deep into multi-dimensional lists (embedded lists)
(caar list) = (car (car list)
(cadar list = (car (cdr (car list)))
(caar ‘((a b) c))
so, car of the first dimension of the list returns (a b)
car of this list returns (a)
cadar ‘((a b) c))
car returns (a b)
cdr of this is b
fuck, i’m confused.
alternatives to cons, list and append.
list (‘a ‘b ‘c) creates the list (a b c)
(list (list ‘a ‘b) ‘c) creates the list ((a b) c)
append ‘(a) ‘(b c d))
returns (a b c d)
I am hungry. What time is this class over. I’m going to stop explaining shit and just enter raw code.
(defun greeting ()
“ask for a name, read it, and say hello”
(format t “what is your name? ~%“)
“t means print to TERMINAL, ~% means go to next line”
(let ((name (read)))
(format t “~% Hello ~a”
“~a refers to what the user types in”
Fuck this. The only way to learn computer shit is to just do it. Then it’s easy. I’m going to wait for the assignment and learn everything the night before it’s due.
Fucking hungry. I want a muffin.