question about a+:1

Hi,When I parse the above expression I get this:q)parse “a+:1”+:a1This is the same like:q)parse "(+:)[a;1]"+:a1On the other hand it looks like the ‘+:’ function is monadic:q)type (+:)101hI’m confused how a monadic function is called with 2 arguments (like adyadic function)I also noticed the ‘flip’ function has the same definition (unary’+'):q)flip+:I’ve tried to replace ‘+:’ with ‘flip’ and… it worked:q)a:1q)flip[a;1]q)a2q)parse “flip[a;1]”+:`a1Thanks,PM

2011/2/10, petrum <petru.marginean>:> Hi,>> When I parse the above expression I get this:>> q)parse “a+:1”> +:> a&gt; 1&gt;&gt; This is the same like:&gt;&gt; q)parse "(+:)[a;1]"&gt; +:&gt; a> 1>> On the other hand it looks like the ‘+:’ function is monadic:>> q)type (+:)> 101h>> I’m confused how a monadic function is called with 2 arguments (like a> dyadic function)>> I also noticed the ‘flip’ function has the same definition (unary> ‘+’):>> q)flip> +:>> I’ve tried to replace ‘+:’ with ‘flip’ and… it worked:>> q)a:1> q)flip[a;1]> q)a> 2>> q)parse “flip[a;1]”> +:> `a> 1>> Thanks,> PM>> –>

Submitted via Google Groups</petru.marginean>

Ove2011/2/10, petrum <petru.marginean>:> Hi,>> When I parse the above expression I get this:>> q)parse “a+:1”> +:> a&gt; 1&gt;&gt; This is the same like:&gt;&gt; q)parse "(+:)[a;1]"&gt; +:&gt; a> 1>> On the other hand it looks like the ‘+:’ function is monadic:>> q)type (+:)> 101h>> I’m confused how a monadic function is called with 2 arguments (like a> dyadic function)>> I also noticed the ‘flip’ function has the same definition (unary> ‘+’):>> q)flip> +:>> I’ve tried to replace ‘+:’ with ‘flip’ and… it worked:>> q)a:1> q)flip[a;1]> q)a> 2>> q)parse “flip[a;1]”> +:> `a> 1>> Thanks,> PM>> –>

Submitted via Google Groups</petru.marginean>

On Feb 10, 10:56?am, petrum <petru.margin…> wrote:> q)type (+:)> 101h>> I’m confused how a monadic function is called with 2 arguments (like a> dyadic function)>> I also noticed the ‘flip’ function has the same definition (unary> ‘+’):>> q)flip> +:the function type system is, um, advisory? “?” can be (among otherthings), find (2 args), vector ternary (3 args), and select with andwithout extended options (3, 4, or 5 args). all are the same functionand of type 102h:q)f:(“1?2”;“?[01b;ab;cd]”;“select from t”;“select[5]fromt”;“select[5;>x]from t”)q)distinct first each parse each f?q)distinct type each first each parse each f,102hplist is completely variadic (and immune to the eight-param limit),but of type 101h:q)plist 1,1q)plist[1;2]1 2q)plist[1;2;3;4;5;6;7;8;9;0]1 2 3 4 5 6 7 8 9 0q)type(plist)101hi’m told that some of this may be k3 legacy–in k3, monadics could becalled in postfix form as in “in-place” or “writeback” op–“a+:” wasequivalent to “a:+a”.in general, in-place forms seem to be available for all theoperators–“aX:b” means “a:aXb” for some operator X. here are a seriesof statements, where the last of each line returns true (note parserissues with underscore and dot):ao:a:1 2 3; b:4 5 6; a~:b; a~ao~bao:a:1 2 3; b:4 5 6; a!:b; a~ao!bao:a:1 2 3; b:4 5 6; a@:b; a~ao@bao:a:1 ; b:4 5 6; a#:b; a~ao#bao:a:“f” ; b:4 5 6; a$:b; a~ao$bao:a:1 2 3; b:4 5 6; a%:b; a~ao%bao:a:1 2 3; b:4 5 6; a^:b; a~ao^bao:a:1 2 3; b:4 5 6; a&:b; a~ao&bao:a:1 2 3; b:4 5 6; a*:b; a~ao*bao:a:1 ; b:4 5 6; a _:b ;a~ao _bao:a:1 2 3; b:4 5 6; a-:b; a~ao-bao:a:1 2 3; b:4 5 6; a+:b; a~ao+bao:a:1 2 3; b:4 5 6; a=:b; a~ao=bao:a:1 2 3; b:4 5 6; a|:b; a~ao|bao:a:1 2 3; b:4 5 6; a::b; a~ao:bao:a:1 2 3; b:4 5 6; a<:b; a~ao<bao:a:1 b:4 a>:b; a~ao>bao:a:1 2 3; b:4 5 6; a,:b; a~ao,bao:a:1 2 3; b:1#0 ; a .:b; a~ao . bao:a:1 2 3; b:4 5 6; a?:b; a~ao?b(i don’t yet know whether this is possible to do with apostrophe (inthe q senses of “case” or “compose”) or with adverbs)</bao:a:1></petru.margin…>

