嵌套函数调用

发布于 2024-09-25 01:25:38 字数 687 浏览 3 评论 0原文

这已经让我彻底抓狂了。我有一个像这样的替代函数:

(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷心人i 2024-10-02 01:25:38

从 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 applies mysub to each pair of values in x and bind.

Using map doesn't work here, because you need to pass around the "current" value of body through each mysub call.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文