Gammapedia is archived. No new edits are allowed and no new accounts can be registered.

Ikepedia is the officially decreed successor to Gammapedia concerning Gammasphere canon.

Infinitypedia is another successor.

User:Abwayax/Abwayax programming language

From Gammapedia
Jump to navigationJump to search

Data types

  • Scalar: holds an alphanumerical value, denoted by $
  • Array: holds a collection of values of any data type, denoted by @
  • Hash: holds a collection of values mapped to keys, denoted by %
  • Object: a data structure with methods and instance variables, denoted by *
  • Function: an executable body of code, denoted by & (all functions are defined like this)

Scope

Global scope

Everything defined outside an object or function is considered to be in the global scope. A variable is defined as public by default; to mark it as private to the currently running script, prefix the variable declaration with private. To ensure that a variable is not redefined later in the script, mark it as final.

Function scope

Anything defined inside the body of a function is considered to be in "function scope". Variables defined within a function are local to the function and cannot be referenced outside it. However, any attempt to define a variable that has the same name as one in the global scope will reference the global variable; to get around this define the variable with the keyword local.

Object scope

"Object scope" refers to code in object methods. Object scope includes the instance fields and other methods of the object. In object scope, all members of the object, including private ones, are available for reading and writing. The special variables *this and *super are used to access the members of the current object and its superclass. At any time, a member (field or method) may be defined or redefined. Individual members of an object must be marked final to prevent redefinition or modification. Marking the object variable itself as final prevents any new members from being added to it.

Namespace scope

"Namespace scope" refers to all code enclosed in a namespace block. A namespace is a grouping of related functions and data. To create a namespace, use

namespace MyNamespace {
    // stuff here
}

Alternatively, to place all the code in a script file under a namespace, you can use

namespace MyNamespace;

To access data in a namespace, use

MyNamespace::nameOfVariable

Note that you have to add the appropriate prefix ($,%,@,&,*) to the beginning of the namespace name. In addition, if you want to import all of the members of a namespace into the global scope, you can use

using namespace MyNamespace;

Data marked private is available only to the namespace.

Access Modifiers

  • public: Every script can access the data.
  • protected: In objects, protected fields can only be accessed by methods of that object or a subclass.
  • private: In objects, private fields can only be accessed by methods of that object. In namespace scope, private variables are hidden from code outside the namespace.

1

$string = "A String with Spaces";
@words = split(" ",$string);
foreach(@words As $words) {
    print $string;
}

2

&foo = {
   print bar();
}
&bar = {
   return baz("foo");
}
&baz($arg) = {
   return "$arg equals $arg";
}
foo(); // foo equals foo

3

*myObj = object();
*myObj->method = {
   print "Method";
}
*myObj->method();

4

&Increaser = {
   *myObj = object();
   setType(*myObj,"Increaser");
   public-readonly *myObj->amount = 0;
   final *myObj->increase = {
       *this->amount++;
   }
   return *myObj;
}
*myIncreaser = Increaser();
*myIncreaser->increase();
*myIncreaser->increase();
print *myIncreaser->amount; // you can read it, but not write to it

5

&SuperIncreaser($step) = {
   *myObj = Increaser();
   setType(*myObj,"SuperIncreaser");
   final private *myObj->step = $step;
   final *myObj->superIncrease = {
       for($i = 0; $i < *this->step; $i++) *this->increase(); 
   }
   return *myObj;
}
*mySuperIncreaser = SuperIncreaser(40);
*mySuperIncreaser->increase(); // amount is 1;
*mySuperIncreaser->increase(); // amount is 2;
*mySuperIncreaser->superIncrease(); // amount is 42;

6

&square($num) = stringAsFunction("return \$num * \$num");
print square(5); // 25

7

&smethit($arg) = eval("smeth { $arg }");
smethit("Loop i from 1 to 10, increasing i by 1: Print i.");

8

malbolge {
(=<`:9876Z4321UT.-Q+*)M'&%$H"!~}|Bzy?=|{z]KwZY44Eq0/{mlk**
hKs_dG5[m_BA{?-Y;;Vb'rR5431M}/.zHGwEDCBA@98\6543W10/.R,+O<
} // Hello, world.

9

java {
    JFrame frame = new JFrame();
    frame.add(new JTextArea(mySuperIncreaser.amount));
} smeth {
    Call method setTitle on frame with parameter "Dynamically Generated Project F Window".
}
*frame->setSize();
*frame->setVisible(true);

10

&pfeval($stuff) = { return eval($stuff); }
java {
    System.out.println(pfeval("*frame->getTitle()"));
} // note: the Project F eval function is not carried over into embedded languages because almost every language has its own eval

11

*aList = JavaObject("java.util.ArrayList");
*aList->add("woot");
*aList->add("pwn");
print *aList->toString();

12

/* lol */
maybe() {
    print "This line has a 50% chance of being printed.";
}
maybe(4/5) {
    print "but this line has an 80% chance";
}