q operators are heavily overloaded. ‘type’ can only manifest one of them.

And it seems that in-place only happens at top-level eval, neither
inside compose nor with adverb:

1*) compose

q)a:42
q)eval (parse “a+:2*”;1)
'type

Interestingly, when a becomes a matrix, the same thing can eval (+: as flip=
):

q)a:2 3#til 6
q)eval (parse “a+:2*”;1)
2 5

I guess this is due to how curry works internally:

q)(parse “a+:2*”;1)
(';(+:;`a);(*;2))
1

, first of which gets eval’ed to (‘;<>;2*), and when
applied to data 1, becomes equiv. to

(<>;(2*;1))
(<>;2)
2 5

With this, it can be inferred that +: (or any q optr) is nothing but a
name. What it means, depends on the eval context (num of args, types
of args). The flip to +: translation is just a simple substitution at
parse.


2*) adverb

q)a:42
q)b:23
q)eval ((’;+:);enlistab;1 2)
'rank

inner +: seems interpreted as a stand-alone k operator (meaning flip),
which can not take 2 args, leading to a 'rank error. IOW,
interpretation of +: as an in-place ±then-: only happens at top-level
eval.


2011/2/11 Aaron Davies <aaron.davies>:
> On Feb 10, 10:56=A0am, petrum <petru.margin…> wrote:
>
>> q)type (+:)
>> 101h
>>
>> I’m confused how a monadic function is called with 2 arguments (like a
>> dyadic function)
>>
>> I also noticed the ‘flip’ function has the same definition (unary
>> ‘+’):
>>
>> q)flip
>> +:
>
> the function type system is, um, advisory? “?” can be (among other
> things), find (2 args), vector ternary (3 args), and select with and
> without extended options (3, 4, or 5 args). all are the same function
> and of type 102h:
>
> q)f:(“1?2”;“?[01b;ab;cd]”;“select from t”;“select[5]from
> t”;“select[5;>x]from t”)
> q)distinct first each parse each f
> ?
> q)distinct type each first each parse each f
> ,102h
>
> plist is completely variadic (and immune to the eight-param limit),
> but of type 101h:
>
> q)plist 1
> ,1
> q)plist[1;2]
> 1 2
> q)plist[1;2;3;4;5;6;7;8;9;0]
> 1 2 3 4 5 6 7 8 9 0
> q)type(plist)
> 101h
>
> i’m told that some of this may be k3 legacy–in k3, monadics could be
> called in postfix form as in “in-place” or “writeback” op–“a+:” was
> equivalent to “a:+a”.
>
> in general, in-place forms seem to be available for all the
> operators–“aX:b” means “a:aXb” for some operator X. here are a series
> of statements, where the last of each line returns true (note parser
> issues with underscore and dot):
>
> ao:a:1 2 3; b:4 5 6; =A0a~:b; a~ao~b
> ao:a:1 2 3; b:4 5 6; =A0a!:b; a~ao!b
> ao:a:1 2 3; b:4 5 6; =A0a@:b; a~ao@b
> ao:a:1 =A0 =A0; b:4 5 6; =A0a#:b; a~ao#b
> ao:a:“f” =A0; b:4 5 6; =A0a$:b; a~ao$b
> ao:a:1 2 3; b:4 5 6; =A0a%:b; a~ao%b
> ao:a:1 2 3; b:4 5 6; =A0a^:b; a~ao^b
> ao:a:1 2 3; b:4 5 6; =A0a&:b; a~ao&b
> ao:a:1 2 3; b:4 5 6; =A0a*:b; a~ao*b
> ao:a:1 =A0 =A0; b:4 5 6; =A0a _:b ;a~ao _b
> ao:a:1 2 3; b:4 5 6; =A0a-:b; a~ao-b
> ao:a:1 2 3; b:4 5 6; =A0a+:b; a~ao+b
> ao:a:1 2 3; b:4 5 6; =A0a=3D:b; a~ao=3Db
> ao:a:1 2 3; b:4 5 6; =A0a|:b; a~ao|b
> ao:a:1 2 3; b:4 5 6; =A0a::b; a~ao:b
> ao:a:1 2 3; b:4 5 6; =A0a<:b; a~ao> ao:a:1 2 3; b:4 5 6; =A0a>:b; a~ao>b
> ao:a:1 2 3; b:4 5 6; =A0a,:b; a~ao,b
> ao:a:1 2 3; b:1#0 =A0; a .:b; a~ao . b
> ao:a:1 2 3; b:4 5 6; =A0a?:b; a~ao?b
>
> (i don’t yet know whether this is possible to do with apostrophe (in
> the q senses of “case” or “compose”) or with adverbs)
>
> –
>

