[q-lang-users] The implicit operator in Q
Brought to you by:
agraef
From: John C. <co...@cc...> - 2006-07-20 15:52:49
|
Today I discovered that (whether intentionally or not, I don't know) the Q rule processor will accept rules whose head is a variable. You can write rules like: X:Num Y:Num = X * Y; X:String Y:String = X ++ Y; X:List Y:List = X ++ Y; and get these results: ==> 5 6 30 ==> "abc" "def" "abcdef" ==> [1,2,3] [4,5,6] [1,2,3,4,5,6] In effect, Q is allowing an implicit (empty) operator in these cases. As long as the definition is associative, we also get useful results from curried invocations like: ==> 1 2 3 4 5 120 This could be a very handy feature when dealing with types that have some natural "principal" function of two or more arguments. -- Said Agatha Christie / To E. Philips Oppenheim John Cowan "Who is this Hemingway? / Who is this Proust? co...@cc... Who is this Vladimir / Whatchamacallum, http://www.ccil.org/~cowan This neopostrealist / Rabble?" she groused. --author unknown to me; any suggestions? |