learning each /: \:

hi guys,

how can i shorten the second expression here??

i’m sure i’ve got too many enlist /: , : words.

q)r:(“eax”;“ecx”;“edx”)

q)raze raze (enlist each (“mov”;“add”)){x,/:y}/::r{enlist x,y}/::r ?

“mov” “eaxeax”

“mov” “eaxecx”

“mov” “eaxedx”

“mov” “ecxeax”

“mov” “ecxecx”

“mov” “ecxedx”

“mov” “edxeax”

“mov” “edxecx”

“mov” “edxedx”

“add” “eaxeax”

“add” “eaxecx”

“add” “eaxedx”

“add” “ecxeax”

“add” “ecxecx”

“add” “ecxedx”

“add” “edxeax”

“add” “edxecx”

“add” “edxedx”

ta, jack

I’m sure there’s a better way, but this is all you get for a Friday night at midnight. How did you leave ebx out? I mean common he’s all about the array crowd ;-)

q)r

“eax”

“ecx”

“edx”

q)a

"mov "

"add "

q)a cross","sv’3 cut’r cross r

“mov eax,eax”

“mov eax,ecx”

“mov eax,edx”

“mov ecx,eax”

“mov ecx,ecx”

“mov ecx,edx”

“mov edx,eax”

“mov edx,ecx”

“mov edx,edx”

“add eax,eax”

“add eax,ecx”

“add eax,edx”

“add ecx,eax”

“add ecx,ecx”

“add ecx,edx”

“add edx,eax”

“add edx,ecx”

“add edx,edx”

i’m quite happy with this now:

q).q.X:cross;.q.XX:{x X x}
q)(4 cut"mov add “)X”,“sv’3 cut’XX"e”,'2 cut"axcxdxbxbpsidi"
“mov eax,eax”
“mov eax,ecx”
“mov eax,edx”
“mov eax,ebx”
“mov eax,ebp”
..

but disappointed that i can’t write something like this (in k):

(0 4_“mov add “)X”,”:/'0 3_'XX"e",'0 2_“axcxdxbxbpsidi”

To: personal-kdbplus@googlegroups.com
X-Mailer: Apple Mail (2.1084)

> but disappointed that i can’t write something like this (in k):
>
> (0 4_“mov add “)X”,”:/'0 3_'XX"e",'0 2_“axcxdxbxbpsidi”

.q.X[.q.cut[4]“mov add “]@”,”/:‘3 .q.cut’.q.XX"e",'.q.cut[2]“axcxdxbxbpsidi”

or

.q.X[0N 4#“mov add “]@”,”/:'0N 3#/:.q.XX"e",'0N 2#“axcxdxbxbpsidi”

incidentally to me the most natural solution to the original question is

q)r:enlist each(“eax”;“ecx”;“edx”)
q)o:enlist each(“mov”;“add”)
q)o cross r cross r
“mov” “eax” “eax”
“mov” “eax” “ecx”
“mov” “eax” “edx”
“mov” “ecx” “eax”
“mov” “ecx” “ecx”
“mov” “ecx” “edx”
“mov” “edx” “eax”
“mov” “edx” “ecx”
“mov” “edx” “edx”
“add” “eax” “eax”
“add” “eax” “ecx”
“add” “eax” “edx”
“add” “ecx” “eax”
“add” “ecx” “ecx”
“add” “ecx” “edx”
“add” “edx” “eax”
“add” “edx” “ecx”
“add” “edx” “edx”

or

q)raze o,/::raze r,/::r
“mov” “eax” “eax”
“mov” “eax” “ecx”
“mov” “eax” “edx”
“mov” “ecx” “eax”
“mov” “ecx” “ecx”
“mov” “ecx” “edx”
“mov” “edx” “eax”
“mov” “edx” “ecx”
“mov” “edx” “edx”
“add” “eax” “eax”
“add” “eax” “ecx”
“add” “eax” “edx”
“add” “ecx” “eax”
“add” “ecx” “ecx”
“add” “ecx” “edx”
“add” “edx” “eax”
“add” “edx” “ecx”
“add” “edx” “edx”

