AL language

AL is a new language (acronym of Algoid Language). It was inspired by java, python, smalltalk and lua, but it is not these languages.
The aim of Algoid is to be simple but fully featured and our goal is to help you learn how to use different paradigms:
Imperative, procedural, functional, recursive, object-oriented (multi-inheritance) and aspect-oriented programming.
It implements powerful idioms like meta-object protocol (from python) and cascade (from smalltalk).
It is a great platform to learn how to use these paradigms and idioms progressively.
And because one day we hope you will work with an industry standard language (certainly close to c/java and c++) AL is as close as possible to their respective syntaxes.
The syntax involving braces may seem a little complicated when you start experimenting, but you will see how easily you get used to it!

In addition, the fundamental principle of AL are :

  • A function is an expression.
  • An object is an expression.
  • An expression is an object.
  • So a function is a meta-function and an object is a meta-object.

Everything else in AL is inspired by the languages I have listed above.

Index

Language structure


Language primitives


[dynamic] type


[dynamic] void


[dynamic] boolean


[dynamic] number


[dynamic] string


[dynamic] array


[dynamic] function


[dynamic] object


API root


al


al.order


al.combine


al.types


util


math


ui


text


algo.color


algo


algo.stamp


instruction

The unit of expression is a statement.
In AL Semicolon is entirelly optional. It exists because AL is inspired from C and in C semicolon is mendatory. So you can write your program with ou without. Prefer with, because the majority of languages ??requested it. It's become a habit.

SYNTAX : instruction [';'] 

Instruction are divided in two familly : the expression and the controls (imperative one).

block

Block is a self scoped suite of instructions.
Scope means that if variables are declared into it, its will be deleted a the end of the block.

SYNTAX : '{' {[instruction]} '}' 

expression

Al support several types of expression : VOID, BOOLEAN, NUMBER, STRING, FUNCTION, OBJECT, ARRAY.
AL is a dynamically typed language, so it is not necessary to manage types. Transtyping is automatic.

SYNTAX :
nil
true | false
nan | infinity | number
'"' string '"'
array | function | object
ident '[' expr ']' 

Binary operators in expressions can be :

symboldescription
&&(boolean) and : true and true is true
||(boolean) or : true or false is true
==is equals
!=is differents
<is less than
>is greater than
<=is less or equals
>=is greater or equals
+(number) plus
-(number) minus
*(number) multiply
/(number) divide
%(number) modulo
..(string) concat
->(function) then

unary operators in expressions can be :

symboldescription
!(boolean) not : !true is false
-(number) minus : -i is equivalent to 0 - i
++increment : i++ is equivalent to i = i + 1 or i += 1
--decrement : i-- is equivalent to i = i - 1 or i -= 1

 
example: 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

        ui.showLog();
        set i = 100 / 2 + 4 * -2;
        i++;
        set b = true || false;
        util.log("result : " .. i .. " and 1 or 0 : " .. b);
     


AL also support several constant values: true, false, nil, nan, infinity:
- true and false are the two boolean values
- nil represents null value
- nan for "not a number" (result of an unautorized operation)
- infinity for infinite number (use -infinity for negative one)

statement

Statement declare a new variable in the current scope.
Declared variable can be used for future in the same scope.

SYNTAX : 'set' ident [symbol expr] ';' 

symbol can be :

symboldescription
=equal i = n;
+=plus and equal, equivalent to i = i + n
-=minus and equal, equivalent to i = i - n
*=multiply and equal, equivalent to i = i * n
/=divide and equal, equivalent to i = i / n
%=modulo and equal, equivalent to i = i % n
..=concatenate and equal (for string), equivalent to s = s .. t
->=then and equal (for function), equivalent to f = f -> g

Statement is itself an expression.

 
example: 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

      ui.showLog();
      set i = 10;
      i += 20;
      util.log("result: " .. i);
     

while

While is the first control instruction. It loops while condition is true.

SYNTAX : 'while' '(' condition ')' block 

 
example: 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

      ui.showLog();
      set i = 10;
      while (i-- > 0) {
        util.log("result: " .. i);
      }
     

do

Loop until condition become false. Condition is tester after execution.

SYNTAX : 'do' block 'until' '(' condition ')' 

 
example: 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

      ui.showLog();
      set i = 10;
      do {
        util.log("result: " .. i);
      } until (i-- <= 0)
     

loop

Loop repeats a block of code while limit is reached.

SYNTAX : 'loop' (limit) block 

 
example: 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

      ui.showLog();
      set a = 0;
      loop (10) {
        util.log("loop: " .. a);
        a++;
      }
     

for

For loop repeats a block of code while a control variable runs through an arithmetic progression.

SYNTAX : 'for' ([initialization] ';' [condition] ';' [progression]) block 

 
example: 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

      ui.showLog();
      for (set i = 0; i < 10; i++) {
        util.log("loop: " .. i);
      }    
     

if

If execute the block if condition is true and else otherwise.
Elseif are executed if the other condition is true

SYNTAX : 'if' '(' condition ')' block {['elseif' '(' condition ')' block]} ['else' block] 

 
example: 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

      ui.showLog();
      for (set i = 0; i<4; i++) {
        if (i == 0) {
          util.log("i is 0");
        } elseif (i == 1) {
          util.log("then 1");
        } else {
          util.log("then others");
        }
      }    
     

In AL language, IF is also an expression. It can be user to describe a conditional value.

 
example: 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

      ui.showLog();
      set i = 0;
      set s = if (i==0) "zero" elseif (i == 1) "one" else "other";
      util.log ("if i=" .. i .. ", s=" .. s);
     

function

Define a reusable and nested scoped part of code with parameters.
The particularity of AL it that functions are considered as data. Function is an expression, so function declaring can be terminated by a semicolon.

SYNTAX : 'function' ['(' [arg [{',' arg}]] ')'] '{' instruction '}' 

 
example: 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

      set f = function (x) {
        ui.message("x parameter is " .. x);
      };
      f (10);    
     

lambda

A lambda is a function with a simplified syntax. It can only been used as parameter of another function. And be designed to lighten the writing of functors in functional style.

SYNTAX : ['(' [arg [{',' arg}]] ')'] '{' instruction '}' 

 
example: 
  • 1
  • 2
  • 3
  • 4
  • 5

      util.pulse({
        algo.go(10);
      }, 50);
     

object

Define a reusable scope composed of a set of attributes, methods and nested objects.
Statements can be : attributes (variable), methods (functions) and another nested object.

SYNTAX : 'object' '(' {parent {[ ',' parent ]}} ')' '{' declarations '}' 

 
example: 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

      ui.showLog ();
      set o = object () {
        set a = 0;
        set b = "my b attribut";
      };
      util.log ("o.a = " .. o.a);
      util.log ("o.b = " .. o.b);
     

All functions declared into an object are called methods. Methods are the object set of behaviours.
A method designed to access to an attribut is called accessor.
A method designed to modify an attribute is called mutator.

 
example: 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

      set o = object () {
        set a = 0;
        // the a setter
        set setA = function(a) {
          this.a = a;
        };
        // the a getter
        set getA = function() {
          return this.a;
        };
        // a method
        set doubleA = function() {
          this.a = this.a * this.a;
        };
     
      };
     
      o.setA(2);
      ui.message("o.a parameter is " .. o.getA());
      o.doubleA();
      ui.message("and its double is " .. o.getA());    
     

Objects can be duplicated and keeping their internal structure. It is called cloning object.
In AL objects are created and can be cloned. It exists two maneers to clone; The new statement create a new duplicated object with same states and the clone method.
This last one assign the parameters passed to her to the states of the new object.

 
example: 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

      ui.showLog();
      set o = object () {
        set a = 7;
        set b = "my attribute b";
        set toString = function () {
          return "o {a=" .. a .. ", b=" .. b .. "};"
        };
      };
      set p = o.clone (8, "another parameter");
      util.log (o);
      util.log (p);
     

This is a reference to the object himself.

 
example: 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

        ui.showLog();
      set o = object () {
        set a;
        set setA = function (a) {
          this.a = a;
        };
        set getA = function () {
          return this.a;
        };
      };
      o.setA (7);
      util.log (o.getA());
     

Supers[n] accesses to the list of super objects (multi-inheritance).

 
example: 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

      set q = object() {
        set ret7 = function () {
          return 7;
        };
      };
     
      set p1 = object() {};
     
      set p2 = object(q) {};
     
      set o = object (p1, p2) {
        set test = function () {
          return this.supers[1].supers[0].ret7();
        };
      };
     
      ui.message("o.test result is " .. o.test());     
     

array

Define a list of elements or a dictionary indexed by any expression.
When defining nested arrays, the keyword 'array' is only required for the first level of the array (the root). It then becomes optional.

SYNTAX :
item : [ expr ':' ] expr
array : [ 'array' ]1 '{' item [{ ',' item }] '}' 

 
example: 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

      ui.showLog();
      set a = array {7, 8, 9, 10, 11};
      for (set i=0; i < a.length(); i++) {
        util.log("a[" .. i .. "] is " .. a[i]);
      }
      // or more elegent
      a.each (function (item, index) {
        util.log("a[" .. index .. "] is " .. item);
      });
     

Array can already been used as a dictionary.
It keeps its list capabilities, but its values are accessible by a key expression :

 
example: 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

      ui.showLog();
      set a = array {"a" : 7, "b" : 8, "c" : 9, "d" : 10, "e" : 11};
      a.each (function (item, index, key) {
        util.log("a[" .. key .. "] is " .. item);
      });
     
      util.log ("Find a[c] = " .. a["c"]);
     

