[MWForum]When or if
Jeff R
mwforum@lists.mathcats.com
Wed, 13 Nov 2002 09:11:34 +1100 (EST)
On Tue, 12 Nov 2002, Wendy Petti wrote:
> The one thing I don't understand about these primitives is the use of
> brackets. "when" uses two sets of bracketed commands while "if" only
> uses one set:
> when [timer > 1200] [do-the-next-step]
> if timer > 1200 [do-the-next-step]
Wendy
thanks for the example... that's what's really needed: an embodiment of
why WHEN is neccessary.
The syntactic difference arises from the way LCSI implementations are
writtem to reflect consostently what is actually going on(even tho' this
isn't always immediately evident!).
Logo evaluates from right to left. So, IF works with 2 'inputs', a
Condition, and a List of instructions that are to be run IF te condition
is met. WHEN evaluates two lists of instructions... the first, while it
looks like the Condition in an IF statement, is actually an Instruction
list, as with LAUNCH and FOREVER. Another way of implementing the effects
of WHEN could be:
LAUNCH [FOREVER [IF condition [instruction list]]]
Jeff