Lang - yet another programming language

As far as possible the language is designed to resemble C and C++, so comments are similar and statements end with a ";".

functions and classes can be defined using Generics with a concise syntax. It's simple to write Generic functions and to call the functions on your own types.

Here is an example:

// zip 2 sequences using function F
zip fun(
   lhs_seq :FixedSequence Lhs,
   rhs_seq :FixedSequence Rhs,
   f       :(fun(_1,_2))
   L = length(Lhs);
   samelen = L == length(Rhs);
where( samelen )
   result :...[L] = ? ;
   for i in [ 0 .. ( L - 1) ]{
      result[i] ?= f(lhs_seq[i],rhs_seq[i]);
   return result;
default = error("sequences must be same length");

The symbol "zip" is of type function taking 3 object arguments being named lhs_seq, rhs_seq and f

The arguments each have constraints.

The first and second arguments must be models of the FixedSequence Archetype. The type of the first and second arguments have been given the alias Lhs and Rhs, which is optional, but means that type-computations can refer to these names to get at the actual types. Though both models of FixedSequence the actual types of lhs_seq and rhs_seq may be different yet valid.

By default function arguments cannot be modified and are passed by reference.

The third argument named f is an object of type function taking two arguments. In this case no further constraints on argument or return types have been specified, though they could be if desired.

After the formal function prototype is an optional "scratch-block", a local context to create static symbols that can be used later in the function body, rather than having to perform the computations again and again when needed. Here, two symbolic constants, L and samelen are defined in the scratch-block. Their types are deduced. L of type static integer and samelen of type static boolean.

After the scratch block comes a where clause (which is optional). There can be any number of where clauses and function bodies. This saves having to write many similar function prototypes for generic functions. Where clauses can optionally be terminated with a catch-all default clause as here, which applies to all where conditions not fulfilled in previous where clauses . In this case its used to catch an error

Within the body of the function the most interesting symbol is "result". It is defined as a tuple of Length L.( The length is optional in fact). The "=?" initialisation signifies that the actual type of the tuple is not yet defined. Its dependent on the application of f, which may invoke different actual function-sigs dependent on the arguments. The types of the elements of result are computed in the following for-loop. The special initialisation symbol "?=" is used to signfify this tuple building initialisation. Until result is defined the only actions that can be performed on it are those to define it!

There is no return type of the zip function given. Its only known when the type of result is computed, then deduced. Each where clause may return a different type.

I hope this gives a flavour of the language.

Here is the current Grammar.