"Sputnik" help  
Sputnik Help
Language Reference - Preprocessor - Predefined Macros

Predefined Macros

Primary Macros
__File__ // The current input file
__Line__ // The current input file line number
__LineText__ // The current input file line text
__BaseFile__ // The main input file
__Counter__ // Sequential counter
            // that In conjunctionwith the ## operator,
            // this provides a convenient means to generate unique identifiers. 
__TimeStamp__ // Current (at preprocess) timestamp in the format of "Fri Jul 24 01:32:50 2020"
__Date__ // Current (at preprocess) date in the format of "Feb 12 1996"
__Time__ // Current (at preprocess) time in the format of "23:59:01"
__Win__ // True if the script is running under Windows
__MacOsx__ // True if the script is running under MacOsx
__Linux__ // True if the script is running under Linux
__x86_64__ // True if the script is running under an Intel/Amd x86-64 CPUs
__Arm__ // True if the script is running under an ARM CPU
__64Bit__ // True if the script is running on a 64Bit version of Sputnik
__32Bit__ // True if the script is running on a 32Bit version of Sputnik
__BigEndian__ // True if the script is running on a system using Big Endian
__LittleEndian__ // True if the script is running on a system using Little Endian
__UniqueLbl__ // Provides a unique label for use such as for anonymous function names
__UniqueVal__ // Provides a unique 64bit integer

Argument Macros

__VaArgs__   // All the arguments
##__VaArgs__ // 
__VaFirst__  // The first argument
__VaLast__   // The last argument
__VaCount__  // The argument count
argnth(x)    // A specific argument (x = index)
__VaNth1__   // A specific argument
__VaNth2__   // A specific argument
__VaNth3__   // A specific argument
__VaNth4__   // A specific argument
__VaNth5__   // A specific argument
__VaNth6__   // A specific argument
__VaNth7__   // A specific argument
__VaNth8__   // A specific argument
__VaNth9__   // A specific argument
__VaNth10__  // A specific argument
__VaNth11__  // A specific argument
__VaNth12__  // A specific argument
__VaNth13__  // A specific argument
__VaNth14__  // A specific argument
__VaNth15__  // A specific argument
__VaNth16__  // A specific argument
__VaNth17__  // A specific argument
__VaNth18__  // A specific argument
__VaNth19__  // A specific argument
__VaNth20__  // A specific argument
__VaNth21__  // A specific argument
__VaNth22__  // A specific argument
__VaNth23__  // A specific argument
__VaNth24__  // A specific argument
__VaNth25__  // A specific argument
__VaNth26__  // A specific argument
__VaNth27__  // A specific argument
__VaNth28__  // A specific argument
__VaNth29__  // A specific argument
__VaNth30__  // A specific argument
__VaNth31__  // A specific argument
__VaNth32__  // A specific argument
__VaNth33__  // A specific argument
__VaNth34__  // A specific argument
__VaNth35__  // A specific argument
__VaNth36__  // A specific argument
__VaNth37__  // A specific argument
__VaNth38__  // A specific argument
__VaNth39__  // A specific argument
__VaNth40__  // A specific argument
__VaNth41__  // A specific argument
__VaNth42__  // A specific argument
__VaNth43__  // A specific argument
__VaNth44__  // A specific argument
__VaNth45__  // A specific argument
__VaNth46__  // A specific argument
__VaNth47__  // A specific argument
__VaNth48__  // A specific argument
__VaNth49__  // A specific argument
__VaNth50__  // A specific argument
__VaNth51__  // A specific argument
__VaNth52__  // A specific argument
__VaNth53__  // A specific argument
__VaNth54__  // A specific argument
__VaNth55__  // A specific argument
__VaNth56__  // A specific argument
__VaNth57__  // A specific argument
__VaNth58__  // A specific argument
__VaNth59__  // A specific argument
__VaNth60__  // A specific argument
__VaNth61__  // A specific argument
__VaNth62__  // A specific argument
__VaNth63__  // A specific argument
__VaNth64__  // A specific argument
// You can go higher than 64 if you wish to

Using these predefined macros you can make your own debug feed out such as

#define MIN(a,b) ((a)<(b)?(a):(b)) 

#macro LogInfo(M, ...)
    Printf("[INFO] (%s:%d) " M "\n", __File__, __Line__, ##__VaArgs__);
#endm

LogInfo("Start %d", 88);
printf("Minimum between 10 and 20 is: %d\n", MIN(10, 20));
LogInfo("End");

// PRINTS
// [INFO] (Main.spk:13) Start 88
// Minimum between 10 and 20 is: 10
// [INFO] (Main.spk:15) End

You could also allow your script to use words instead of symbols by making a few macros for example

#define EQ      =
#define AND && #define ANDEQ &= #define BITAND & #define BITOR | #define COMPL ~ #define NOT ! #define NOTEQ != #define OR || #define OREQ |= #define XOR ^ #define XOREQ ^= $a EQ 1; $b EQ 2; $c EQ $a BITOR $b; say $c; if (1 AND 2) say "True"; else say "false"; // PRINTS // 3 // True

However its not a good idea to do that since them words are functions etc so if you must do this make sure the words you pick are not in use.

It is also possible to create entirely new kinds of loops using macros for example

#define LoopStr(x) foreach(my $c in \
                        split( \
                        gsub(x, '.', function($s) { return "0x{Hex(Asc(\$s), 2)} ($s),"; }), \
                        ','))
                        
LoopStr("Hello!")
{
    say $c;
}
// PRINTS
// 0x48 (H)
// 0x65 (e)
// 0x6C (l)
// 0x6C (l)
// 0x6F (o)
// 0x21 (!)

LoopStr("Cat!")
{
    say $c;
}
// PRINTS
// 0x43 (C)
// 0x61 (a)
// 0x74 (t)
// 0x21 (!)

This defines a new loop type called a "LoopStr" that loops each all characters in a string in hex form.


Macro _T(...)

Macro _T for the creation of Tuple classes:

// here is the definition of _T macro for easier creation of Tuples
#define _T(...) new Tuple(__VaArgs__)

Here is an example of it's use:

// create the array
my $array = array(  "Zero",
                    "One",
                    "Two",
                    "Three",
                    "Four",
                    "Five",
                    "Six", 
                    "Seven", 
                    "Eight"
                );
// splice and print
printr($array[_T(1, 3, 5, 0)]);
// PRINTS
// Array
// (
//     [0] => One
//     [1] => Three
//     [2] => Five
//     [3] => Zero
// )

Macro ZIP(...)

Macro ZIP for the creation of zipped arrays:

// here is the definition of ZIP macro
#define ZIP(...) Map(null, 0, __VaArgs__)

Here is an example of it's use:

my $a = [1, 2, 3];
my $b = ["a", "b", "c"];
my $c = [];
foreach(my list($x, $y) in ZIP($a, $b))
    $c[] = [$x, $y];
printr $c;
// PRINTS
// Array
// (
//     [0] => Array
//         (
//             [0] => 1
//             [1] => a
//         )
//     [1] => Array
//         (
//             [0] => 2
//             [1] => b
//         )
//     [2] => Array
//         (
//             [0] => 3
//             [1] => c
//         )
// )

Macro SWAP(a, b)

Macro _T for the creation


Macro _T(...)

Macro _T for the creation


Macro _T(...)

Macro _T for the creation


Macro _T(...)

Macro _T for the creation


Macro _T(...)

Macro _T for the creation


Macro _T(...)

Macro _T for the creation


Macro _T(...)

Macro _T for the creation


Macro _T(...)

Macro _T for the creation

 


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