Anthony Borla wrote:
Greetings,
Playing around with nested loops, for example, to iterate through a list of
cells:
for rec(x:Xo y:Yo) in TheList do
...
for rec(x:X y:Y) in {List.drop TheList @Idx} do
...
TX := @Xo + @X
TY := @Yo + @Y
...
end
end
The above code works fine since different variable names are used in each
loop. I would have thought, though, that the '!' operator would have allowed
the following usage:
for rec(x:X y:Y) in TheList do
...
for rec(x:X y:Y) in {List.drop TheList @Idx} do
...
TX := @!X + @X
TY := @!Y + @Y
...
end
end
that is, allow selective exposure of same-name outer-scope variables so that
both outer-loop and inner-loop variables could be referenced using the same
name. My attempts in using this approach have failed, so am wondering
whether I have misunderstood the use of the '!' operator, or am otherwise
doing something wrong.
Cheers,
Anthony Borla
_________________________________________________________________________________
mozart-users mailing list
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users
The bang is not an outer-scope operator. It is just a way to prevent
introduction of a new variable. In essence its meaning is : "I really
want to use the variable with that name, not create a new variable
hiding it." The most common use of bang is in pattern-matching against
names:
Secret={NewName}
case Message
of wellKnown then ...
[] !Secret then ...
[] AnythingElse then ...
end
Without the bang, the second case would always match and introduce a
variable Secret local to the second clause.
Yves
_________________________________________________________________________________
mozart-users mailing list
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users