Discussion:
[Lisp-cn] ANSI Common Lisp 习题10.3
宋为@凉拌茶叶
2014-05-21 14:32:12 UTC
Permalink
3. 定义一个宏,接受一个数字 /n/ ,伴随着一个或多个表达式,并返回第 /n
(let ((n 2))
(nth-expr n (/ 1 0) (+ 1 2) (/ 1 0)))
3
想了很久没搞出来,网上查到的所有答案在SBCL上都跑不下来 T_T

求解
--
--
Lisp-cn(Lisp中文用户组)
CLUG http://lisp.org.cn

---
您收到此邮件是因为您订阅了 Google 网上论坛的“Lisp-cn(Lisp中文用户组)”论坛。
要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到lisp-cn+***@googlegroups.com。
要查看更多
savior michael
2014-05-21 15:22:21 UTC
Permalink
(defmacro eval-nth-expr (n &rest lst)
`(let ((exp (nth ,n (quote ,@(list lst)))))
(eval exp)))



(eval-nth-expr 2 (/ 2 4) (+ 1 2) (* 4 5)) ==> 20 (it is the result of (*
4 5))



================================================
3. 定义䞀䞪宏接受䞀䞪数字 /n/ 䌎随着䞀䞪或倚䞪衚蟟匏并返回第 /n
(let ((n 2))
(nth-expr n (/ 1 0) (+ 1 2) (/ 1 0)))
3
想了埈久没搞出来眑䞊查到的所有答案圚SBCL䞊郜跑䞍䞋来 T_T
求解
--
--
Lisp-cn(Lisp䞭文甚户组)
CLUG http://lisp.org.cn

---
悚收到歀邮件是因䞺悚订阅了 Google 眑䞊论坛的“Lisp-cn(Lisp䞭文甚户组)”论坛。
芁退订歀论坛并停止接收歀论坛的电子邮件请发送电子邮件到lisp-cn+***@googlegroups.com。
芁查看曎倚选项请访问 https://groups.google.com/d/optout。
祕密
2014-05-21 17:44:32 UTC
Permalink
答案沒有問題啊

(defmacro nth-expr (n &body body)
(if (integerp n)
(nth n body)
`(case ,n
,@(let ((i -1))
(mapcar #'(lambda(x) `(,(incf i) ,x)) body)))))



涌拌茶葉斌 2014幎5月21日星期䞉UTC+8䞋午10時32分12秒寫道
3. 定矩䞀個宏接受䞀個敞字 /n/ 䌎隚著䞀個或倚個衚達匏䞊返回第 /n
(let ((n 2))
(nth-expr n (/ 1 0) (+ 1 2) (/ 1 0)))
3
想了埈久沒搞出䟆網䞊查到的所有答案圚SBCL䞊郜跑䞍䞋䟆 T_T
求解
--
--
Lisp-cn(Lisp䞭文甚户组)
CLUG http://lisp.org.cn

---
悚收到歀邮件是因䞺悚订阅了 Google 眑䞊论坛的“Lisp-cn(Lisp䞭文甚户组)”论坛。
芁退订歀论坛并停止接收歀论坛的电子邮件请发送电子邮件到lisp-cn+***@googlegroups.com。
芁查看曎倚选项请访问 https://groups.google.com/d/optout。
祕密
2014-05-21 17:50:20 UTC
Permalink
答案没有问题啊

(defmacro nth-expr (n &body body)
(if (integerp n)
(nth n body)
`(case ,n
,@(let ((i -1))
(mapcar #'(lambda(x) `(,(incf i) ,x)) body)))))

由于n䞺2衚蟟匏䞺(/ 1 0)因歀䌚星瀺error

涌拌茶葉斌 2014幎5月21日星期䞉UTC+8䞋午10時32分12秒寫道
3. 定矩䞀個宏接受䞀個敞字 /n/ 䌎隚著䞀個或倚個衚達匏䞊返回第 /n
(let ((n 2))
(nth-expr n (/ 1 0) (+ 1 2) (/ 1 0)))
3
想了埈久沒搞出䟆網䞊查到的所有答案圚SBCL䞊郜跑䞍䞋䟆 T_T
求解
--
--
Lisp-cn(Lisp䞭文甚户组)
CLUG http://lisp.org.cn

---
悚收到歀邮件是因䞺悚订阅了 Google 眑䞊论坛的“Lisp-cn(Lisp䞭文甚户组)”论坛。
芁退订歀论坛并停止接收歀论坛的电子邮件请发送电子邮件到lisp-cn+***@googlegroups.com。
芁查看曎倚选项请访问 https://groups.google.com/d/optout。
宋为@凉拌茶叶
2014-05-22 02:54:58 UTC
Permalink
嗯,后来发现了,这个答案仅仅是索引不对
答案没有问题啊
(defmacro nth-expr (n &body body)
(if (integerp n)
(nth n body)
`(case ,n
(mapcar #'(lambda(x) `(,(incf i) ,x)) body)))))
由于,n为2表达式为(/ 1 0),因此会显示error
涼拌茶葉於 2014年5月21日星期三UTC+8下午10時32分12秒寫道:
3. 定義一個宏,接受一個數字 /n/ ,伴隨著一個或多個表達式,並返回第 /n
(let ((n 2))
(nth-expr n (/ 1 0) (+ 1 2) (/ 1 0)))
3
想了很久沒搞出來,網上查到的所有答案在SBCL上都跑不下來 T_T
求解
--
--
Lisp-cn(Lisp中文用户组)
CLUG http://lisp.org.cn

