:For i :In ⍳0
Forum rules
This forum is for discussing APL-related issues. If you think that the subject is off-topic, then the Chat forum is probably a better place for your thoughts !
This forum is for discussing APL-related issues. If you think that the subject is off-topic, then the Chat forum is probably a better place for your thoughts !
2 posts
• Page 1 of 1
:For i :In ⍳0
Hi,
I found the following error "amusing".
Given a function Foo
I did not expect it to error with a value error thus.
Somehow (but I don't understand how it really could!) I would have expected "i" to have been assigned a value!
(An "empty" scalar perhaps? LOL)
Ray
I found the following error "amusing".
Given a function Foo
- Code: Select all
∇ Foo;i
[1] :For i :In ⍳0
[2] i
[3] :End
[4] :If i>1
[5] 'over 1'
[6] :End
∇
I did not expect it to error with a value error thus.
- Code: Select all
Foo
VALUE ERROR: Undefined name: i
Foo[5] :If i>1
∧
Somehow (but I don't understand how it really could!) I would have expected "i" to have been assigned a value!
(An "empty" scalar perhaps? LOL)
Ray
Ray Cannon
Please excuse any smelling pisstakes.
Please excuse any smelling pisstakes.
-
ray - Posts: 221
- Joined: Wed Feb 24, 2010 12:24 am
- Location: Blackwater, Camberley. UK
Re: :For i :In ⍳0
The reference guide (p. 82 for release 18.0) gives a good description of the logic. Read literally, it does accurately describe the expected behaviour, but OTOH it could say just a tad more, since the null case is always important. One might helpfully add the words in red.
You could of course set the variable in advance:The way a :For loop operates is as follows. On encountering the :For, the expression to the right of :In is evaluated and the result stored. This is the control array. The control variable, named to the right of the :For, is then assigned the first value in the control array, and the code between :For and :EndFor is executed....
Note that if the control array is empty, the control variable is not set (or updated) and the code in the body of the :For structure is not executed.
i←⍬and life would be good.
- petermsiegel
- Posts: 143
- Joined: Thu Nov 11, 2010 11:04 pm
2 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group