Lecture 1 Flashcards
What is an atom?
letters, digits, *, -, , etc.
What is a List?
(1 2 3 4), (a (b c) (d (e f))) (sequence of atoms/lists)
what represents false in LISP?
nil and ()
what is an s-expression?
- an atom is an s-sxpression
2. if s⌄1, s⌄2, s⌄3, … s⌄n are s-expressions then so is the list (s⌄1 s⌄2 s⌄3)
how are s-expression lists evaluated?
first elements is function name and the others are arguments
how are number, lists and atomic symbols evaluated?
numbers - evaluated as numbers
atomic symbols - return value bound (error if nothing is bound)
list - evaluate second to last and apply the first element as function
write a function that squares a number
(defun square (x)
(* x x))
explain defun arguments
first argument is name, second is a list of arguments passed in, third is the function itself (body)
explain cond keyword
(cond (()())
(()()))
cond goes until non-nil value is found, if non is found returns nil
how do we make a default action in cond statement?
last argument in cond should be (t x)
t - always true
x - default action
describe if statement
(if (
explain when and unless in terms of if statements
when and unless both return nil in else case
when - 1st arg is true preform second
unless - 1st arg is false preform secnd
what is a predicate?
function that returns true or false
when does lisp return nil?
to indicate false, t is used for EVERYTHING else
explain and and or functions in lisp
and - everything has to be t, or result is nil. If everything is true last expression is returned.
or - evaluates until non-nil is found.