Globals, Lists, and Kois …. [oh, my!]

Some staggering improvements to the language have occurred since the last post so staying true to the cause, I’ve gone back and edited all previous ones to keep them up to date and contains the latest syntax additions.

Out of the gate, I’m going to throw some new syntax your way:

koi + Person

def - firstName = "";
def - lastName = "";
def - age = 0;
def - eating = FALSE;
def - sleeping = FALSE;
def - pets = [];

fn + Initialize :fname :lname :a begin
   firstName = fname;
   lastName = lname;
   age = a;
   eating = FALSE;
   sleeping = FALSE;
   pets = [];

fn + getStatus begin
   puts firstName ^ " " ^ lastName;
   puts age;

   if eating == TRUE then
       puts "nummy nummy, eating";
       puts "stomach want food!";

   if sleeping == TRUE then
       puts "shh...sleeping";
       puts "Me want sleepy time!";

   puts "Number Of Pets: " ^ call length@pets;


After our koi decleration we have Globals.  Globals are variables that are bound to the scope of the koi instead of bound to the scope of a function.  Because these are at the koi level, they need access modifiers to indicate their visibility to the pond.  An important note about globals is that the value you assign does not stick! It is there soley to allow the compiler to infer the type while compiling your koi.

Next, we have our Initialize function. This is a special function (you can tell this because it’s capitalized) that is called when allocated and acts as your koi’s Constructor.   It’s here that we assign our arguments from an allocation statement and initialize our global since if left undone, they will be nil.

You’ll notice that pets is assigned ‘[]’. This is an empty list.  A list is a data structure in KoiFish that holds objects of any type.  If you wanted to initialize it with data you could do so like:

def emptyList = []; #empty list
def nonEmptyList = [1, "some string", emptyList, ["a new list"]];

A list also has functions associated with it like ‘push’, ‘pop’, ‘length’, ‘element’, ‘insertAt’, ‘concat’, and ‘toString’.

Going back to the koi, we next have a function that outputs the status of our Person.  The first new syntax you’ll see is the ‘^’ character.  This is KoiFish’s symbol for string concatenation.  It’s operation is simple, it attempts to convert the evaluated expression on it’s left to a string and concatenate it to the evaluated expression on the right after attempting to convert it to a string as well.  We can see this in more detail at the last statement in the function where it concatenates a string and a function call. Here it evaluates our call to length, which returns an integer, on our ‘pets’ global, which is a list, and then converts the evaluated result to a string and finally concatenates it with the string “Number Of Pets: “.

This entry was posted in Uncategorized and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s