nil

Syntax

%nil(body)

Description

%nil(body) expands the body that is passed to it and throws away the output. The function %out() is defined in the context of the body, so that you can generate output only when you want.

This is useful for throwing away comments and whitespace in your code, and explicitly outputting the specific things that need to get outputted.

WARNING: the body of %nil(body) pushes a new context, so if you %set any variables in the argument to %nil, they will disappear when the %nil macro finishes. You can use %gset instead, or %set the macro outside the %nil, then %let the variable inside the %nil. This is also true of any macro in SMX that defines macros that are only defined in the body of the argument to that function, like %sql(), and the %col() macro that is only defined in the body passed to %sql.

Here are the rules:
- variables that are %set in the %nil will always revert after the nil
- variables that are %gset in the %nil will never revert after the nil
- variables that are %let in the %nil will not revert if they exist outside the %nil
- variables that are %let in the %nil will revert if they do not exist outside the %nil

Example

%set(var1,original value)
%set(var2,original value)
%set(var3,original value)
%nil(
        lots of comments
        also notice all the whitespace too!
        %set(var1,new value)
        %gset(var2,new value)
        %let(var3,new value)
        %let(var4,new value)
        %gset(var5,new value)
        %out(inside the nil%asc(10))
        %out(var1=%var1%%asc(10))
        %out(var2=%var2%%asc(10))
        %out(var3=%var3%%asc(10))
        %out(var4=%var4%%asc(10))
        %out(var5=%var5%%asc(10))
        %out(leaving the nil%asc(10))
)
var1=%var1%
var2=%var2%
var3=%var3%
var4=%var4%
var5=%var5%


outputs:




inside the nil
var1=new value
var2=new value
var3=new value
var4=new value
var5=new value
leaving the nil

var1=original value
var2=new value
var3=new value
var4=%var4%
var5=new value

notice how var1 went back, and var4 became undefined, and
var5 stuck around even though it was not set before the nil? 


See Also

null | set | gset | let