Re: [q-lang-users] New stuff in cvs: multichar ops, views
Brought to you by:
agraef
From: Albert G. <Dr....@t-...> - 2007-05-31 11:18:58
|
John Cowan wrote: > I always forget that -2 is the application of minus to 2 rather than a > constant, so I write things like "foo -2", which then turns out to be > "(foo -) 2". Well, syntactically the '-' in '-2' is a unary minus, although semantically, it's still a number and not an explicit application of minus. IMHO, that's the only reasonable way to implement it, since I want '-2' and '-X' to be parsed in the same manner. >> 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. > > I don't like that much. I suppose there is no way to make 0+1*i the > constructor/view? I guess not, since Q is eager. Well, X+Y*i doesn't work here since '+' is not a virtual constructor of Complex, so while you can use this for pretty-printing (as we did in Q 7.6), you can't write stuff like 'foo (X+Y*i) = ...'. So, to make matching against the view work, the head symbol of the view must be a virtual constructor of the type and that's the purpose that ':+' serves. We could have something like 'X:+Y*i' instead of just 'X:+Y' but that seems redundant. What's so bad about 'X:+Y'? I can easily read ':+' aloud as "+i times". 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 |