taocp

This site has no text of the book. Keep your own copy of TAOCP next to it. See what is checked.

Exercise · Volume 1 · 2.1-6

Exercise 2.1-6

not stated yet in Lean solution written

Rating06
KindK2, decide: say whether a claim holds from the written solution
SectionSection 2.1 of Volume 1

The task

After CARD ←\gets NODE(TOP), decide which of four notations stand for the suit of the top card.

The exact wording is in your copy of the book.

Hints

Open one hint at a time. Try the exercise again after each.

Hint 1

A field name must be followed by a link to a node. Ask for each notation whether its argument is a link.

Solution

Show the solution

The operation copies the node at TOP into the variable CARD. So CARD holds a whole node, not a link to a node. The address of the variable is LOC(CARD), and this address is a link to the copy.

(a) SUIT(CARD) is wrong. CARD is a node, not a link, so it is not a valid argument of a field name.

(b) SUIT(LOC(CARD)) is right. It is the suit field of the copy, and the copy has the same fields as the top card.

(c) SUIT(CONTENTS(CARD)) is wrong. CONTENTS applies to a link, and CARD is not one.

(d) SUIT(TOP) is right. It is the suit field of the top card itself, and the copy has the same suit.

So the answers are (b) and (d).

Check

Take the pile of (3). Then SUIT(TOP) =2= 2. After the copy, the variable CARD holds the fields (0,2,2,386," 2 D")(0, 2, 2, 386, \text{" 2 D"}), and SUIT(LOC(CARD)) =2= 2 too.

Remarks

The same distinction as in Exercise 2.1-7: a link variable holds an address, and a node variable holds the fields. The notation LOC turns the second into the first.

This solution is drafted, and a person has not reviewed it yet. The source.

In Lean

not stated yet The exercise is not stated in Lean yet.

The status is computed from the Lean build. The node of the map.

Something is wrong? Report it.