The average below isn't tacit since it refers to the argument of the function, x. It's true that J's [ and ] do similar things, but with entirely different semantics: they are actually functions of one or two arguments that return the appropriate argument. Perhaps it's not so evident here, but in J you could also write something like (- * +) and execute it on two variables to multiply their sum and their difference. Q would require {(x-y) * (x+y)} , which is unwieldy.
Marshall On Tue, Jan 17, 2012 at 9:14 PM, Colin Ward <ward...@gmail.com> wrote: > Thank you to everyone for your replies. I have taken the advice of the > first response and am trying both, starting with q. > > On tacit programming, i think i have found it is possible in q, and it does > have currying. They have default (implicit?) arguments x and y to refer to > the first and second args in a monad/dyadic function. similar to j's [ > and ] operators? > > So by my reckoning this code below is an example of tacit average in q? > q) is the prompt... > > > q)average:{ (sum x) % count x} > q)average[2 3 4] > 3f > q)average[2 3 4 5] > 3.5 > > hope my other three questions are as easy to figure out... > > On 17 January 2012 00:59, Boyko Bantchev <boyk...@gmail.com> wrote: > > > On 16 January 2012 18:11, Kim Kuen Tang <kuent...@vodafone.de> wrote: > > > > > > I tried to calculate the mean in K using tacit programming. > > > (+/%# ) !10 > > > But it is not working. Can you show how to program it in K? > > > > There are no forks like +/%# in K. Instead, you can do: > > avg: %/(+/;#:)@\: > > avg 2 3 7 > > 4.0 > > avg' (2 3 7; 5 6) > > 4 5.5 > > > > Or, you can define a `fork' yourself: > > fork: {[f;g;h;x] g[f[x];h[x]]} > > which itself is non-tacit, but allows tacit definitions such as: > > avg: fork[+/;%;#:;] > > ---------------------------------------------------------------------- > > For information about J forums see http://www.jsoftware.com/forums.htm > > > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm