SICP-2.3.1节练习
练习 2.53 - 2.55
练习 2.53:
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))) (cadr '((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)
练习 2.54:
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))
练习 2.55:
Eva Lu Ator types to the interpreter the expression (car ''abracadabra) To her surprise, the interpreter prints back quote. Explain.
我的解答:
'abracadabra 是 (quote abracadabra) 的简写形式,试看下面各个表达式的运行结果: scheme@(guile-user)> 'abracadabra abracadabra scheme@(guile-user)> (quote abracadabra) abracadabra scheme@(guile-user)> (quote 'abracadabra) (quote abracadabra) scheme@(guile-user)> (quote (quote abracadabra)) (quote abracadabra) scheme@(guile-user)> ''abracadabra (quote abracadabra) scheme@(guile-user)> (car ''abracadabra) quote
Apr 17, 2011 09:52:15 PM
怎么最近没更新了呀,一直觉得Scheme是一种很有趣的东西。
Apr 17, 2011 11:35:18 PM
谢谢关注,
只是这些天太忙了,没时间看书了,
估计还得好些天。
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.
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