level 4
习题3-7,用reduce实现copy-list和表的reverse函数。
研究完reduce怎么用了,但是对此题很无奈,麻烦吧友给提供个思路
2012年10月09日 17点10分
1
level 8
我的版本:
(defun r-copy-list (list)
(reduce (lambda (a b)
(if (atom a)
(list a b)
(nconc a (cons b nil)))) list))
(defun r-reverse (list)
(reduce (lambda (a b)
(if (atom a)
(list b a)
(nconc (cons b nil) a))) list))
2012年10月10日 00点10分
2
level 8
第二个可以改成这样:
(defun r-reverse (list)
(reduce (lambda (a b)
(if (atom a)
(list b a)
(cons b a))) list))
2012年10月10日 00点10分
4
原来可以用lambda自定义函数,聪明啊!我一直在想Lisp自带的函数,呼呼
2012年10月10日 16点10分
level 6
不得不说这跟SICP里accumulate这块内容也太像了吧。。。
2012年10月12日 12点10分
5
level 1
(defun my-reverse (lst)
(reduce #'(lambda (init elt)
(cons elt init))
lst :initial-value nil)
2015年03月11日 04点03分
6