Difference between revisions of "Evaluation brackets"

From Scriptwiki
Jump to: navigation, search
m
 
m
Line 14: Line 14:
 
Now lets see how it works out in more complex forms.
 
Now lets see how it works out in more complex forms.
 
   echo -a [ %a $+ [ %b ] ]
 
   echo -a [ %a $+ [ %b ] ]
This would echo "sometext%a" In this case %a is evaluated once and so is %b. Note that echoing [ %a $+ %b ] will not work.
+
This would echo "sometext%a" In this case %a is evaluated once and so is %b. Note that echoing [ %a $+ %b ] won't work.
 
   echo -a [ %a $+ [ [ %b ] ] ]
 
   echo -a [ %a $+ [ [ %b ] ] ]
 
This would echo "sometextsometext" since %a is evaluated once and %b twice.
 
This would echo "sometextsometext" since %a is evaluated once and %b twice.

Revision as of 23:27, 5 July 2006

Controles evaluation of identifiers / variables

 [ string ]

The evaluation brackets work a bit like $eval though you can add multiple things to evaluate at different levels at once.

Example:

 var %a = sometext
 var %b = % $+ a

Now %a is "sometext" and %b is "%a"

 echo -a [ %b ]

This would echo "%a" since %b is evaluated once. Note that this is the same as just echoing %b

 echo -a [ [ %b ] ]

This would echo "sometext" since %b is first evaluated to "%a" and then %a is evaluated to "sometext".

Now lets see how it works out in more complex forms.

 echo -a [ %a $+ [ %b ] ]

This would echo "sometext%a" In this case %a is evaluated once and so is %b. Note that echoing [ %a $+ %b ] won't work.

 echo -a [ %a $+ [ [ %b ] ] ]

This would echo "sometextsometext" since %a is evaluated once and %b twice.


Another example:

 var %name = fish
 var %surname = bot
 set % [ $+ [ %name ] $+ . $+ [ %surname ] ] m00

This would set %fish.bot to m00.