Algoid framework

A language comprises a set of primitives, control structures and status modifiers.
A framework is a set of tools containing functions and objects.

A feature of the AL langage is that every value in the language has associated methods.
This feature was inspired by SmallTalk (cascade) and Python (magic methods).

type

In AL all variables inherits from type object. When any variable is declared, AL create a specific object that is also a type object. Type have some properties and methods that are common for all variables types.

property

*.getType ()

Return the AL type of the data. For complete type reference see AL Types.

*.is (type)

Verifies that the data is of the type specified as the parameter. For complete type reference see AL Types.

*.isNull ()

Verify if variable is VOID (is equals to nil).

*.ifNull (value)

Verify if variable is VOID (is equals to nil). In this case the function return the value in parameter.

*.ifNotBreak (type)

Verify if variable is not of the type specified as the parameter. In this case the function return nil and break call chain. For complete type reference see AL Types.

*.ifNullBreak ()

Verify if variable is VOID (is equals to nil). In this case the function return nil and break call chain.

*.equals (b)

Test if boolean is equals to b.

*.toString ()

Return the data value as String. In case of complexe data type (like array, function and object), return the set of data of the type as String.

method

*.add (item [, index])

Index is optional.
If index is not setted, it create an array with value at first position and add item at its end.
Else, it create the array and add item at the index position on it.

*.addAll (array [, index])

Index is optional.
If index is not setted, create an array with value at first position and add items at the end of the array.
Else, it create the array and add items at the index position on it.

event

*.onChanged ( function(value){} )

An event raised every time a variable is modified in program.

void

When variable is declared and nothing is setted on it, AL create a VOID object. This object have some properties and methods. See Type object for type common methods and properties.

boolean

When an boolean is declared, AL create an object. This object have some properties and methods. See Type object for type common methods and properties.

property

boolean.not ()

Return the inverted boolean value.

boolean.and (b)

Return the boolean && b operation result.

boolean.or (b)

Return the boolean || b operation result.

boolean.xor (b)

Return the (boolean || !b) && (!boolean || b) operation result. In other words boolean != b.

boolean.ifTrue (function () {})

Execute the parameter function if boolean value is true.
It it the functional equivalent of If imperative statement.

boolean.ifFalse (function () {})

Execute the parameter function if boolean value is false.
It it the functional equivalent of Else imperative statement.

boolean.whileDo (function () {})

Execute the parameter function while function return true.
It it the functional equivalent of While imperative statement.

boolean.untilDo (function () {})

Execute the parameter function while function return true.
It it the functional equivalent of While imperative statement.

number

When an number is declared, AL create an object. This object have some properties and methods. See Type object for type common methods and properties.
Be carefull, parenthesis must be employed with this type because dot is used for decimal.
ex : (7).isNumber();

number.isInteger ()

Verify if variable type is NUMBER and integer.

number.isReal ()

Verify if variable type is NUMBER and real.

number.isNan ()

Verify if value is Not a number, e.g. if the result of the operation is invalid.

number.isInfinite ()

Verify if the value is infinite.

method

number.toInteger ()

Return the integer value of the number.

number.minus ()

Return the inverted number value, same as -n.

number.increment ([n])

Return the incremented number value, same as number + n. If n is not setted it is equal to 1.

number.decrement ()

Return the decremented number value, same as number + n. If n is not setted it is equal to 1.

number.addition (n)

Is the number + n operation equivalent.

number.substract (n)

Is the number - n operation equivalent.

number.multiply (n)

Is the number * n operation equivalent.

number.divide (n)

Is the number / n operation equivalent.

number.modulo (n)

Is the number % n operation equivalent.

number.limit (min, max)

Limit the value between minimum and maximum.

number.greaterThan (n)

Is number > n operation equivalent.

number.smallerThan (n)

Is number < n operation equivalent.

number.greaterOrEquals (n)

Is number >= n operation equivalent.

number.smallerOrEquals (n)

Is number <= n operation equivalent.

number.between (min, max)

Return true if number if between min and max. It is equivalent to number >= min && number <= max.

number.decodePoint ()

Return the character corresponding to codepoint codes.

number.loopFor (function (index) {} [, init, [, increment]])

Is the for (set index = init; index < number; index += increment) imperarive instruction equivalent. Execute the function from 0 (or optional init) to number by adding 1 (or optional increment) each time.

string

When a string is used, AL create a STRING object. This object have some properties and methods. See Type object for type common methods and properties.

property

string.isEmpty ()

Verify if string is empty ("").

string.length ()

Return the number of characters of the string.

string.getChar (index)

Return the character at the index position in the string.