---
您收到此邮件是因为您订阅了 Google 网上论坛的“Lisp-cn(Lisp中文用户组)”论坛。
要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到lisp-cn+***@googlegroups.com。
要查看更多选项,
宋为@凉拌茶叶
2014-05-22 03:00:16 UTC
Permalink
当时以为答案求值了所有表达式
嗯,后来发现了, 这个答案仅仅是索引不对
答案没有问题啊
(defmacro nth-expr (n &body body)
(if (integerp n)
(nth n body)
`(case ,n
(mapcar #'(lambda(x) `(,(incf i) ,x)) body)))))
由于,n为2表达式为(/ 1 0),因此会显示error
涼拌茶葉於 2014年5月21日星期三UTC+8下午10時32分12秒寫道:
3. 定義一個宏,接受一個數字 /n/ ,伴隨著一個或多個表達式,並返回
第 /n
(let ((n 2))
(nth-expr n (/ 1 0) (+ 1 2) (/ 1 0)))
3
想了很久沒搞出來,網上查到的所有答案在SBCL上都跑不下來 T_T
求解
--
--
Lisp-cn(Lisp中文用户组)
CLUG http://lisp.org.cn

---
您收到此邮件是因为您订阅了 Google 网上论坛的“Lisp-cn(Lisp中文用户组)”论坛。
要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到lisp-cn+***@googlegroups.com。
要查看更多选项,请访问 https://grou
桃源村
2014-05-23 12:39:54 UTC
Permalink
mylisp -- 发自 Android 眑易邮箱 圚2014幎05月21日 22:32 "宋䞺@凉拌茶叶"写道 >  3. 定义䞀䞪宏接受䞀䞪数字 /n/ 䌎随着䞀䞪或倚䞪衚蟟匏并返回第 /n >     / 䞪衚蟟匏的倌: > > >  (let  ((n  2)) >      (nth-expr  n  (/  1  0)  (+  1  2)  (/  1  0))) > 3 想了埈久没搞出来眑䞊查到的所有答案圚SBCL䞊郜跑䞍䞋来 T_T 求解 -- -- Lisp-cn(Lisp䞭文甚户组) CLUG http://lisp.org.cn --- 悚收到歀邮件是因䞺悚订阅了 Google 眑䞊论坛的“Lisp-cn(Lisp䞭文甚户组)”论坛。 芁退订歀论坛并停止接收歀论坛的电子邮件请发送电子邮件到lisp-cn+***@googlegroups.com。 芁查看曎倚选项请访问 https://groups.google.com/d/optout。
--
--
Lisp-cn(Lisp䞭文甚户组)
CLUG http://lisp.org.cn

---
悚收到歀邮件是因䞺悚订阅了 Google 眑䞊论坛的“Lisp-cn(Lisp䞭文甚户组)”论坛。
芁退订歀论坛并停止接收歀论坛的电子邮件请发送电子邮件到lisp-cn+***@googlegroups.com。
芁查看曎倚选项请访问 https://groups.google.com/d/optout。
Jeova Sanctus Unus
2014-05-24 00:53:26 UTC
Permalink
42
Post by 桃源村
mylisp
--
发自 Android 眑易邮箱
3. 定义䞀䞪宏接受䞀䞪数字 /n/ 䌎随着䞀䞪或倚䞪衚蟟匏并返回第 /n
(let ((n 2))
(nth-expr n (/ 1 0) (+ 1 2) (/ 1 0)))
3
想了埈久没搞出来眑䞊查到的所有答案圚SBCL䞊郜跑䞍䞋来 T_T
求解
--
--
Lisp-cn(Lisp䞭文甚户组)
CLUG http://lisp.org.cn
---
悚收到歀邮件是因䞺悚订阅了 Google 眑䞊论坛的“Lisp-cn(Lisp䞭文甚户组)”论坛。
芁查看曎倚选项请访问 https://groups.google.com/d/optout。
--
--
Lisp-cn(Lisp䞭文甚户组)
CLUG http://lisp.org.cn
---
悚收到歀邮件是因䞺悚订阅了Google眑䞊论坛䞭的“Lisp-cn(Lisp䞭文甚户组)”论坛。
芁查看曎倚选项请访问https://groups.google.com/d/optout。
--
--
Lisp-cn(Lisp䞭文甚户组)
CLUG http://lisp.org.cn

---
悚收到歀邮件是因䞺悚订阅了 Google 眑䞊论坛的“Lisp-cn(Lisp䞭文甚户组)”论坛。
芁退订歀论坛并停止接收歀论坛的电子邮件请发送电子邮件到lisp-cn+***@googlegroups.com。
芁查看曎倚选项请访问 https://groups.google.com/d/optout。
Loading...