SICP车/ cdr练习题问题

时间:2011-03-26 10:10:29

标签: lisp scheme sicp

我正在这里为SICP尝试这个“在线辅导员”:http://icampustutor.csail.mit.edu/6.001-public/tutor.cgi?op=registration-page

我正在看以下问题:

  

假设我们已经评估过   表格

(define thing (cons (cons (cons 1 nil) nil)
                    (cons (cons 2 (cons 3 (cons 4 nil)))
                          (cons 2
                               (cons 3 nil))))) Write expressions
  

仅使用汽车,cdr和其中的东西   值是给定的列表结构   下方。

     

(1)
  1
  (2 3)
  (3)

我遇到了最后一个问题。我想出了一种使用反引号和非引号的方法,但是在线教程不接受答案。使用鸡计划的翻译:

#;3> (define nil '())
#;4>  (define thing (cons (cons (cons 1 nil) nil)
--->                         (cons (cons 2 (cons 3 (cons 4 nil)))
--->                               (cons 2
--->                                    (cons 3 nil)))))
#;5> 
#;5> thing
(((1)) (2 3 4) 2 3)

#;25> `(,(car(cdr(car(cdr thing)))))
(3)

还有其他办法吗?

1 个答案:

答案 0 :(得分:6)

看起来我只是在傻。这很好用:

(cdr(cdr(cdr thing)))