#header-inner {background-position: right !important; width: 100% !important;}

10/29/15

'Ola AH' Programming Language Syntax.

(under construction, probably will change).

Introduction.

'Ola AH' Programming Language is targeted to Quantum Computer Architectures with the multi-core support of Advanced RISC Machines - it's designed for ARM / Quantum Architectures.

it's syntax will probably evolve as related technology advances.


Description.

what are Design Goals, what kind of language 'Ola AH' should be?
how 'Ola AH' Programming Language's Syntax should be described ?

in my opinion syntax & language's semantic should be:
* beautiful,
* elegant,
* modest,
* strict,
* mindful,
* spiritual,
* mathematical,
* philosophical,
* terse (means: a short form, but inner complexity is strictly & precisely defined; in a polish language it's translated as 'zwięzły'),
* sexy,
* short,
* nice,
* gentle, easy to read, understand & learn,
* agile,
* insightful,
* precise,
* artful,
* both esoteric & practical,
* optionally visuospatial,
* secure,
* sane,
* scientific,
* classical yet very modern,
* formal yet still casual,
* esoteric, pragmatic & practical,
* simple yet skillful, expressive & powerful,
* professional.


Data Types.

constants,

enumerations (enum),

int8 - signed 8-bit integer,
int16 - signed 16-bit integer,
int32 - signed 32-bit integer,
int64 - signed 64-bit integer,
int128 - signed 128-bit integer,
int256 - signed 256-bit integer,

bigint - signed big integer, a data structure of variable length (can be resized to hold bigger numbers).

boolean - logical boolean type, with a { true, false } values,

char - a single character, 16 bit UTF,

string - character string object data type with a proper convenience methods,

float32 - 32-bit floating point number,
float64 - 64-bit floating point number,
float128 - 128-bit floating point number,
float256 - 256-bit floating point number,

bigfloat - big floating point number, a data structure of variable length (can be resized to hold bigger, more precise numbers).


decimal32 - 32-bit floating point numbers written in a form: m * 10e, where:
  m is BCD-encoded mantissa;
  e is called exponent (BCD-noted as well).
decimal64 - 64-bit floating point numbers written in a form: m * 10e, where:
  m is BCD-encoded mantissa
  e is called exponent (BCD-noted as well).
decimal128 - 128-bit floating point numbers written in a form: m * 10e, where:
  m is BCD-encoded mantissa
  e is called exponent (BCD-noted as well).
decimal256 - 256-bit floating point numbers written in a form: m * 10e, where:
  m is BCD-encoded mantissa
  e is called exponent (BCD-noted as well).

bigdecimal - a big floating point number, a data structure that uses BCD-notation & is of a variable length (both mantissa as well as exponent are BCD-noted & can be resized to hold bigger numbers, respectively increasing the possible number magnitude range as well as the number's precision).

for details about BCD notation (encoding), about mantissa & exponent notations, feel free to look at an article: Binary-Decimal-Hexadecimal Conversions.


fractional - a potentially big & precise number represented in a Base-k arbitrary precision arithmetics with PreciseNumbers. This allows for simple basic arithmetic operations without a precision loss, at a cost of memory use & calculation speed. i think it'll have great uses in science & banking - will simplify programmers' & other scientists' life a lot.


Variables.

'variable' object type that abstracts over a primitive & object. with 'inspect' operation to discover contained data type, with a typesafe cast. probably a shorter instruction mnemonic of 'var' will be used.

example #1:

var v1 := 108;
if (inspect v1 = int8) { ... };

example #2:

var v2 := new MyClass1();
if (inspect v2 = MyClass1) { ... };

example #3:

var v3 := new MyClass2();
if (inspect v2 instanceof MyClass2) { ... };

example #4:

var v4 := 108;
int8 i1 := (int8) v4;

example #5:

var v5 := new MyClass3();
MyClass3 o1 := (MyClass3) v5;


static variables & constants (with java's semantics of the 'static' keyword),


Collections (with a proper syntax support):

collection can be 'flat' (tuples, arrays, lists or sets) or 'not flat' (maps).

collections will feature built-in sorting (with a default or user-implemented comparison method).

collections will feature built-in conversions to other collection type, using source collection's 'comparison method' as well.

collections will feature built-in transformation (with user-implemented 'transformer' method.

also there will be abstract 'predicate' method, a subtype of 'transformer' which will transform any input state to a boolean value; this has uses in the 'predicate logic' & artificial intelligence as well; there also will be 'constant predicates' : 'TruePredicate', 'FalsePredicate' - that transform 0-argument input state into a boolean value; there also will be strictly 'boolean predicates', as for example: 'NotPredicate', 'OrPredicate', 'AndPredicate', 'IffPredicate', 'NandPredicate', ... - that operate on a collection of the predicates & transform them into a boolean value. for a list of logical operators, see: 'Logical Operators' article; a part of 'boolean predicates' will use collections with a set size of 1 or 2, other 'boolean predicates' will accept collections of any size.

there will be default 'default variable comparator' as well, that can compare types & state differencies for two 'variables' of the same type.

shorter keyword will be used for a 'default variable comparator': 'dvcomparator'.


there will be predicate calculus constructs:
- predicates,
- terms,
- formulas,
- models,
- entailment operators,
- inference operators.


... this has uses in logic & in the artificial intelligence fields.


Arrays.

array of a given type, with a support on the syntax level:

  for example:

    int32 iarr[] = ${ 1, 2 };
    char carrarr[][] = ${ ${ 'a', 'b' }, ${ 'z' } };
    ...
    object oarr[] = ${ o1, o2 };
    ...

operations available on arrays:
- standard array get & set (for example: char ca[] = ${ 'a', 'b' }; ca[1] := 'a'; var v = ca[0];),
- length,
- inspectvals,
- amountin,
- contains (element),
- containsall ('flat' collection),
- clear // clears array, setting 'null' or '0' values ...,
- sort (comparator) // sorts elements using a passed comparator.


Tuples.

tuple aggregate ( for example: (1, 2), (1, (2,3)), ... ),

tuple differs from array in that, that tuple uses type-safety for each of it's values,

  for example:

    (int8, int8, int8)
    (object, object)
    (object, int8, float64)

tuples can be both l-values (assignable variables), as well as r-values (non-assignable expression values).


process of assignment (a,b) := (b,a); proceeds as follows:

r-value of (b,a) is copied to temporary memory, then assigned value-by-value to a l-value tuple (a,b);

in the end a variable of 'a' contains an initial value of 'b', a variable of 'b' contains an initial value of 'a';


process of assignment (a,b) := (func1(a), a); proceeds as follows:

r-value of (func1(a),a) is calculated to a value tuple (as opposed to expressions tuple), then values are copied to a temporary memory. next we assign value-by-value to a
l-value tuple (a,b);

in the end a variable of 'a' contains calculated value of a 'func1(a)' expression, a variable of 'b' contains an initial value of 'a';


assigning values from a tuple proceeds as follows:

example #1:

(char, char, char) t1 := ('a','b','c');
char a,b,c;
(a,b,c) := t1;

example #2:

(char, char, char) t2 := ('d','e','f');
char d,f;
(d,_,f) := t2;


in an example #2, the underscore: _, allows for omitting a variable during the variables assignment process.


it seems there's a conflict between tuples & conditional instruction 'if' on the syntax level.

this will be solved by evaluating a tuple to a value - first value in a tuple is r-value of a tuple.

therefore we can write:

if ( (true, 1, 3) and ( booleanVal1 or booleanVal2) ) { ... };

this will evaluate to:

if ( true and ( booleanVal1 or booleanVal2) ) { ... };

then to:

if ( booleanVal1 or booleanVal2 ) { ... };


tuple should be 'inspectable' both for it's type, the type of n-th value, as well as for the amount of values in it.

example #1:

(char, char, char) t1 := ('a', 'b', 'c');
if ( (inspect t1 = tuple) and (amountin t1 = 3) ) { ... };

example #2:

(char, int8, char) t2 := ('a', 108, 'b');
if ( (inspect t2 = tuple) and (amountin t2 = 3) and (inspectval 0 of t2 = char) { ... };


Maps.

hash maps with keys of a string type & values of a given type, with a support on the syntax level.

tree maps for more efficient search in larger data size, at greater memory storage cost.

shorter keywords will be used: 'map', 'tmap'.

default hash maps with key values of 'string' type will have following notation:

for example:

  object map om1 := %{};
  object map om2 := %{ "akey" : o1, "bkey" : o2 };
  char map cm1 := %{};
  char map cm2 := %{ "akey" : 'a', "bkey" : 'b' };
  var map vm1 := %{ "akey" : 'a', "bkey" : 'b' };
  ...

hash maps with different key values than 'string' will have following notation:

(it's also possible to write default hash maps with a 'string' key type that way).

for example:

  (object, object) map oom1 := %{};
  (object, object) map oom2 := %{ so1 : to1, so2 : to2 };
  (char, char) map ccm1 := %{ 'z' : 'a', 'b' : 'c' };
  (string, char) map scm1 := %{ "akey" : 'a', "bkey" : 'b' };
  (string, char) map scm2 := %{ "zkey" : 'z', "ukey" : 'u' };

tree maps will have following notation:

for example:

  (string, object) tmap sotm1 := %{};
  (string, object) tmap sotm2 := %{ "akey" : o1, "bkey" : o2 };
  (string, char) tmap sctm1 := %{ "akey" : 'a', "bkey" : 'c' };

internally maps will be not be stored as (key, value) tuples, because of type safety.

other operations available on maps:
- clear // clears map of any (key, value) tuples,
- inspectkeys,
- inspectvals,
- amountin // returns legth of keys list,
- insert (key, value) // inserts a (key, value) tuple into a map,
- remove (key) // returns removed (key, value) tuple,
- insertall (map) // inserts all of (key, value) tuples in a passed map,
- removeall (map) // returns map of removed (key, value) tuples,
- sortkeys (comparator) // sorts keys using a passed comparator, can't be null but can be default comparator.
- keys // returns sorted list of keys,
- getcmp // returns comparator used to sort keys.

maps will resize automatically, throwing error if not possible.

by default, construct: %{ ... } is represented as a variable hash map, that is converted to a proper type during a succesful assignment.


Lists.

either linked lists or array lists (tuples are not array lists in 'Ola AH' Programming Language, because of type safety).

shorter keywords will be used: 'list', 'alist'.

for example:

  char list cl := #{ 'a', 'b', 'c' };
  string list sl := #{ "str1", "str2" };
  object alist oal := #{ o1, o2, o3, o4 };

lists will be inspectable for contained data type as well as for amount of elements contained.

for example:

  char list cl := #{ 'a', 'b', 'c');
  if ( ( inspect cl = char ) and ( amountin cl = 3 ) { ... };

other operations available on lists:
- clear,
- amountin,
- inspectvals,
- insert (position, element),
- get (position),
- contains (element),
- remove (position),
- remove (element),
- insertall (position, 'flat' collection),
- getall (startposition, endposition),
- removeall ('flat' collection),
- removeall (startposition, endposition),
- containsall ('flat' collection),
- sort (comparator), // null value means unsorted.
- getcmp.

lists will resize automatically, throwing error if not possible.

by default, construct: #{ ... } is represented as a variable linked list, that is converted to a proper type during a succesful assignment.


Sets.

sets are unsorted, may contain a maximum of one element of a given (type, value) pair. for this case, subtypes are different than supertypes.

by default, 'Ola AH' Programming Language will use hash sets.

a keyword that will be used is: 'set'.

for example:

  char set cs1 := @{}; // initial memory asignment.
  char set cs2 := @{ 'a', 'b', 'c' }; // initial memory assignment & initialization.
  string set ss := @{ "str1", "str2" }; // initial memory assignment & initialization.

sets will be inspectable for contained data type as well as for amount of elements contained.

for example:

  char set cs := @{ 'a', 'b', 'c' };
  if ( ( inspect cs = char ) and ( amountin cs = 3 ) { ... };

other operations available on sets:
- clear,
- inspectvals,
- amountin,
- insert (element),
- remove (element),
- contains (element),
- insertall ('flat' collection) // if collection is a set, it acts as 'union' or 'add',
- removeall ('flat' collection) // if collection is a set, it acts as 'set subtraction',
- intersect ('flat' collection).

three last operations ('insertall', 'removeall' & 'intersect') will not produce a result set of more abstract type, since these operations will affect the source set's state. this might result in an exception being thrown instead.

for example:

  char set cs := new char set @{}; // initial memory asignment.
  cs insert 'z';
  cs insert 'y';
  cs insert 'x';
  char c1 := cs remove; // removes any element, then returns it or null if failed to remove.
  char c2 := cs remove 'y'; // removes element 'y', then returns it or null if failed
                                       // to remove (when set didn't contain 'y').
  cs insertall @{ 'l', 'm' }; // inserts two elements to cs.
  char set cs3 := cs removeall @{ 'x', 'm' }; // removes two elements: 'x' and 'm',
                                                               // then returns @{ 'x', 'm' } or null when failed
                                                               // to remove both (it's atomic operation).
  cs clear; // removes all of remaining elements from cs.

by default, construct: @{ ... } is represented as a variable set, that is converted to a proper type during a succesful assignment.

sets will resize automatically, throwing error if not possible.

sets are not sorted.


Interfaces, Classes, Objects

in 'Ola AH' Programming Language objects will be represented internally as a
(state, strategy) tuple or a LightPoint but this will be hidden behind a simplified syntax.

there will be a way to extract state or strategy from an object on the syntax level; extracted state won't contain data required to choose method called inside a strategy.

... rest as in standard object oriented programming, similar to Java's syntax.

example #1:

public class MyClass {
  var a;
  public var getA() { return a; };
  public void setA(var a) { this.a = a; };
};

object o = new MyClass();
var v = o.getA();
state stt = o.getState();
strategy str = o.getStrategy();

(blog's author's note to self: for java interpreter's concurrency use Lock, use thread names with method to call as well so there's no collision when multiple threads use the same object).


Other Collections.

there will be a standard library with other collections, as neccessary.

for example: trees (trees can also be constructed using lists of lists or tuples of tuples or maps of maps, with differing leaf nodes. abstract data type (root or leaf node) might prove useful here as well.


Machine.

stitie machine, with state, with strategy, with router,

machines' state setting using either a single-setter way, or using an elegant hash map syntax,

  for example:

    m clear; // clears state, removing all of the key-value pairs.
    m put ("akey", "aval"); // adds a key-value pair to the state.
    m putmap %{ "akey" : 'a', "bkey" : 'b' }; // adds a key-value pairs to state;
                                                                                // using default hash map
                                                                                // with a 'String' key
                                                                                // is mandatory, but it's 'char' type
                                                                                // of value is not mandatory.
    m putmap myDefaultHashMap; // adds a key-value pairs to state.
    m set ("akey", "aval"); // overwrites state of a select key/value pair.
    m setmap %{ "akey" : 'a', "bkey" : 'b' }; // overwrites state with a
                                                                                // key/value pairs found in a
                                                                                // default hash map;
                                                                                // using default hash map
                                                                                // with a 'String' key
                                                                                // is mandatory, but it's 'char' type
                                                                                // of value is not mandatory.
    m setmap myDefaultHashMap; // overwrites state with a default hash map.


Space.

stitie space, with methods as a certain form invocation, mindful imaging, ...

stitie machine & stitie space are data structures.

stitie space is a three dimensional objects array (3D Object Matrix),

stitie space uses stitie machine, is a tool for modelling & transforming graphs in three dimensional space (stitie space).

stitie space has convenience methods that allow for 'Agile Transformation of Information State' in space.

stitie space & stitie machine are introduced & described mostly in two posts:
* Stitie Machine (Maszyna Stanikowa Wysockiego),
* Stitie Machine 1.1 'Sunsail'.

probably more,

...


Instructions.

any of the instructions can be dynamically created as well, will be properly typed objects that can be 'passed around' - even 'asm' instruction, after that functionality is added to interpreter or compiler, respectively.


comments,

imports,

modes (including 'AH' mode, 'machine-less' mode, 'machine-less AH' mode, ...),

assert keyword,

basic arithmetic, expression operators: +, -, *, /, pow, ceil, floor, sqr, div, modulo, =, eq, ...
logic arithmetic, expression operators: not ( ! ), and ( && ), or ( || ), xor, imp, irev, iff,
 nand,
bitwise logic,expression operators, not ( neg ), and ( & ), or ( | ), xor ( ^ ), imp ( => ),
  irev ( <= ), bitwise iff ( biff ), bitwise nand ( bnand ), shl ( << ), shr ( >> ),

assignment instruction LET ( := ),

complex instruction { ... },

empty instruction { },

conditional instruction if,

iterations & loops: while ... end, do ... while, for,

break & continue,

standarized but optional, class & method invariants & contracts
 ( assert invariant name boolean_expression , or something similar),

standarized but optional, unit tests & integration tests, based on invariants & contracts ... using invariant names & perhaps more (for example a function call can be tested by providing a mock object with assert invariant name boolean_expression in it, or something similar),

methods,

in 'Ola AH' Programming Language methods will be properly typed objects that can be 'passed around', most probably with a proper syntax support.

method objects can be statically or dynamically constructed as well, with an elegant syntax support.

static methods,

inner visibility constructs,

recursion,

class definition instructions, constructors, methods, with private, package-private, protected & public visibility (had not better idea here than a Java-Way),

class destructor methods,

automatic memory allocation for built-in primitive data types,

'new' operator for object memory allocation & object construction,

exceptions (try ... catch),

'sizeof' instruction,

'inspect' instruction,

'instanceof' instruction,

low level / asm instructions,

threads & concurrency mechanisms,

perhaps class templates, simpler form than Java Generics - in future versions,

reflection mechanisms,

'transform' instruction (takes as parameters a 'variable' & transformation function that returns 'variable' depending on a 'variable' passed to it ... then returns transformed 'variable').

example: var v1 := o1 transform ft1;

'compare' instruction (takes as parameters two 'variables' in a tuple & a comparison function that returns a value (-1, 0 or 1) depending on 'variables' passed to it ... then returns a comparison value - a primitive: -1, 0 or 1),

perhaps shorter mnemonic ('cmp') will be used,

example: int8 p1 := (108, o1) cmp fc1;

both 'compare' as well as 'transform' instructions can throw an error when appropriate.

most probably lambda calculus constructs for functional programming in future versions as well (with reflection mechanisms' use, most likely),

probably there won't be any of 'garbage collection' mechanism(s), so recources release has to be done manually using 'release' instruction - because of low level / asm instructions in 'Ola AH' Programming Language,

lazy evaluation,

... perhaps more as well,

...


see also, if You wish or need, ... : 'Ola AH' Programming Language, 'Ola AH' Programming Language's Interpreter in Java.

No comments:

Post a Comment