🕸💡📝Fergus Duniho wrote on Fri, Dec 11, 2020 02:15 AM UTC:
I previously made the variable prefixes recursive. This allows something like this:
set m Mars;
set p m;
echo ##p;
The expression ##p returns #m, which returns Mars. So, "echo ##p" prints Mars. While helpful, this breaks some code I previously used to check whether a variable has been set. This code no longer works:
set m Mars;
if == #m "#m":
echo undefined;
else:
echo #m;
endif;
When m is defined, #m should be its value, which is Mars, and "#m" should be the string "#m". But thanks to recursion of variable prefixes, or so I presume, the string "#m" is converted to #m, which is then converted to the value of m. So, the test == #m "#m" still returns true when m has been defined. This makes it useless for telling whether a variable has been defined.
In its place, you can use the test == var m null. When a variable is undefined, calling it with var instead of a prefix will return null. So, this code works properly:
set m Mars;
if == var m null:
echo undefined;
else:
echo #m;
endif;
I previously made the variable prefixes recursive. This allows something like this:
The expression ##p returns #m, which returns Mars. So, "echo ##p" prints Mars. While helpful, this breaks some code I previously used to check whether a variable has been set. This code no longer works:
When m is defined, #m should be its value, which is Mars, and "#m" should be the string "#m". But thanks to recursion of variable prefixes, or so I presume, the string "#m" is converted to #m, which is then converted to the value of m. So, the test == #m "#m" still returns true when m has been defined. This makes it useless for telling whether a variable has been defined.
In its place, you can use the test == var m null. When a variable is undefined, calling it with var instead of a prefix will return null. So, this code works properly: