::SHE+ILA:: example program [$83]

113
1
  • Squishy Plushie's avatar Artist
    Squishy Pl...
  • Prompt
    Read prompt
  • DDG Model
    DaVinci2
  • Access
    Public
  • Created
    1d ago
  • Try

More about ::SHE+ILA:: example program [$83]

Let's write an example program. Our module starts with the "GHOST", Global Hosting Online Segment Table, which is vaguely similar to C++'s "#include" or Java's "import" statement. It declares all the other modules that are referred to by our module, and sets up internal address registers to refer to their Segs in the datastore. It also implements an important security feature, by limiting which other Segs we have access to; the datastore (::SHE::) only allows access to Segs by means of those address registers, your program is not allowed to alter them at run time, only specify them by means of the "GHOST".
£::MATHS:: // Make a hidden kernel address register ...
£::UTILS:: // ...point to these Segs
The "£" (pound) operator is also used when declaring "private" or "protected" variables, this will be covered later when we cover "classes" or "structs". We can also set up local address registers with the "@" (at) operator in order to optimise array accessing :
Table <:: ((1, 2, 3), (4, 5, 6), (7, 8, 9));
ttyout(Table[2][2]); // Prints the number 5
@Foo <:: & Table[2]; // Point to the row (4, 5, 6)
ttyout (@Foo[2]); // Again prints 5
We can insert new data into an existing array with the "<<" (insert) operator :
Table [1] << ("hehehe", 42);
ttyout(Table[1]); // This now prints 1 2 3 hehehe 42
Finally for now we can get the length of an array with the "#" (hash) operator :
ttyout(# Table[1]); // Prints 5, since there are now five elements
ttyout(# Table); // Prints 5 3 3, giving the individual lengths of each row
Note that Table is now a "ragged array", i.e. its rows have differing numbers of elements.
Note also that subscripting starts from 1 (like Fortran), not 0 (like C++), because slot 0 is used internally to hold the names of the fields.
This will be explained when we cover "classes", "structs", and "records". Seeya :)

Comments


Loading Dream Comments...

Discover more dreams from this artist