Rebol 匿名函数行为很奇怪

发布于 2024-09-13 06:45:49 字数 283 浏览 2 评论 0原文

下面我的匿名 func 测试仅执行一次:

repeat i 5 [
  func[test][
    print test
  ] rejoin ["test" i]
]

我必须将其命名为能够按预期执行 5 次:

repeat i 5 [
  test: func[test][
    print test
  ] test rejoin ["test" i]
]

这很奇怪。难道真的不能在循环中使用匿名函数吗?

My anonymous func test below is executed only once:

repeat i 5 [
  func[test][
    print test
  ] rejoin ["test" i]
]

I am obliged to name it to be able to execute it 5 times as expected:

repeat i 5 [
  test: func[test][
    print test
  ] test rejoin ["test" i]
]

This is weird. isn't it really possible to use anonymous function in loops ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

好倦 2024-09-20 06:45:49

您的第一个代码示例只是定义匿名函数五次。它不调用它。添加一个 do ,一切都应该很好:

repeat i 5 [
  do func[test][
    print test
  ] rejoin ["test" i]
]

test1
test2
test3
test4
test5

Your first code example simply defines the anonymous function five times. It does not invoke it. Add a do and all should be well:

repeat i 5 [
  do func[test][
    print test
  ] rejoin ["test" i]
]

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