# SICP Solutions

### Chapter 4, Metalinguistic Abstraction

#### simple-query example

In simple query, delay ensures that we first find/match assertions and then on demand we evaluate rules. This behaviour will be same even if the underlying scheme is evaluates arguments right to left!

In some cases, using delay, postpones the infinite loop and even produce some result(if there are any assertions matched) while going into infinite loop.

Consider the following:

Evaluating the query (tmp1 a)

• With delay(original):
• Without delay(as suggested in exercise):

#### disjunction example

Our and works procedurally in left to right order so should be the case with or. Thus if any clause in or can return some answer from a clause then instead of first evaluating all the clauses it would be better to first generate the first answer found!

Again like above this ensures left to right order as well as generates answers if found in earlier clauses even if later clauses result in infinite loop.

Consider the following example:

Evaluating the query (tmp2 a)

• With delay(origninal):
• Without delay(as suggested in exercise):