hi aaron,below…On Tue, Jan 17, 2012 at 2:42 PM, Aaron Davies <aaron.davies> wrote:>> but disappointed that i can’t write something like this (in k):>>>> (0 4_“mov add “)X”,”:/'0 3_'XX"e",‘0 2_“axcxdxbxbpsidi”>> .q.X[.q.cut[4]“mov add “]@”,”/:‘3 .q.cut’.q.XX"e",’.q.cut[2]"axcxdxbxbpsidi"i was disappointed that i can’t define X as an infix operator in k(ie. use X without .q.X qualification)> incidentally to me the most natural solution to the original question is>> q)r:enlist each(“eax”;“ecx”;“edx”)> q)o:enlist each(“mov”;“add”)> q)o cross r cross r> “mov” “eax” “eax”> “mov” “eax” "ecx"yes, this is the essence of the expression. i have the cuts on inputdata so i can show my input and intention in one line - maybe 3 lineswould have been better. what would arthur do?ta, jack.</aaron.davies>

To: personal-kdbplus@googlegroups.com
X-Mailer: Apple Mail (2.1084)

>>> but disappointed that i can’t write something like this (in k):
>>>
>>> (0 4_“mov add “)X”,”:/'0 3_'XX"e",‘0 2_“axcxdxbxbpsidi”
>>
>> .q.X[.q.cut[4]“mov add “]@”,”/:‘3 =
.q.cut’.q.XX"e",’.q.cut[2]“axcxdxbxbpsidi”
>
> i was disappointed that i can’t define X as an infix operator in k
> (ie. use X without .q.X qualification)

yes, unfortunately k has neither of the blessed namespace behaviors =
(resolving and infix)

>> incidentally to me the most natural solution to the original question =
is
>>
>> q)r:enlist each(“eax”;“ecx”;“edx”)
>> q)o:enlist each(“mov”;“add”)
>> q)o cross r cross r
>> “mov” “eax” “eax”
>> “mov” “eax” “ecx”
>
> yes, this is the essence of the expression. i have the cuts on input
> data so i can show my input and intention in one line - maybe 3 lines
> would have been better. what would arthur do?

i don’t know, i might do

q){x," “,y,”,“,z}.'{(cross)over(enlist each x;y;y:enlist each =
y)}[(“mov”;“add”);“e”,'2 cut"axcxdxbxbpsidi”]

k){x," “,y,”,",z}.'{.q.cross/(,:'x;y;y:,:'y)}[(“mov”;“add”);“e”,'0N =
2#“axcxdxbxbpsidi”]

if i wanted to keep it on one line

i might prefer something like

q){x," “,y,”,“,z}.'string{(cross)over(x;y;y)}[`mov`add;`$“e”,'2 =
cut"axcxdxbxbpsidi”]

k){x," “,y,”,",z}.'${.q.cross/(x;y;y)}[`mov`add;`$“e”,'0N =
2#“axcxdxbxbpsidi”]

though, since conceptually the opcodes and registers are enums =
(independent of how you generate them)

(my best guess at arthur’s style might be something like

k){" “/:',/(,:‘0N 3#x),/::,:’”,"/:'y:,/y,/::y:,:'y}[“movadd”]“e”,'0N =
2#“axcxdxbxbpsidi”

taking it as a string-manipulation problem, or

k){,/'${,/z,/::y,'x}/[y;", =
";(y;x)]}[movadd]$"e",'$axcxdxbxbpsidi

as a list-manipulation problem)=

hi aaron,> i might dothanks for your code - i am studying it, i see how useful projection is.> though, since conceptually the opcodes and registers are enums (independent of how you generate them)actually, my aim is to see how an assembler deals with differentinput… i’ve got an i686 reference, but it’s good to confirm withassembler output. then a larger goal is to generate machine languagedirectly.(following the leader)ta, jack