MantisBT - Core Inform
View Issue Details
0000786Core InformPhrases and functional programmingpublic2011-10-31 10:342014-05-07 07:34
gnomon 
graham 
normalseriousalways
closedfixed 
6G60 
6L02 
(serious) Compiler rejects valid code
0000786: The compiler doesn't accept the construct 'unless (condition), (phrase 1); otherwise (phrase 2).'
The attached code is rejected with the following error message:

Problem. You wrote 'otherwise say "You think about the apple."' : but inside an 'if ... begin'/'end if' an 'otherwise' (or 'else') must be a single word phrase, so it appears that the two ways to use 'otherwise' have been mixed up. It can either be used as 'if ... begin; ...; otherwise; ...; end if', or as 'if ..., ...; otherwise ...;'.
The Lab is a room. The player carries an apple.

Instead of thinking:
unless the apple is carried, say "You can't think of anything to think about.";
otherwise say "You think about your apple."
If we use "if not" instead of "unless" there's no problem:
---
Instead of thinking:
if the apple is not carried, say "You can't think of anything to think about.";
otherwise say "You think about your apple."
---


Using the block form works fine as well:
---
Instead of thinking:
unless the apple is carried:
say "You can't think of anything to think about.";
otherwise:
say "You think about your apple."
---
No tags attached.
Issue History
2011-10-31 10:34gnomonNew Issue
2011-11-02 13:00EmacsUserRelationship addedduplicate of 0000557
2011-11-02 13:01EmacsUserRelationship deleted0000557
2011-11-02 13:07EmacsUserNote Added: 0001442
2011-11-02 14:32gnomonNote Added: 0001444
2011-11-02 14:47gnomonNote Added: 0001445
2011-11-03 09:37EmacsUserNote Added: 0001446
2011-11-03 09:37EmacsUserStatusnew => confirmed
2014-01-12 13:36grahamNote Added: 0002280
2014-01-12 13:36grahamStatusconfirmed => resolved
2014-01-12 13:36grahamResolutionopen => fixed
2014-01-12 13:36grahamAssigned To => graham
2014-05-07 07:34jmcgrewFixed in Version => 6L02
2014-05-07 07:34jmcgrewStatusresolved => closed

Notes
(0001442)
EmacsUser   
2011-11-02 13:07   
Hmm. The relevant documentation is WI 11.8, in particular these bits:

- - - -
[Otherwise] can only be used as part of an "if ...:" or "unless: ...", and provides an alternative block of phrases to follow if the first block isn't followed.
- - - -

- - - -
When there is only a single phrase we can use the shortened form:
    if N is 2, say "Hooray, N is 2!";
    otherwise say "Boo, N is not 2...";
- - - -

So the first says that ``otherwise'' applies both to ``if'' and ``unless'' in block form, and the second gives a shortened form for ``if,'' possibly implying a similar shortened form for ``unless.'' I'll have to ask whether the attached source text is meant to be valid or the documentation is just unclear.
(0001444)
gnomon   
2011-11-02 14:32   
You may be right, but in that case I'd say the documentation is very unclear about this limitation. Both of those quotes give an example using "if"; I would never have thought that significant, especially as it has already said (in 11.6) that "unless" can be used whenever "if" can.

Besides, (though this may just be ignorance on my part,) why would this phrase even be illegal in the first place? Isn't "unless" basically the same thing as "if" (just with the condition negated)? It just feels confusing and inconsistent that they can't be used the same way.
(0001445)
gnomon   
2011-11-02 14:47   
Also, the error message is pretty unhelpful:
1) It says that "an 'otherwise' (or 'else') must be a single word phrase", which it already is (say "..."), and
2) the correct form it suggests ('if ..., ...; otherwise ...;') is exactly what was used, only with "unless" instead of "if".
(0001446)
EmacsUser   
2011-11-03 09:37   
Yes, this would be a weird asymmetry. For some reason I was reading the documentation very literally yesterday.
(0002280)
graham   
2014-01-12 13:36   
Well, in fact, this _was_ a bug, but it's now gone and the example text produces correct code.