Scheme Flashcards
What is the car of I where l is ((a b c) x y z)
(a b c), because (a bc ) is the first S-expression of this non-empty list.
What is (car (car I)) where I is (((hotdogs) (and))
(hotdogs).
What is the cdr of I where I is ((a b c) x y z)
(x y z).
What is the cdr of I where l is (hamburger)
().
What is (cdr I) where l is ((x)tr)
(t r),
because (cdr I) is just another way to ask for “the cdr of the list I.”
The Law of Cdr
The primitive cdr is defined only for non-empty lists. The cdr of any non- empty list is always another list.
What does car take as an argument?
It takes any non-empty list.
What does cdr take as an argument?
It takes any non-empty list.
What is the cons of the atom a and the list I where a is peanut andI is (butter and jelly)
This can also be written “(cons a I)”.
Read: “cons the atom a onto the list I.”
(peanut butter and jelly),
because cons adds an atom to the front of a list.
What does cons take as its arguments?
cons takes two arguments:
the first one is any S-expression;
the second one is any list.
The Law of Cons
The primitive cons takes two arguments. The second argument to cons must be a list. The result is a list.
What is (null? (quote ()))
True,
because (quote ()) is a notation for the null list.
The Law of Null?
The primitive null? is defined only for lists.
True or false: a lat is a list of atoms.
True! Every lat is a list of atoms!
Í Scheme viljum við forrita án hliðarverkana, hvað þýðir það?
Það þýðir að við viljum ekki nota neinar gildisveitingar. Breytur fá því gildi þegar þær verða til og fá aldrei nýtt gildi.