"Sputnik" help  
Sputnik Help
With ( arg[<blank>, <class>, <array>] )


Allows the execution of code within a block as if it was taking place within the class itself so there is no need for the -> operator and so on.


arg A class to use or an array to use or just empty braces.


With statements may be nested.

The With Statement in Sputnik provides a convenient way to execute code within a block as if it were taking place within a specific class. It eliminates the need for repetitive use of the "->" operator, simplifying code and enhancing readability.

By using the With Statement, you can set variables and call functions within the specified class without explicitly referencing the class instance each time. This feature streamlines your code and allows for cleaner syntax, making it easier to work with classes and their associated methods and properties.

In the example provided, a new class "Test" is defined, and an instance of the class is created. With the With Statement, the variables "$X" and "$Y" of the class instance are directly accessed and modified, and the "Hello()" function is called without the need for explicit class references.

The With Statement offers a concise and expressive way to interact with class members, enhancing code readability and reducing repetitive syntax. It's important to note that the With Statement can be nested, allowing for more complex scenarios where multiple class instances are involved.

In summary, the With Statement in Sputnik simplifies class interactions by providing a more intuitive syntax and reducing the need for repetitive class references. It contributes to cleaner and more readable code, improving developer productivity and code maintainability.




Complete example of using it with a class:

// Define a new class
Class Test
    my $X;
    my $Y;
    Function Hello()
        say "Hello";
// Create new intance of the class
$t = new Test();
// Use With to set the variables of the class
// and call functions within the class
// without having to do ->
    $X = 10;
    $Y = 20;
// Print the content of the class so we can view it
// Prints:
// Hello
// test Class
// (
//     [x] => 10
//     [y] => 20
// )


Cheryl (uberfox@hotmail.com)