Re: [q-lang-users] "listof" surprises
Brought to you by:
agraef
From: Albert G. <Dr....@t-...> - 2007-05-17 20:05:02
|
Hi Marco, again, it's a feature, not a bug. Please refer to Section 9.2 [Special Constructors] of the manual for an explanation: http://q-lang.sourceforge.net/qdoc/qdoc_9.html#SEC44 Quote: "Pattern matching on non-special arguments of a function takes into account embedded special data constructors and will automagically evaluate deferred subterms as needed." This "call-by-need" pattern matching works pretty much like in Haskell. It was introduced in Q 7.1. You can find a discussion of this feature in the mailing list archive: http://sourceforge.net/mailarchive/forum.php?thread_name=4463BF32.2020900%40t-online.de&forum_name=q-lang-users It makes it much easier to define non-special functions by pattern matching on lazy data structures. Special functions work as before (they will not do any automatic evaluations when matching special subterms), so declaring g to be a special form as well will give you the behaviour that you want. Cheers, Albert Marco Maggesi wrote: > Unfortunately, I found another obstacle (bug?). > I really do not understand this: given the program > > special expr E; > f (expr X) = expr X; > g (expr 0) = expr 0; > g (expr X) = expr X; > > I get > > ==> f (expr random) > expr random > > ==> g (expr random) > expr 2635609360 -- 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 |