method

string.contains (subString)

Return true if string contains the sub string

string.concat (string)

Concatenate string with the other one.

string.indexOf (subString, index)

Return the position of sub string in string.
Index is optional and indicate at what position it begin to search.

string.count (subString)

Return the number of sub string present in string.

string.upper ()

Return the upper representation of the string.

string.lower ()

Return the lower representation of the string.

string.append (substring [, index])

Return result of string concatening.
Index is optional and specify the position to insert in the string.
Equivalent of ".." operator.

string.appendSep (substring , separator)

Return result of string concatening and separator if string was not empty.

string.subString (begin [, end])

Get the substring between begin and end position in string.
End is optional, if setted indicate the position of the end of sub-string, else, the end is the end of the string.

string.subStringOf (begin [, end])

Get the substring between begin and end sub string in string.
End is optional.

string.replace (from, to)

Return string that sub string has been replaced by the second sub-string.

string.replaceAt (subString, index)

Return string that the sub string has been replaced at index position in the string.

string.remove (index [, length])

Return string that the char at position has been removed.
Length is optional, if setted, remove the number of char indicated.

string.split (separator)

Split the string according the specified separator and store results in an array.
Use "" separator to convert a string to an array of characters.

string.splitAt (array)

Split the string according the specified ids (contained in the array) and store results in an array.

string.trim ()

Return the string that unused spaces has been removed at the beginning and the end of the string.

string.create (subString, count)

Create a string by duplicating sub string from 0 to count time.

string.encodePoint ()

Create an array that contains String caracters as codepoint codes.

functional method

string.each (function (char [, index]) {} [, step])

Loop on all character of the string.
Executed function must define one parameter to retreive the current character of each loop iteration.
The second parameter index is optional and deliver the character index in the string.Step is optional, it represent the number of character to jump before next call.

array

When an array is declared, AL create an object. This object have some properties and methods. See Type object for type common methods and properties.

property

array.isEmpty ()

Verify if array is empty ({}).

array.length ()

Return the number of element of the array.

array.getItem (identity)

Get the array item at identity.
Identity should be the position of the item or it's key.

array.setItem (identity, item)

Set the value of the array item at identity.
Identity should be the position of the item or it's key.

array.getFirst ()

Get the first item of the array.

array.getLast ()

Get the last item of the array.

prototype

array.clone ()

Duplicate the array to another new one.
Every modifications of the clone does not affect the original object.

method

array.clear ()

Remove all items of array.

array.contains (item)

Test if the item is contained by the array.

array.containsAll (array)

Test if all the items of the subset are contained by the array.

array.containsAny (array)

Test if at least one of the items of the subset is contained by the array.

array.remove (identity)

Remove item from the array at identity position.
Identity should be the position of the item or it's key.

array.pop ([identity])

Identity is optional and should be the position of the item or it's key.
If identity is not setted, remove the last item from the array and return it.
If identity is setted, remove the item at positin and return it.
Use array.add() and array.pop() to have LiFo (Last in First out) stack behaviours.
Use array.add() and array.pop(0) to have FiFo (First in First out) queue behaviours.

array.indexOf (item)

Return the position of item in the array.

array.count (item)

Return the number of item with certain value present in string.

array.swap(identity1, identity2)

Swap the two items at positions identity1 and identity2.
Identity1 & 2 should be the positions of the items or their keys

array.decodePoint ()

Create a string from it's unicode codepoint representation.

functional method

array.find (function (item [, index [, key]] [, pos]) {})

Find item of the array for which function returns true.
Executed function must define one parameter to retreive the current item of each loop iteration.
The second parameter index is optional and deliver the item index in the array.
The thrid parameter is optional too and deliver the key of the item.
Pos is an optional parameter too that indicates the index to begin the search in the list.

array.create (count, function ([index]) {})

Create an array of n elements. Each element is calculated by function passed by parameter.

array.each (function (item [, index [, key]]) {})

Loop on all items of the array.
Executed function must define one parameter to retreive the current item of each loop iteration.
The second parameter index is optional and deliver the item index in the array.
The thrid parameter is optional too and deliver the key of the item.

array.eachOnRow (row, function (item [, index [, key]]) {})

In a two dimentional array (une table), loop on all items of the row of the array.
Executed function must define one parameter to retreive the current item of each loop iteration.
The second parameter index is optional and deliver the item index in the array.
The thrid parameter is optional too and deliver the key of the item.

array.eachOnCol (col, function (item [, index [, key]]) {})

In a two dimentional array (a table), loop on all items of the column of the array.
Executed function must define one parameter to retreive the current item of each loop iteration.
The second parameter index is optional and deliver the item index in the array.
The thrid parameter is optional too and deliver the key of the item.

array.eachItem (function (item [, index [, key]]) {})

