Re: [q-lang-users] "listof" surprises
Brought to you by:
agraef
From: Albert G. <Dr....@t-...> - 2007-05-19 10:38:40
|
/me wrote: > Unfortunately, the above won't work yet if you define 'let' in terms of > 'case', because 'case' expressions aren't an instance of 'Lambda' right > now. Should they be? Probably. Another item for the Q 7.7 TODO list... Ok, this is fixed now. Thus the following alternative definition of 'let' will now work as expected: type Let : Lambda = special let B X; let (A=Z) X = case Z (A,X;); lambdax (let (A=Z) X) = '(case Z (A,X;)); As a bonus, I've also added two special forms 'condfun' and 'casefun' which allow you to create conditional and pattern-matching abstractions, which take their data as the second parameter. I.e., 'casefun' is just 'case' with its arguments reversed, which provides you with a means to quickly define an anonymous p.-m. function, e.g.: ==> casefun ((X,Y),X*Y;X,X) (2,3) 6 Similarly, 'condfun' applies the predicate P from each branch (P,X) to the extra parameter Y and, if it yields true, returns the corresponding X Y. For instance, here's a rather contrived way to describe the sign function: ==> condfun ((>0),cst 1;(<0),cst (-1);(=0),cst 0) 0 0 In fact, both 'case' and 'casefun' are now instances of 'Lambda' which just expand to an equivalent 'condfun' expression. Cheers, 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 |