!if(4)!if, !elif, !else, !endif - Conditional statements
!if condition
!iif condition body
The conditional directives allow statements to be executed only if a condition specified in the directive is met, as follows:-
The condition may be any logical condition as evaluated by the variable functions (e.g. &equal(4)) returning TRUE or FALSE. An integer value, non-zero evaluates TRUE, zero evaluates to FALSE. A non-numerical argument, such as a string is always FALSE.
The conditional body may be any MicroEmacs function, macro or directive with the exception of define-macro and !emacro. All directives that alter the execution of the macro are handled correctly within the !if statement (e.g. !goto, !return etc).
!iif provides an optimal way to write an !if statement with exactly one body line and no !elif or !else statements.
The following macro segment creates the portion of a text file automatically. (yes believe me, this will be easier to understand then that last explanation....)
!if &sequal %curplace "timespace vortex" insert-string "First, rematerialize\n" !endif !if &sequal %planet "earth" ;If we have landed on earth... !if &sequal %time "late 20th century" ;and we are then ml-write "Contact U.N.I.T." !elif &sequal %time "pre 20th century" ml-write "start praying for a miracle" !else insert-string "Investigate the situation....\n" insert-string "(SAY 'stay here Sara')\n" !endif !else set-variable %conditions @ml"Atmosphere conditions outside? " !if &sequal %conditions "safe" insert-string &cat "Go outside......" "\n" insert-string "lock the door\n" !else insert-string "Dematerialize..try somewhere else" newline !endif !endif
The first !if statement in the above example can be optimised to:-
!iif &sequal %curplace "timespace vortex" insert-string "First, rematerialize\n"
There is a convention in MicroEmacs macro code of using 2 spaces to separate the condition from the body of an !iif statement making it easier to locate the start of the body.
(c) Copyright JASSPA 2025
Last Modified: 2025/08/28
Generated On: 2025/09/29