In a multi-dimentional array (a tree), loop on all items of the array, if element is an array, it will loop on it's children recursivelly.
Executed function must define one parameter to retreive the current item of each loop iteration.
The second parameter index is optional and deliver the item index in the array.
The thrid parameter is optional too and deliver the key of the item.

array.filter (function (item [, index [, key]]) {})

Filter the array items on function value.
Function must return a boolean value.
If the value is true, the item is keeped, else it is removed.
Executed function must define one parameter to retreive the current item of each loop iteration.
The second parameter index is optional and deliver the item index in the array.
The thrid parameter is optional too and deliver the key of the item.

array.sort ([function (item1, item2){}])

Return an array that the items of the array has been sorted.
Function is optional.

array.min ([function (item1, item2){}])

Return the minimum value contained in the array.
Function is optional. See sort for more details.

array.max ([function (item1, item2){}])

Return the maximum value contained in the array.
Function is optional. See sort for more details;

array.join (function (item1, item2 [, index [, key]]){})

Join all the elements of the array together.
The function is needed to know how to join sequentialy elements.
It is usefull for concatenate an array to one string, or to adding all the number element of an array.

array.merge (array, function (item1, item2, index [, key]){})

Return result of the two arrays merging. Each element of the first array is merged with the corresponding element of the second array.
The function determin the merging behaviour by returning value of each merged element.
Note: if second array is shorter than first one, the elements will be repeated until merging is complete.

array.union (array)

Return the union of array and subset.

array.intersection (array)

Return the intersection of array and subset.

array.complement (array)

Return the complement of array and subset.

array.difference (array)

Return the difference of array and subset.

array.product (array)

Return the cartesian product of array and subset.

function

When a function is declared, AL create an object. This object have some properties and methods. See Type object for type common methods and properties.

property

function.parameterExists (name)

Verify that parameter exists on the function definition.

function.getParametersNames ()

Return an array that containing all the names of the parameters defined in the function.

function.setParameter (name, value))

Set the value to the parameter of the function that correspond to the name. If parameter does not exists, create it. Usefull to set parameters before execution (for function passing in another without parameters copying).

function.setParameters ({ values })

Set the values to the parameters of the function. be carefull, the parameters values must be express as array (with {}). Usefull to set all parameters before execution (for function passing in another without parameters copying).

method

function.removeParameter (name)

Remove function parameter dynamically from the function definition..

functional method

function.concat (function)

Return a new function that is the result of functions concatenation. Parameters are merged togather and treatments run along. Equivalent to -> operator.

function.decorate (function)

Return a new function resulte of the decoration of the function execution with a decorator one. The decored fonction execution is encapsulated into the decorator one. Needed for Aspect Oriented Programming paradigm.

object

When an object is declared, AL create a meta-object. This object have some properties and methods. See Type object for type common methods and properties.

prototype

object.clone ()

Duplicate the object to another new one.
Every modifications of the clone does not affect the original object.
It is a new operator equivalent.

property

object.attributeExists (name)

Verify that attribute exists on the object definition.

object.getAttributesNames ()

Return an array that containing all the names of the Attributes defined in the object.

object.isA ()

Verify that object is an instance or a sub-object of the parameter one.

object.setAttribute (name, value)

Set or add (if does not exists) Attribute dynamically to the object definition. Attribute can be an attribute, a method or a nested object.

method

object.toString = function () {}

Replace the default text when object is printed.

object.merge (object)

Return an object that is the result of two objects merging. The definitions are merged togather by addition of the attributes and methods.

object.removeAttribute (name)

Remove object attribute dynamically from the object definition. Attribute can be an attribute, a method or a nested object.

API root

print (text)

Print a line with text.

al

property

al.allObjects

Return all the Algoid API objects and methods that can be uses.

al.allLocalObjects

Return all the objects and methods that can be uses in current scope.

al.clock

Return the time is second from Algoid was started.

al.order

method

al.order.ascending (item1, item2)

Sort the order of the array with ascending maneer.

al.order.descending (item1, item2)

Sort the order of the array with descending maneer.

al.order.random (item1, item2)

random the order of the array.

al.order.reverse (item1, item2)

Reverse the order of the array.

al.combine

al.combine.sum (item1, item2)

Combine the elements of an array together by summing.

al.combine.product (item1, item2)

Combine the elements of an array together with a product.

al.combine.concat (item1, item2, index, key, separator)

Combine the elements of an array together by concatening them.

al.types

property

al.types.VOID

The AL VOID type. It is a null value.

al.types.BOOL

The AL BOOL type. It is a boolean value (true, false).

al.types.NUMBER

The AL NUMBER type. It is a numeric value (1, 2, 3.5, 7 ....).

al.types.STRING

The AL STRING type. It is a string value.

al.types.ARRAY

