Add NOP Instruction
tajmone opened this issue · comments
REQUEST
Add a new NOP instruction to do nothing.
Possible syntax: NOP
, DO NOTHING
, NOTHING
.
RATIONALE
In various occasions I've come across the need of a NOP instructions, e.g. when I'm forced to rely on the ELSE
part of a condition containing an expression that can't be NOT
-evaluated, or because I needed a temporary placeholder while drafting some code changes.
As a practical example, class expression can only be positively evaluated, so it's not possible to use If X NOT IsA someclass
(e.g. when trying to affect only instances of the ancestor class, when targeting an attribute that is inherited along the line).
The closest thing to a NOP right now is printing an empty string, but this is not possible inside RULEs:
WHEN location OF hero IS lit
THEN
IF location OF hero IsA cave
THEN "" -- do nothing! (doesn't work)
ELSE
-- Whatever needs to be done on `lit` locations that
-- are not cave instances...
The above example (possibly not 100% correct) roughly illustrates where a NOP instruction would be useful.
Hopefully, implementing a NOP shouldn't be too complex, nor have unexpected side effects (since it does nothing), and wouldn't affect backward compatibility.
For the example you gave the natural solution would be to switch the IF statement around:
...
IF location Of hero Not IsA cave ...
This would make more sense since the only action you want to do is when that expression is true.
I think that if you can find a situation where a NOP is actually needed I'd prefer to fix that rather than introduce a NOP statement.
EDIT: Just saw that you said that it's not possible to write "Not Isa", it should be according to the grammar. I'll have to investigate this.
Ok, so thank you for exploring the edges of the Alan language ;-)
It is not possible to use not
in a general way to negate the logical expression. It surely should. I'll get right on it.
Thanks for the prompt reply.
Definitely, being allowed to negate any expression would be useful — after all, they should evaluate to boolean, so there's is no reason why the NOT
operator shouldn't be usable here.
But I still think that a NOP could always come handy — even if as a temp placeholder, or a quick fix when editing code. Since it does nothing, it shouldn't cause harm either (except for the few bytes overhead it might occupy).