views:

48

answers:

1

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 ?

+2  A: 

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
Sunanda