The AL ARRAY type. It is a array value.

al.types.FUNCTION

The AL FUNCTION type. It is a function.

al.types.OBJECT

The AL OBJECT type. It is an object.

util

method

util.eval (code)

Execute code in parameter in current scope.

util.wait (milli)

Wait the time indicated in milli-seconds.

util.pulse (function ([index]) {}, milli [, count[, after]])

Execute function each time number of milli-seconds is elapsed.
The called function received an optional parameter named index that specify the call number.
When function return a value, it terminate the event.
The optional parameter count define a number of time that pulse run before finish. When pulse is finnished, call the 'after' parameter function.

util.notice (function, milli)

Execute function after the amount of specified milli-seconds is elapsed.

util.pullOn (array, milli)

PullOn accept an array of functions. It execute them sequentially with a delay between them.

util.clearTasks (array, milli)

Clear all upcoming tasks and events but not the current one.

util.log (msg)

Log the message to the log file.

util.warn (msg)

Log the message to the log file as warning (orange).

util.err (msg)

Log the message to log file as error (red).

math

constant

math.E

The mathematical constant e.

math.PI

The mathematical constant PI.

method

math.abs (number)

Get the absolute value (positive) of a number.

math.acos (factor)

Calculate the arc cosinus of the segments factor.

math.aim (number, number)

Calculates the angle of algo to aim target from center coordonates (0, 0).

math.asin (factor)

Calculate the arc sinus of the segments factor.

math.atan (factor)

Calculate the arc tangent of the segments factor.

math.ceil (number)

Return the smallest natural value directly greater than the number : 10.9 = 11

math.cos (angle)

Calculate the cosinus of the angle in degree.

math.dbl (number)

Calculate the 2 power of the number.

math.diagonal (number, number)

Calculates the diagonal (hypotenuse) of the rectangle.

math.exp (number)

Calculate the exponential of the number.

math.floor (number)

Return the natural part of the number : 10.9 = 10

math.log (number[, base])

Return the natural(e) log of the number. If base is setted, return the logarithm of the number to the given base.

math.max (number, number)

Returns the greater of the two numbers.

math.min (number, number)

Returns the smaller of the two numbers.

math.pow (number, power)

Calculate the n power of the number.

math.random (factor)

Generate a random number between 0 and factor excluded

math.round (number)

Round the reel number to natural one : 10.9 = 11

math.sin (angle)

Calculate the sinus of the angle in degree.

math.sqrt (number)

Calculate the squared root of the number.

math.tan (angle)

Calculate the tangent of the angle in degree.

ui

ui.message (msg)

Display a message box popup in application.

ui.fullScreen ()

Show execution window in full screen mode.

ui.halfScreen ()

Show execution window in half screen mode.

ui.miniScreen ()

Hide execution window and show source code.

ui.showText ()

Flip to text window, text allow exchange input and output messages with user.

ui.showAlgo ()

Flip to algo window.

ui.showScope ()

Flip to scope debugger window.

ui.showLog ()

Flip to log file window.

ui.clearLog ()

Clear the application log file.

ui.showMenu ()

(android only !) Show the slidding menu on the right of algo screen.

ui.hideMenu ()

(android only !) Hide the slidding menu on the right of algo screen.

text

text.clear ()

Clear the text window of all content (inputs and outputs).

text.output (msg)

Print a new line in text window.

text.inputText (msg)

Print a new line in text window with text box control to ask user.
Return a string.

text.inputNumber (msg)

Print a new line in text window with number box control to ask user.
Return a number.

algo.color

constant

algo.color.TRANSP

Represent the transparent color constant (-1). See colors table.

algo.color.BLACK

Represent the black color constant (0). See colors table.

algo.color.DARK_BLUE

Represent the dark blue color constant (1). See colors table.

algo.color.DARK_GREEN

Represent the dark green color constant (2). See colors table.

algo.color.DARK_CYAN

Represent the dark cyann color constant(3). See colors table.

algo.color.DARK_RED

Represent the dark red color constant (4). See colors table.

algo.color.DARK_MAGENTA

Represent the dark magenta color constant (5). See colors table.

algo.color.BROWN

Represent the brown color constant (6). See colors table.

algo.color.GRAY

Represent the gray color constant (7). See colors table.

algo.color.DARK_GRAY

Represent the dark gray color constant (8). See colors table.

algo.color.BLUE

Represent the blue constant (9). See colors table.

algo.color.GREEN

Represent the green color constant (10). See colors table.

algo.color.CYAN

Represent the cyann color constant(11). See colors table.

algo.color.RED

Represent the red color constant (12). See colors table.

algo.color.MAGENTA

Represent the magenta color constant (13). See colors table.

algo.color.YELLOW

Represent the yellow color constant (14). See colors table.

algo.color.WHITE

