New! Reference Variables

Highly experimental but I now have implemented rudimentary Reference Variables and Pass-By-Reference for functions in SEL. For those who are not familiar with references in programming here’s how it is useful e.g.:

$x=5;
$y=\$x; ## $y is now a reference for $x
&print $$y; ## prints 5, note the DEREFERENCING with $$
$x=10;
&print $$y; ## prints 10 since $$y is effectively what $x is

Example of passing by reference to a function:
sub testPBR(\$x){
$$x=20;
return 5;
}

$z=&testPBR(\$x);
&print $x; ## prints 20! This is because $x has been modified in function
&print $$y; ## also prints 20 since $$y is still a reference to $x
&print $z; ## prints 5, this means you can modify as many vars as you like by calling a function and still have the return variable free for use.

Leave a Reply