"Sputnik" help  
Sputnik Help
Language Reference - Operators - Operator & (Bitwise And / Reference Creator)

Operator &

BitwiseAnd. e.g.

my $var = 50 & 48;
say $var;
// PRINTS
// 48

Reference creator. e.g.

my $test = "Hello";
my $p = &$test; // Now $p links to $test
// so if we edit $p it will edit $test
// we use * to resolve the ref before we edit
// we also surround it in ( ) to make sure
// Sputnik knows what we want to resolve
(*$p)[1] = 'Z';
// print it
say $test; // HZllo
say $p . " | " . *$p; // {Ref} | HZllo

When used with arrays you dont really need to use * to resolve the ref example:

my $test = array("Hello", "Cat");
my $p = &$test; // Now $p links to $test
// so if we edit $p it will edit $test
// we dont need to resolve the ref here
// since Sputnik can figure out its an array ref
$p[1] = "Dog";
// print it
printr $test;
// PRINTS
// Array
// (
//     [0] => Hello
//     [1] => Dog
// )

Function reference creator

// Create a function
Function Cat($a, $b)
{
    say "Meow! Value is: " . ($a + $b);
}
// Create a ref to it using the &
$Func = &Cat;
// Call it
$Func(10, 20);
// PRINTS
// Meow! Value is: 30

Class function reference creator

class Cat
{
    my $name;
    my $lives;
    Function __Construct($n, $l)
    {
        $name = $n;
        $lives = $l;
    }
    Function Meow()
    {
        say "$name says Meow!";
    }
}

class SuperCat inherits "Cat"
{
    my $speed;
    Function __Construct($n, $l, $s)
    {
        (&Cat:__Construct)($n, $l);
        $speed = $s;
    }
}

my $felix = new SuperCat("Felix", 9, 4);
my $fluffy = new SuperCat("Fluffy", 4, 6);

say "Felix lives: " . $felix->$lives;
say "Felix speed: " . $felix->$speed;
say "Fluffy lives: " . $fluffy->$lives;
say "Fluffy speed: " . $fluffy->$speed;
$felix->Meow();
$fluffy->Meow();

// PRINTS
// Felix lives: 9
// Felix speed: 4
// Fluffy lives: 4
// Fluffy speed: 6
// Felix says Meow!
// Fluffy says Meow!
Notice a referance is made to the original "__Construct" of the class "Cat" then called this is how class function references work.

To see a list of all the operators go here.


Contact
Cheryl (uberfox@hotmail.com)
Homepage
http://ubersoft.org