The scope of "Range foreach" depends on the number of invocation arguments

"eebel_igman" <[email protected]> Mon, 30 Jul 2012 21:50:57 -0000
Newsgroups gmane.comp.lang.io
Message-ID <[email protected]>
Hello Again

Why is the callers scope not visible in the execution scope of the Range foreach message, when the Range foreach message is invoked with only a single argument - the message tree. When foreach is invoked with the two arguments - value and message tree - then the callers scope is visible as expected.

Example:
replicate := method(
        string, numberOfTimes,
        res := ""
        Range 1 to(numberOfTimes) foreach(v, res = res .. string)
)

replicate_throws_exception := method(
        string, numberOfTimes,
        res := ""
        Range 1 to(numberOfTimes) foreach(res = res .. string)
)

replicate("a", 10) println
replicate_throws_exception("a", 10) println

The output is the following:
$ io foreach_strange_behavior.io
aaaaaaaaaa

  Exception: Slot res not found. Must define slot using := operator before updating.
  ---------
  updateSlot                          foreach_strange_behavior.io 10
  Object replicate_throws_exception    foreach_strange_behavior.io 14
  CLI doFile                           Z_CLI.io 140
  CLI run                              IoState_runCLI() 1

Best regards, Eebel.