Represent the white color constant (15). See colors table.

algo

property

algo.setColor (color)

Set the foreground color of Algo's futur shapes and paths.

color value color value
transp.-1   
black0 dark gray8
dark blue1 blue9
dark green2 green10
dark cyan3 cyan11
dark red4 red12
dark magenta5 magenta13
brown6 yellow14
light gray7 white15

algo.setRGB (red, green, blue)

Set the foreground RGB color of Algo's futur shapes and paths.

algo.setBgColor (color)

Set the current background color of Algo.

algo.setBgRGB (red, green, blue)

Set the background RGB color of Algo's futur shapes and paths.

algo.setAlpha (color)

Set the current transparency of color of futur shapes. Value must be between 0 and 1.

algo.setTextSize (size)

Set the text size of Algo's futur text.

algo.setStroke (size)

Set the stroke size of Algo's futur shapes and paths.

algo.setStack ()

Set the number of simultaneous visible elements in Algo.

algo.getX ()

Get the X coordonate of Algo.

algo.getY ()

Get the Y coordonate of Algo.

algo.getAngle ()

Get the angle of Algo.

algo.getTop ()

Get the top coordonate of Algo window (lower than 0).

algo.getBottom ()

Get the bottom coordonate of Algo window (greater than 0).

algo.getLeft ()

Get the left coordonate of Algo window (lower than 0).

algo.getRight ()

Get the right coordonate of Algo window (greater than 0).

algo.getWidth ()

Get the width of Algo window.

algo.getHeight ()

Get the Height of Algo window.

method

algo.show ()

Show the Turtle.

algo.hide ()

Hide the Turtle.

algo.clear ()

Delete all the visible elements in Algo.

algo.autoClear ()

Delete all the visible elements in Algo without flicking. Useful for animation and game developpement. Put it at the beginning or the render loop.

algo.removeFirst ()

Delete the first drawn element in Algo.

algo.removeLast ()

Delete the last drawn element in Algo.

algo.goTo (x, y)

Move algo's Turtle to the absolute x, y position in the grid.

algo.lineTo (x, y)

Draw line from actual position to x, y one.

algo.go (len)

Move Algo's Turtle go forward and draw line.

algo.jump (len)

Move foreward algo's Turtle without drawing anything.

algo.turnRight (angle)

Turn right the Algo's Turtle to relative angle.

algo.turnLeft (angle)

Turn left the Algo's Turtle to relative angle.

algo.rotateTo (angle)

Rotate Algo's Turtle to absolute angle.

algo.circle (diameter)

Draw circle at current position.

algo.disc (diameter)

Draw filled circle at current position.

algo.square (size)

Draw square at current position.

algo.box (size)

Draw filled square at current position.

algo.rect (width, height)

Draw rectangle at current position.

algo.plane (width, height)

Draw filled rectangle at current position.

algo.oval (width, height)

Draw oval at current position.

algo.platter (width, height)

Draw filled oval at current position.

algo.path (array[, closed = true])

Draw a path. Closed parameter is optional and determine if path is closed, it's default value is true. Be carefull, need an array of x, y pairs as input. First point of the path is always the current position.

algo.poly (array[, closed = true])

Draw a polygone. Closed parameter is optional and determine if path is closed, it's default value is true. Be carefull, need an array of x, y pairs as input. First point of the path is always the current position.

algo.curve (array[, closed = true])

Draw a curved path. Closed parameter is optional and determine if path is closed, it's default value is true. Be carefull, need an array of x, y pairs as input. First point of the path is always the current position.

algo.curvedPoly (array[, closed = true])

Draw a polygone. Closed parameter is optional and determine if path is closed, it's default value is true. Be carefull, need an array of x, y pairs as input. First point of the path is always the current position.

algo.text (text)

Draw text at current position.

event

algo.onClick (function (x, y))

(desktop only !) Execute defined function when user click with mouse on algo.
When function return a value, it terminate the event.

algo.onRelease (function (x, y))

(desktop only !) Execute defined function when user has finished to click with the mouse.
When function return a value, it terminate the event.

algo.onMove (function (x, y))

(desktop only !) Execute defined function when user move the mouse on algo.
When function return a value, it terminate the event.

algo.onDrag (function (x, y))

(desktop only !) Execute defined function when user click and move (drag) the mouse on algo.
When function return a value, it terminate the event.

algo.onWheel (function (rotation))

(desktop only !) Execute defined function when user use the mouse wheel over algo.
Returned values are 1 for down and -1 for up.
When function return a value, it terminate the event.

algo.onKey (function (key))

(desktop only !) Execute defined function when user hit a keyboard key.
When function return a value, it terminate the event.

algo.onTap (function (x, y))

Execute defined function when user Tap with his finger on algo.
When function return a value, it terminate the event.

