# SICP-2.3.1节练习

lispor posted @ Mar 21, 2011 02:14:17 AM in Scheme with tags SICP , 3085 阅读

```What would the interpreter print in response to evaluating each of the following expressions?
(list 'a 'b 'c)
(list (list 'george))
(cdr '((x1 x2) (y1 y2)))
(pair? (car '(a short list)))
(memq 'red '((red shoes) (blue socks)))
(memq 'red '(red shoes blue socks))
```

```scheme@(guile-user)> (list 'a 'b 'c)
(a b c)
scheme@(guile-user)> (list (list 'george))
((george))
scheme@(guile-user)> (cdr '((x1 x2) (y1 y2)))
((y1 y2))
scheme@(guile-user)> (pair? (car '(a short list)))
#f
scheme@(guile-user)> (memq 'red '((red shoes) (blue socks)))
#f
scheme@(guile-user)> (memq 'red '(red shoes blue socks))
(red shoes blue socks)```

```Two lists are said to be equal? if they contain equal elements arranged in the same order. For
example,
(equal? '(this is a list) '(this is a list))
is true, but
(equal? '(this is a list) '(this (is a) list))
is false. To be more precise, we can define equal? recursively in terms of the basic eq? equality of
symbols by saying that a and b are equal? if they are both symbols and the symbols are eq?, or if
they are both lists such that (car a) is equal? to (car b) and (cdr a) is equal? to (cdr b). Using
this idea, implement equal? as a procedure.
```

```(define (equal? a b)
(if (and (pair? a)) (pair? b))
(and (equal? (car a) (car b))
(equal? (cdr a) (cdr b)))
(eq? a b))
```

```Eva Lu Ator types to the interpreter the expression
To her surprise, the interpreter prints back quote. Explain.
```

```'abracadabra 是 (quote abracadabra) 的简写形式，试看下面各个表达式的运行结果：
quote```

ee.zsy 说:
Apr 17, 2011 09:52:15 PM

Lispor 说:
Apr 17, 2011 11:35:18 PM

Michael Lake 说:
Nov 28, 2018 04:03:28 PM

A list of the program is prepared or the convenience of the candidates. The matter of the concern and bestdissertation.com reviews is implied for the youngsters. The term is reflected for the optional items for the humans in these varied items for the persons.

seo service UK 说:
Jan 13, 2024 10:53:35 PM

This is a great article thanks for sharing this informative information. I will visit your blog regularly for some latest post. I will visit your blog regularly for Some latest post

(输入验证码)
or Ctrl+Enter