Scheme Flashcards

1
Q

What is the car of I where l is ((a b c) x y z)

A

(a b c), because (a bc ) is the first S-expression of this non-empty list.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
What is (car (car I)) where
I is (((hotdogs) (and))
A

(hotdogs).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
What is the cdr of I where
I is ((a b c) x y z)
A

(x y z).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
What is the cdr of I where
l is (hamburger)
A

().

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
What is (cdr I) where
l is ((x)tr)
A

(t r),

because (cdr I) is just another way to ask for “the cdr of the list I.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

The Law of Cdr

A

The primitive cdr is defined only for non-empty lists. The cdr of any non- empty list is always another list.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does car take as an argument?

A

It takes any non-empty list.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does cdr take as an argument?

A

It takes any non-empty list.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

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.”

A

(peanut butter and jelly),

because cons adds an atom to the front of a list.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does cons take as its arguments?

A

cons takes two arguments:
the first one is any S-expression;
the second one is any list.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

The Law of Cons

A

The primitive cons takes two arguments. The second argument to cons must be a list. The result is a list.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is (null? (quote ()))

A

True,

because (quote ()) is a notation for the null list.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

The Law of Null?

A

The primitive null? is defined only for lists.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

True or false: a lat is a list of atoms.

A

True! Every lat is a list of atoms!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Í Scheme viljum við forrita án hliðarverkana, hvað þýðir það?

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Hvað þurfum við að gera til þess að forrita án hliðarverkana í Scheme?

A

Við notum endurkvæmni (recursion) í stað lykkju.

17
Q

Hvað gerir endurkvæmt fall?

A

Kallar á sjálft sig

18
Q

Hvað gerir hala endurkvæmt fall ?

A

Endurkvæmt fall sem endar á að kalla á sjálft sig (eða jafnvel annað endurkvæmt fall) er kallað halaendurkvæmt (tail recursive).

19
Q

Afhverju er halaendurkvæmni hagstæð í Scheme ?

A

Þegar Scheme fall endar á að kalla á annað fall (eða sjálft sig) er strax hætt í núverandi falli og næsta fall tekur við og skilar sínu gildi til þess sem kallaði á upphaflega fallið.

20
Q

Listavinnsla í Scheme byggist á föllunum?

A

car, cdr og cons

21
Q

Hvað gerir car í Scheme ?

A

Gefur þér fyrsta stak í lista

22
Q

Hvað gerir cdr í Scheme ?

A

Gefur þér allt sem kemur á eftir fyrsta stakinu

23
Q

Hvernig myndi ég fá stak 2 í lista?

A

Með því að kalla á car af cdr af listanum, eða cadr sem er short fyrir það

24
Q

Hvað gerir cons?

A

Setur stak fremst í lista