Saturday, August 29, 2015

Wombat changes

Here are some changes to Wombat:

  1. The type that was Void is now Unit. Its only value, that was empty, is now unit. This is cutting a link to Algol68 usage, but the new naming is a modern standard.
  2. I plan to allow operators to have prefix and left-parameter forms. This will allow the "-" in 5-3 to be different from the "-" in -3. What happens to the right can then be different for each. So prefix "-" can have a higher right priority to infix "-". This will also allow the Python3 "if" style. It will allow the whole APL/J monadic/dyadic suite for those that like that sort of thing. [Previously Wombat could handle -3 because it became unit-3 which could be handled differently via polymorphism.]
  3. The type Muteable X [which used to be Var X before that] becomes Assignable X, following the lead of Robert Harper.
  4. Wombat will make more use of 1-tuples. The 0-tuple type is exactly Unit. The comma operator generates n-tuples for n>1. There is no syntax for 1-tuples, just procedures to go to and fro. Previously I vaguely thought that X and Tuple[X] were the same, which caused various problems. Now all is sweetness and light, and I can, for example say that Option X is just Union[Unit,Tuple[X]], and even if X=Unit, that still works because unit!=to1tuple(unit).
  5. In addition to operators for tight and loose breaks, add breaks representing line breaks with various sorts of indentation change.
[update 2016-09-28: point 4 is rubbish.]

Super Simple Syntax

Super Simple Syntax

Wombat likes to take minimalism to extremes. The only built in types are procedure types and tuples (Which includes Unit, the 0-tuple). There is no builtin syntax. All syntax is defined with the syntax creation scheme called Super Simple Syntax (SSS) which is available to library writers and even end-users. If the programmer doesn’t like the syntax she can make big or small changes, without affecting interoperability with other modules.
Some programming languages have user defined operators with just one precedence number that is the same on both sides. This means that you also have to specify left or right associativity. In Wombat the left and right can have different precedence. The operator associates to the left if the right precedence is higher.
Wombat allows operators with no left operand, or no right operand, or both. Indeed an identifier is just an operator, with no left or right, from a syntactic viewpoint. Operators can have following sub-operators, such as then and else for the if operator. Sub-operators can repeat or be optional, and can have a nested structure. There can be repeating groups, such as elif-then pairs in an if operator.
Operators can have a left parameter in which case they have a left priority. They can have a right parameter in which case they have a right priority. Technically the right priority belongs to trailing sub-operators such as else, but this is commonly the operator itself when it doesn’t have other sub-operators. (The operator counts as a sub-operator of itself.)
An operator can have a sub-operator (not itself) which is also in use as an operator. It only takes its sub-operator meaning where it is expected.
Priorities form a partial order. If priorities are not comparable then they can’t do battle for an expression between them. This stops different libraries from getting in each other’s way. The partial order includes as a subset the positive decimal numbers with a finite number of digits (Dewey decimal style), which the ordinary programmer might prefer to use. Additional priorities are defined by names together with enough comparisons between each other and (if desired) the numerical priorities. The partial order is the resulting transitive closure.
Most operators just map to a procedure. The parameters are combined into a tuple in the same order that they occur. Repeated parameters map to an n-tuple where n is the number of repeats. Optional parameters map to a 0-tuple or a 1-tuple. The procedure has to be appropriately polymorphic.
Every (sub)expression starts with an operator with no left and ends with an operator with no right. Every operator with no left is the start of one or more expressions, and every operator with no right is the end of one or more expressions. Every operator with no left will be preceded by a suboperator with a right which will swallow one of the expressions it starts. Every operator with no right is followed by an operator with a left to swallow one of the expressions it ends.
When an expression is required after a (sub)operator, and the following operator has no left, then the 0-tuple (unit:Unit) is inserted automatically. This means that unit can be written (), but also that it can be omitted almost anywhere that it might appear. [Note that '(' is an operator in Wombat, with ')' as a suboperator.]
When an operator with no right (such as an identifier or a parenthesized expression) is followed by an operator with no left, then a space-break token is inserted. In standard Wombat this is left associative procedure call. Actually if there is no actual white space (the break is created by the lexical analysis) then it is a different operator: tight-break. This also maps to procedure call. Tight-break is always an operator: it can't be used as a suboperator. Space-break can be used as a suboperator, and is so used in the list constructor operator (e.g. [12 34 56]).

Some initial code for SSS has been released. See the preceding post and https://github.com/rks987/wombatlang.

Very early code available

Some new languages have come out with a facility for user defined syntax that is quite weak compared to Wombat's. So I thought I'd code up (most of) Wombat's Super Simple Syntax. It is available at https://github.com/rks987/wombatlang. Pull requests welcome! It's not too late to become a founding father/mother of the Wombat Programming Language.

A blog post on Super Simple Syntax will follow this.

The code released is just enough to generate the AST for one small program. it is written in a simple recursive descent style using Python 3.4. Sadly it is not in Functional style. I have no idea how to do that for this program. Advice welcome (pull requests more so).

The SSS code does cover more than is required for the example program, so there is untested code. On the other hand there are features, such as sub-sub-operators and repeat groups, that are not yet implemented.

One reason the code is in Python is because it is the probable choice for the language for an initial version of Wombat Compile Time Language (WCTL). However maybe we can define WCTL as a JSON network API, so WCTL libraries can be written in any JSON-compatible language.

This is my first go with git and github. Let me know what I should be doing.