algo.onTouch (function (x, y))

Execute defined function when user Move his finger on algo.
When function return a value, it terminate the event.

algo.onUp (function (x, y))

Execute defined function when user has finished to Tap with his finger.
When function return a value, it terminate the event.

algo.onGravity (function (x, y, z))

(android only !) Execute defined function when user turn the device. x, y and z are 3d axis of gravity force and their unit is m/s.
When function return a value, it terminate the event.

algo.onAcceleration (function (x, y, z))

(android only !) Execute defined function when user move the device. x, y and z are 3d axis of acceleration force and their unit is m/s.
When function return a value, it terminate the event.

algo.onGyroscope (function (x, y, z))

(android only !) Execute defined function when user turn the device. x, y and z are 3d axis of rotation force and their unit is degree/s.
When function return a value, it terminate the event.

algo.onOrientation (function (z, x, y))

(android only !) Execute defined function when user turn the device compared with geomagnetic field. z, y and x are Azimuth, Pitch and Roll and their unit is in degree.
When function return a value, it terminate the event.

algo.onProximity (function (dist))

(android only !) Execute defined function when user become near or fare the device. Distance is in cm.
When function return a value, it terminate the event.

algo.onTemperature (function (t))

(android only !) Execute defined function when ambient temperature is changing. t is in °C.
When function return a value, it terminate the event.

algo.onLight (function (l))

(android only !) Execute defined function when ambient light is changing. l is in lx.
When function return a value, it terminate the event.

algo.stamp

Stamp is a graphical bitmap that can be drawed in algo.

property

algo.stamp.id

The internal algo's stamp identifier.

algo.stamp.width

The stamp width.

algo.stamp.height

The stamp height.

prototype

algo.stamp.clone (colors, size)

Create a new stamp with bitmap information and size.

algo.stamp.load (filename)

(desktop only !) Create a new stamp with bitmap image.

Filename must be an existing file. It can be an absolute path or a relative to several default path ([project root]/img or [application root]/img or [user root]/img)

 
example: 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
set stamp = algo.stamp.load("PlanetCute/Character Princess Girl");

algo.onTouch((x, y) {
  algo.autoClear();
  algo.goTo(x, y);
  stamp.draw();
});
algo.hide();

method

algo.stamp.delete ()

Remove the stamp from algo.

algo.stamp.draw ()

Duplicate and draw the stamp in algo.

Algoid Language Backus-Nauf form

// expressions and level of operations
assign ::= var ident ( "=" | "+=" | "-=" | "*=" | "/=" | "%=" | "..=" | "->=" ) expr [ ";" ]
expr ::= concat | assign
concat ::= or [ ( ".." | "->" ) or ]
or ::= and [ "||" and ]
and ::= compar [ "&&" compar ]
compar ::= oper [ "==" | "!=" | "<" | "<=" | ">" | ">=" oper ]
oper ::= mult [ "+" | "-" mult ]
mult ::= unary [ "*" | "/" | "%" unary ]
unary ::= ( ["-" | "!" | new ] ident) | ( ident [ "++" | "--" ] )

// identifiers
ident ::= call [ "." call ]
call ::= index "(" [ expr [ { "," expr } ] ] ")"
index ::= value [ { "[" expr "]" } ]

// values
boolean ::= true | false
number ::= nan | infinity | ("0"-"9") [ { ("0"-"9") } ]
string ::= """ [ { .. ASCII character .. } ] """
value ::= "(" expr ")" | object | lambda | function | array | if | this | supers | ident | nil | boolean | number | string

// structures
assign ::= set ident "=" expr [ ";" ]
lambda ::= [ "(" [ ident ] [ { "," ident } ] ")" ] "{" body "}"
function ::= function "(" [ ident ] [ { "," ident } ] ")" "{" body "}"
return ::= return expr [ ";" ]
array ::= array<1*> [ "(" ")" ] "{" [ item [ { "," item } ] ] "}"
item ::= [ expr ":" ] expr
object ::= object "(" [ ident [ "," ident ] ] ")" "{" [ { assign } ] "}"

// imperatives
if ::= if "(" expr ")" body [ { elseif "(" expr ")" body } ] [ else body ]
loop ::= loop "(" [ expr ] ")" body
for ::= for "(" [ assign ] ";" [ expr ] ";" [ expr] ")" body
while ::= while "(" expr ")" body
until ::= do body until "(" expr ")"
break ::= break [ ";" ]

// others
comment ::= ( "//" .. ASCII character .. .. end of line .. ) | ( "/*" .. ASCII character .. "*/")
body ::= instruction | "{" [ { instruction } ] "}"
instruction ::= comment | return | loop | for | while | until | break | expr [ ";" ] | ";" | body

learn programming made simple and funny !
Algoid
EN | FR