开发者

Rebol anonymous function behavior is weird

开发者 https://www.devze.com 2023-01-10 19:41 出处:网络
My anonymous func test below is executed only once: repeat i 5 [ func[test]开发者_Python百科[ print test

My anonymous func test below is executed only once:

repeat i 5 [
  func[test]开发者_Python百科[
    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 ?


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
0

精彩评论

暂无评论...
验证码 换一张
取 消