Junction class

This class is designed for storing code and scope of its execution.
While referring to variables containing junction, Parser executes code within the stored scope.

Value of type
junction appears in variable:

…when it is assigned a code:

$junction{Code to be assigned to variable: ^do_something[]}

…when passing code as parameter:

@somewhere[]
^method{
Code passed as parameter^do_something_else[]}

@method[parameter]
#in this case junction will be passed into $parameter

…while referring to the name of a class method:
$action[$user:edit]
#$action[
$user:delete]
^action[parameter]

In this case,
$action contains reference to the method and its class. Calling action is then identical to calling ^edit[parameter].

…when referring to the name of an object method:

$action[$person.show_info]
^action[full]

In this case,
$action contains reference to the method and its object. Calling action is then identical to calling ^person.show_info[parameters].


@check_if_old_enough[age;order_alcohol]
^myif($age<21 && !$order_alcohol){
    Sorry, but we cannot sell strong drinks to ${age}-year-olds.
}

Example of using junction of expressions and code
@myif[condition;action][age]
$age(11)
^if($condition){
    $action
}

Note: parameter with expression is code calculating the expression. It is executed-i.e. expression is calculated-every time the parameter is referred to within the call.

In this case, operator
myif receives code which-along with everything else-outputs $age. Operator performs check and executes code within the stored scope ($condition and $action). Therefore, what is to be checked and what is to be output will not depend on whether local variable age exists or what its value is.

Example of checking if method exists
^if($some_method is junction){
    ^some_method[parameter]
}{
    no method
}

Method
some_method, will be called only if it is defined.


Copyright © 1997–2021 Art. Lebedev Studio | http://www.artlebedev.com Last updated: 24.12.2004