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> 1>> This is the same like:>> q)parse "(+:)[a;1]"> +:>
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> 1>> This is the same like:>> q)parse "(+:)[a;1]"> +:>
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;a
b;c
d]”;“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 ((’;+:);enlista
b;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;a
b;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; =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>> 1<br>><br>> , first of which gets eval'ed to (';<<flipped a data>>;2*), and when<br>> applied to data 1, becomes equiv. to<br>><br>> (<<flipped a data>>;(2*;1))<br>> (<<flipped a data>>;2)<br>> 2 5<br>><br>> With this, it can be inferred that +: (or any q optr) is nothing but a<br>> name. What it means, depends on the eval context (num of args, types<br>> of args). The flip to +: translation is just a simple substitution at<br>> parse.<br>><br>><br>> 2*) adverb<br>><br>> q)a:42<br>> q)b:23<br>> q)eval ((';+:);enlist
ab;1 2)<br>> 'rank<br>><br>> inner +: seems interpreted as a stand-alone k operator (meaning flip),<br>> which can not take 2 args, leading to a 'rank error. IOW,<br>> interpretation of +: as an in-place +-then-: only happens at top-level<br>> eval.<br>><br>><br>> 2011/2/11 Aaron Davies <aaron.davies>:<br>>> On Feb 10, 10:56 am, petrum <petru.margin...> wrote:<br>>><br>>>> q)type (+:)<br>>>> 101h<br>>>><br>>>> I'm confused how a monadic function is called with 2 arguments (like a<br>>>> dyadic function)<br>>>><br>>>> I also noticed the 'flip' function has the same definition (unary<br>>>> '+'):<br>>>><br>>>> q)flip<br>>>> +:<br>>><br>>> the function type system is, um, advisory? "?" can be (among other<br>>> things), find (2 args), vector ternary (3 args), and select with and<br>>> without extended options (3, 4, or 5 args). all are the same function<br>>> and of type 102h:<br>>><br>>> 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>