Hello:
Is there a way to compose two function f,g without using {}?
I know (2+3-) is a composition. But I failed to define composition of (inc inc) where inc:(1+)
Thanks in advance.
Hello:
Is there a way to compose two function f,g without using {}?
I know (2+3-) is a composition. But I failed to define composition of (inc inc) where inc:(1+)
Thanks in advance.
q)inc:(1+)
q)(inc inc@)2
4
q)f:{[w;x;y;z]w+x+y+z}<o:p></o:p>
q)g:{2*x}<o:p></o:p>
q)h:(‘[g;f]) / The interpreter is finicky about :’<o:p></o:p>
q)h[1;2;3;4]<o:p></o:p>
20<o:p></o:p>
<o:p> </o:p>
HTH,<o:p></o:p>
<o:p> </o:p>
Kim<o:p></o:p>
<o:p> </o:p>
Von: personal-kdbplus@googlegroups.com [mailto:personal-kdbplus@googlegroups.com] Im Auftrag von Hao Deng
Gesendet: Mittwoch, 8. Oktober 2014 11:09
An: personal-kdbplus@googlegroups.com
Betreff: [personal kdb+] function composition<o:p></o:p>
<o:p> </o:p>
Hello:<o:p></o:p>
Is there a way to compose two function f,g without using {}?<o:p></o:p>
I know (2+3-) is a composition. But I failed to define composition of (inc inc) where inc:(1+)<o:p></o:p>
<o:p> </o:p>
Thanks in advance.<o:p></o:p>
<o:p> </o:p>
–
Submitted via Google Groups
Thank you both Charles and Kim:
Both usage are not documents in http://code.kx.com/wiki/Reference and anywhere I can find.
Did I missed any documents?
Thanks Charles.
I don’t understand the @ part.
I understand inc@ is a curry (project) of @,
but how does inc inc@ get parsed? Is this a special form?
juxtaposition is implicit apply
q)x:a
bc
d
q)x@2 3
c
d
q)x 2 3
c
d
if there’s no juxtaposition, i.e. no rhs, and you don’t want immediate evaluation, you have to explicitly insert an infix verb as the terminating token.
btw, you can pull compositions apart with value. e.g.
value(inc inc@)