Reputation:
? MAKE "num RANDOM 1 ? IF [:num = 1] [print "Number is one.] [print "Number is zero.] [:num = 1] is neither FALSE nor TRUE!
Why won't this work? I'm using Imagine LOGO.
Upvotes: 2
Views: 4634
Reputation: 8030
Berkeley Logo (UCBLogo) allows the suggested syntax:
? ifelse [:num = 1] [print [Number is one.]] [print [Number is zero.]]
Number is zero.
However it goes beyond the original idea in LOGO: if
procedures expect either the word "true
or the word "false
, but the passed parameter is a literal list. Since the literal list is different than either words, LOGO complains that it's neither false nor true. Also implicit is that literal lists are not immediately evaluated, instead they're parsed as a literal list of words (and it's up to the procedure being called to decide what to do with them, either keeping them as a list of words, or requesting evaluation as code).
UCBLogo, on the other hand, allows three different things: the word "true
, the word "false
or a list:
A tf input must be the word TRUE, the word FALSE, or a list. If it’s a list, then it must be a Logo expression, which will be evaluated to produce a value that must be TRUE or FALSE. The comparisons with TRUE and FALSE are always case-insensitive.
https://people.eecs.berkeley.edu/~bh/docs/html/usermanual.html#CONTROL
Upvotes: 0
Reputation: 882078
It's been a long time since I used LOGO but I seem to recall that the condition didn't have square brackets around it.
You should try something like:
IFELSE :num = 1 [print [Number is 1]] [print [Number is 0]]
ifelse
is probably required for the one-or-the-other variant and I think you may need (although this may depend on your dialect) even more square brackets for a sentence with spaces :-)
Upvotes: 4