�< Section
"Sputnik" help  
Sputnik Help
Section

Description

The #section directive in the Sputnik programming language serves as a marker or anchor point within your source code file. It enables the expansion of macros to occur at specific locations, allowing a single macro to produce output in multiple places within the source code.

Varients

Parameters

<name>

A user-defined identifier for the section. This name is used to label the anchor point where macro expansions will occur.

Remarks

The #section directive is typically employed in conjunction with macros to facilitate modular and flexible code generation. When a macro is defined with content marked for a specific section using ^<name>, the macro output will be inserted at every occurrence of the corresponding #section <name> in the source file.

To learn more go the main preprocessor macro section.

Related

Block Macros

Example (#)

Example of usage:

#macro COMMAND(NAME, HELP)
// what to expand at the macro location
// in this case a string of the command name
// and a reference to the command
    #NAME => & NAME ## Command
// define the "cmd" section code
// this means anything here will be expanded
// to the "#section cmd" instead of where the
// macro itself is called
^cmd
    // makes the function literal
    Function NAME ## Command()
    {
        say #NAME " command executed";
        say "--> " #HELP;
    }
// define the "exec" section code
// this means anything here will be expanded
// to the "#section exec" instead of where the
// macro itself is called
^exec
    // calls the functions
    $commands[#NAME]();
#endm

// where the ^cmd expands to
#section cmd

// define the command class
// contains its name and function ref
class Command
{
    my $Name;
    my $Function;
};
// create the command array
my $commands = array(
    // where the macro expands to
    // create two commands
    COMMAND(quit, "Quits the app"),
    COMMAND(help, "Seriously?")
);


// where the ^exec expands to
#section exec

// PRINTS
// quit command executed
// --> "Quits the app"
// help command executed
// --> "Seriously?"

 

Example (.)

Example of usage:

 


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