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/Optimum.abwayax

From Gammapedia
Revision as of 07:28, 28 October 2007 by 24.243.13.121 (talk)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

/**

* Optimum.abwayax
* This is the optimal test case. This abwayax script should run flawlessly. 
* All work put into the abwayax interpreter now should be to get Optimum.abwayax to run flawlessly.
* Author: Abwayax
* October 28, 2007
*/

#use com.abwayax.abwayax.WindowFunctions
#use com.abwayax.abwayax.Math
#define Twenty-Seven:27

/* Primer on sigil meanings: $ denotes a scalar variable @ denotes an array % denotes a hash * denotes an object & denotes a function

Everything in abwayax is a first-class value, with the exception of namespaces (note to self: might want to reconsider that decision... but would it do any good?)

  • /

namespace Shoop { private *singleton;

&Whoop = { // constructor for a Shoop::Whoop object. // Although many might find this awkward, I quite like the separation of instance and namespace members. // Everything that has to do with Shoop::Whoop objects can thenceforth be found in the Shoop::Whoop constructor // instead of scattered all over the Shoop namespace. It almost simulates true class design.

*obj = Object(); // this statement creates the plain object private *obj->lazor = 0; // this adds an private instance field final *obj->charge = { // methods are added the same way as the fields. This must be marked final to prevent it // from being redefined later on. Marking the object itself as final only prevents foreign // code from adding new members, you have to mark each member as final to prevent it from // being redefined *this->lazor++; // *this refers to the object the method lives in }; final *obj->fire = { print("<"); for($i = 0; $i < *this->lazor; $i++) print("-"); print("[SHOOP DA WHOOP]"); for($i = 0; $i < *this->lazor; $i++) print("-"); println(">"); *this->lazor = 0; }; final *obj; // mark the object as final so no more members can be added return *obj;

// Note: Final is used quite liberally within &Shoop(). There is a reason - objects in abwayax are, upon creation, // mutable - members may be defined and redefined on a whim no matter what namespace or function is doing it. // Final objects cannot be modified in this manner, so if you want to make sure the object's implementation // cannot be changed then make it final. };

&Single = { // returns a singleton lazer object if(*singleton == null) *singleton = Whoop(); return *singleton; }; };

  • lazor = Shoop::Whoop(); // :: is the scope operator. When :: is used, abwayax first checks user-defined namespaces, then

// then, imported external namespaces (those included with #use or use()), then any external // namespaces in the com.abwayax.abwayax package, then finally it sees if the namespace name // is a fully qualified class name

  • lazor->charge(); // -> is the member access operator
  • lazor->charge();
  • lazor->charge();
  • lazor->fire(); // will print out shoop whoop

namespace MoreStuff { private %digits = [ "0" => "zero", "1" => "one", "2" => "two", "3" => "three", "4" => "four", "5" => "five", "6" => "six", "7" => "seven", "8" => "eight", "9" => "nine" ]; // hashes are created using [ ]

&DigitTranslator($arg) = { // abwayax supports a formal parameter list. If &DigitTranslator is called // with exactly one argument, the call goes to this function. DigitTranslator("1") will work // while DigitTranslator("1","2","fred") will either // look for a &DigitTranslator($arg,$arg2,$arg3) or &DigitTranslator with no arg list // &DigitTranslator() creates a function that will only accept an empty arg list. @digs = String::explode("",$arg); // dynamically loads the com.abwayax.abwayax.String external namespace foreach($digit In @digs) // or foreach(@digs As $digit) print(%digits[$digit] + " "); // both arrays and hashes are accessed with [] }; };

MoreStuff::DigitTranslator("53841259");

@vals = [Twenty-Seven,Twenty-Seven + 1,Twenty-Seven + 2,Twenty-Seven + 3]; // macro Twenty-Seven is expanded to read 27 // so this array contains 27,28,29,30

MsgBox(@vals[0]); // calls the com.abwayax.abwayax.WindowFunctions function MsgBox: Twenty-Seven!