[q-lang-users] New 'where' syntax
Brought to you by:
agraef
From: Albert G. <Dr....@t-...> - 2007-05-25 00:45:22
|
Hi all, Ok, I've finally given in to popular demand and added a syntax for shared 'if' and 'where' clauses. ;-) It's based on the idea of placing the guards on the lhs of an equation which, IIRC, was first suggested by Eddie, but the solution I implemented is more general in that it allows arbitrary collections of 'if's and 'where's to be placed on the lhs of an equation. This is in cvs now, but not documented in the manual yet, and also needs some more testing, so please report bugs asap. Here's the scoop from the NEWS file: There's a new syntax for guards ('if' and 'where' clauses) which may be shared by different equations for the same left-hand side. The new kind of guards is written on the left-hand side of an equation, like so: fact N if N>0: = N*fact (N-1); otherwise: = 1; The lhs guards work exactly like the "old-style" guards which are written on the right-hand side, at the end of an equation, but while the latter are always confined to a single equation, the former have a scope which extends up to the next equation with either another lhs guard or an explicit left-hand side. Conditions and local variable bindings are then shared between all equations in the scope of the guard. Of course, lhs guards can be freely mixed with rhs guards. For instance: strip C S where N = #S-1 if not null S: = strip C $ sub S 0 (N-1) if S!N = C; = strip C $ sub S 1 N if S!0 = C; otherwise: = S; Here, the scope of the condition 'not null S' and the local definition 'N = #S-1' encompasses the first two equations. Enjoy! :) Albert -- Dr. Albert Gr"af Dept. of Music-Informatics, University of Mainz, Germany Email: Dr....@t-..., ag...@mu... WWW: http://www.musikinformatik.uni-mainz.de/ag |