Submitted via Google Groups</petru.margin…></aaron.davies>

2011/2/11, =BA=CE=CE=A1 <hewei.com>:
> q operators are heavily overloaded. ‘type’ can only manifest one of them.
>
> And it seems that in-place only happens at top-level eval, neither
> inside compose nor with adverb:
>
> 1*) compose
>
> q)a:42
> q)eval (parse “a+:2*”;1)
> ‘type
>
> Interestingly, when a becomes a matrix, the same thing can eval (+: as
> flip):
>
> q)a:2 3#til 6
> q)eval (parse “a+:2*”;1)
> 2 5
>
> I guess this is due to how curry works internally:
>
> q)(parse “a+:2*”;1)
> (’;(+:;a);(*;2))<br>&gt; 1<br>&gt;<br>&gt; , first of which gets eval'ed to (';&lt;<flipped a data>&gt;;2*), and when<br>&gt; applied to data 1, becomes equiv. to<br>&gt;<br>&gt; (&lt;<flipped a data>&gt;;(2*;1))<br>&gt; (&lt;<flipped a data>&gt;;2)<br>&gt; 2 5<br>&gt;<br>&gt; With this, it can be inferred that +: (or any q optr) is nothing but a<br>&gt; name. What it means, depends on the eval context (num of args, types<br>&gt; of args). The flip to +: translation is just a simple substitution at<br>&gt; parse.<br>&gt;<br>&gt;<br>&gt; 2*) adverb<br>&gt;<br>&gt; q)a:42<br>&gt; q)b:23<br>&gt; q)eval ((';+:);enlistab;1 2)<br>&gt; 'rank<br>&gt;<br>&gt; inner +: seems interpreted as a stand-alone k operator (meaning flip),<br>&gt; which can not take 2 args, leading to a 'rank error. IOW,<br>&gt; interpretation of +: as an in-place +-then-: only happens at top-level<br>&gt; eval.<br>&gt;<br>&gt;<br>&gt; 2011/2/11 Aaron Davies <aaron.davies>:<br>&gt;&gt; On Feb 10, 10:56 am, petrum <petru.margin...> wrote:<br>&gt;&gt;<br>&gt;&gt;&gt; q)type (+:)<br>&gt;&gt;&gt; 101h<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; I'm confused how a monadic function is called with 2 arguments (like a<br>&gt;&gt;&gt; dyadic function)<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; I also noticed the 'flip' function has the same definition (unary<br>&gt;&gt;&gt; '+'):<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; q)flip<br>&gt;&gt;&gt; +:<br>&gt;&gt;<br>&gt;&gt; the function type system is, um, advisory? "?" can be (among other<br>&gt;&gt; things), find (2 args), vector ternary (3 args), and select with and<br>&gt;&gt; without extended options (3, 4, or 5 args). all are the same function<br>&gt;&gt; and of type 102h:<br>&gt;&gt;<br>&gt;&gt; q)f:("1?2";"?[01b;ab;c`d]";“select from t”;“select[5]from
>> t”;“select[5;>x]from t”)
>> q)distinct first each parse each f
>> ?
>> q)distinct type each first each parse each f
>> ,102h
>>
>> plist is completely variadic (and immune to the eight-param limit),
>> but of type 101h:
>>
>> q)plist 1
>> ,1
>> q)plist[1;2]
>> 1 2
>> q)plist[1;2;3;4;5;6;7;8;9;0]
>> 1 2 3 4 5 6 7 8 9 0
>> q)type(plist)
>> 101h
>>
>> i’m told that some of this may be k3 legacy–in k3, monadics could be
>> called in postfix form as in “in-place” or “writeback” op–“a+:” was
>> equivalent to “a:+a”.
>>
>> in general, in-place forms seem to be available for all the
>> operators–“aX:b” means “a:aXb” for some operator X. here are a series
>> of statements, where the last of each line returns true (note parser
>> issues with underscore and dot):
>>
>> ao:a:1 2 3; b:4 5 6; a~:b; a~ao~b
>> ao:a:1 2 3; b:4 5 6; a!:b; a~ao!b
>> ao:a:1 2 3; b:4 5 6; a@:b; a~ao@b
>> ao:a:1 ; b:4 5 6; a#:b; a~ao#b
>> ao:a:“f” ; b:4 5 6; a$:b; a~ao$b
>> ao:a:1 2 3; b:4 5 6; a%:b; a~ao%b
>> ao:a:1 2 3; b:4 5 6; a^:b; a~ao^b
>> ao:a:1 2 3; b:4 5 6; a&:b; a~ao&b
>> ao:a:1 2 3; b:4 5 6; a*:b; a~ao*b
>> ao:a:1 ; b:4 5 6; a _:b ;a~ao _b
>> ao:a:1 2 3; b:4 5 6; a-:b; a~ao-b
>> ao:a:1 2 3; b:4 5 6; a+:b; a~ao+b
>> ao:a:1 2 3; b:4 5 6; a=3D:b; a~ao=3Db
>> ao:a:1 2 3; b:4 5 6; a|:b; a~ao|b
>> ao:a:1 2 3; b:4 5 6; a::b; a~ao:b
>> ao:a:1 2 3; b:4 5 6; a<:b; a~ao>> ao:a:1 2 3; b:4 5 6; a>:b; a~ao>b
>> ao:a:1 2 3; b:4 5 6; a,:b; a~ao,b
>> ao:a:1 2 3; b:1#0 ; a .:b; a~ao . b
>> ao:a:1 2 3; b:4 5 6; a?:b; a~ao?b
>>
>> (i don’t yet know whether this is possible to do with apostrophe (in
>> the q senses of “case” or “compose”) or with adverbs)
>>
>> –
>> You received this message because you are subscribed to the Google Group=
s
>> “Kdb+ Personal Developers” group.
>> To post to this group, send email to personal-kdbplus@googlegroups.com.
>> To unsubscribe from this group, send email to
>> personal-kdbplus+unsubscribe@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/personal-kdbplus?hl=3Den.
>>
>>
>

–=20
=B4=D3=CE=D2=B5=C4=D2=C6=B6=AF=C9=E8=B1=B8=B7=A2=CB=CD

</petru.margin…></aaron.davies></hewei.com>