
IFMATCH/FILL Syntax Proposal

Current syntax is: ~?name, ~*name, ~+name

This causes ambiguities in parsing (~?name could be almost any type!)
There is also the ambiguity in IFMATCH: does ~?foo mean "match an item
and store the result in foo" or "match against the current value of foo".
Currently, IFMATCH takes the former interpretation if the variable is NIL
(unbound variables are initialised to NIL by the WSL to Lisp translator).
For global variables, the result of an IFMATCH depends on whether the variable
is bound or not in some procedure further up the (dynamic) call path.

Also, there is no way to interpolate the value of an expression
(eg @I^2) in a FILL: the value must be stored in a variable first.


Proposed syntax:

(1) Do away with ~+name matches: these are rarely used and the effect
can be achieved with ~?name1; ~*name2 if required.

(2) Indicate the type of the matched item in the pattern:
 ~S?name matches a Statement, ~E?name matches an Expression,
 ~V?name an Lvalue, ~C?name a Condition, ~G?name a Guarded,
 ~A?name an Assign, ~D?name a Definition, ~N?name a Name,
 ~X?name an Action (since A is already used for Assign!)

??? Do we need to distinguish eg ~S?name for a Statement and ~SS?name
for a statement sequence (type T_Statements)?  Probably not,
since we can always use ~S*name to match the whole sequence of statements.

Now that we have the new T_Name type we should be able to match
against the name of a procedure and the locate var of a FOR.

CALL and EXIT will still cause problems: what is the @Value of
the WSL statement "EXIT(~N?X)"? 

eg: IFMATCH Statement 
      FOR ~N?i := ~E?start TO ~E?end STEP ~E?step DO ~S*body OD

(3) Use ~S?=(...expn...) to match against the value of an expression:
allow Lvalues to match Expressions and vice versa. Use ~S*=(...expn...)
if the expression returns a list of items rather than a single item.
Allow ~S?=X as shorthand for ~S?=(X), ie omit the parentheses
when the expression is a single variable.

??? (4) Add a "functional form" of IFMATCH which takes an item to match
against and returns a table containing the matched variables.
Perhaps something like:

Match := IFMATCH(item) Statement IF ~C?B THEN ~S*S1 ELSE ~S*S2 ENDMATCH;

If the match succeeded, then Match.("B"), Match.("S1") and Match.("S2")
contain the matched item and lists of items respectively.

If the match failed, then Match is the empty sequence.


(5) Occasionally we need something like this:
IFMATCH Condition ~E?=(x) = ~E?=(y) ORMATCH ~E?=(y) = ~E?=(x) 
THEN ...
ELSE ... ENDMATCH

But what is the type of ORMATCH???

An "ANDMATCH" can be handled by a nested IFMATCH.
I don't think we need to combine patterns at a lower level, eg:
IFMATCH Assign ~V?x := ~(~ ~E?=(a) + ~E?=(b) ORMATCH ~E?=(b) + ~E?=(a) ~)~
THEN ...
ELSE ... ENDMATCH

...since this also could be handled by a nested IFMATCH.


Comments?

			Martin
