嵌套函数调用
这已经让我彻底抓狂了。我有一个像这样的替代函数:
(define (mysub x bind body) ;; x, bind, body are lists
...)
我需要这样调用该函数:
;;this is the explicit call for when length x = length bind = 2.
;;how do I generalize these nested calls?
;;in case it's not obvious, i'm passing mysub as the third parameter
;;to a previous mysub call
(mysub (first x) (first bind) (mysub (first (rest x)) (first (rest bind)) body)
这只是我作业的一小部分。
我尝试过使用带有 lambda 函数的映射,但我尝试过的每一种方法都会给我带来类似的结果:
( (x1)(bind1)(body) (x2)(bind2)(body) ) ;;I've found a million ways to get this
我需要调用它,直到 x 列表为空。 我不知道为什么这个想法让我如此困惑,非常感谢任何帮助。
This has been driving me absolutely nuts. I have a substitute function like this:
(define (mysub x bind body) ;; x, bind, body are lists
...)
I need to call the function like this:
;;this is the explicit call for when length x = length bind = 2.
;;how do I generalize these nested calls?
;;in case it's not obvious, i'm passing mysub as the third parameter
;;to a previous mysub call
(mysub (first x) (first bind) (mysub (first (rest x)) (first (rest bind)) body)
This is only small part of my homework.
I've tried using a map with lambda functions, but every approach I've tried leaves me with something like:
( (x1)(bind1)(body) (x2)(bind2)(body) ) ;;I've found a million ways to get this
I need to call this until the x list is empty.
I don't know why this idea is tripping me up so much, any help is greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从 length=2 的示例来看,我认为概括类似于
(foldr mysub body x bind)
,它将mysub
应用于x 中的每对值
和绑定
。使用
map
在这里不起作用,因为您需要通过每个mysub
调用传递body
的“当前”值。From the example with length=2, I think the generalization is something like
(foldr mysub body x bind)
, which appliesmysub
to each pair of values inx
andbind
.Using
map
doesn't work here, because you need to pass around the "current" value ofbody
through eachmysub
call.