Re: [q-lang-users] New stuff in cvs: multichar ops, views
Brought to you by:
agraef
From: Albert G. <Dr....@t-...> - 2007-05-31 03:45:10
|
Hi John, John Cowan wrote: > I'm happy with that -- I assume that "--" is distinct from "- -" > where the latter is unary minus? Yes, sure. The unparser now also makes sure that spaces are inserted between adjacent binary and unary symbols. But note that this was just an example, (--) is not in the standard library. So unless you define (--) yourself you can still write 5--3 and get the expected result, 8. :) > (I always get bitten by unary minus in Q, still.) Care to explain why? I'd say that its usage is rather straightforward. The precedence is the same as in Pascal (IIRC), all you have to remember is that '-' in sections always denotes *binary* minus so to denote the unary minus function you have to write 'minus'. >> Wadler/Okasaki-style views (good stuff!): These are now implemented, > > Hurrah! Thought you might like that. ;-) IMHO, this is in fact the most useful addition to Q since 'unparse' (which is now called 'view', btw). I almost dropped the ball there, as this feature was, ahem, somewhat tricky to implement efficiently in the context of Q. But I perservered, and in the end I figured out how to do it. As a first exercise, I just comitted some changes which turn Complex into an ADT with the virtual constructor (:+). So the constant i now prints as 0:+1. (NB: I chose :+ for the sake of Haskell compatibility, but I actually think that it looks a bit weird. In Haskell they can't do any better because the ':' has to be on the left side to denote a constructor, IIRC. But I'd actually prefer +: for Q. Other suggestions, anyone?) (NB2: Rob, I'm sure you will like this, because you're an ADT fan and because this makes the treatment of Complex very similar to Rational, as you suggested before. We might have to fiddle with ratutils.q though, I'm not sure whether it uses the old 'complex' constructor in some places, which is not public any more. But it should be easy to fix that since the rest of the interface of Complex is unchanged.) I also have plans to turn 'lambda' into a virtual constructor for the builtin external <<Function>> type used to represent compiled lambdas, and, instead of having a builtin pretty-printing of <<Function>> objects, define an appropriate view for them. This will make it possible to write stuff like: foo (lambda X Y) = ...; even if 'foo' is not a special form and thus gets the lambda delivered in its compiled form. Right now it's necessary to play some dirty tricks with 'valq . str' to dissect a compiled lambda. 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 |