Simple question here is there an easy way to save all functions for a given instance?/and/or push those functions to another instances maybe using hopen?
Hi,
This is one way …
q)traverse:{$[(0=count k)or x~k:key x; x; .z.s each sv' x,/:k except
]} //slightly modified version of traverse from torQ, will iterate through namespaces
q)findFuncs:{funcs where ((type value@)@‘funcs:3(raze)/traverse’[ sv'
,'key[]except
$‘raze .Qa
A]) within 100 112h} //from the list above, find functions, remove single letter[reserved] namespaces
q)setFuncs:{[handle;list] handle(set’;list;list)} //set list found above, across ipc, to the same names
example:
proc1) rlwrap q -p 5001
proc2) h:hopen 5001 ; .sean.a:10 ; .sean.f:{x+y} ; .sean.t:(10?10) ; .sean.b.c:{x*y};
//push from proc2 to proc1
q)setFuncs[h;findFuncs]
.sean.f
.sean.b.c
To save the functions just write them to disk, set them down to binary files, text files, whatever you may like to do with them once you have got them all in a nice list.
Let us know if you have issues with that.
HTH,
Sean
Aaron Davies had posted a very useful solution using upsert and hopen in 2010 to k4 list that I copy below with function definition example
$ q -p 5050
q)a:1
q)b:`foo
q)c:(x:())
q)w:til 10
q)f:{(sum x)%count x}
$ q
q). upsert hopen[5050]
.
`.
q)a
1
q)b
`foo
q)c
x
q)f
{(sum x)%count x}
q)f w
4.5
Thanks, this works for any function not in the default . name space. What modifications should be made in order to save the default namespace functions?
Thanks.
On Monday, December 5, 2016 at 3:09:56 PM UTC-6, Sean O’Hagan wrote:
Hi,
This is one way …
q)traverse:{$[(0=count k)or x~k:key x; x; .z.s each
sv' x,/:k except
]} //slightly modified version of traverse from torQ, will iterate through namespaces
q)findFuncs:{funcs where ((type value@)@‘funcs:3(raze)/traverse’[sv'
,'key[]except
$‘raze .Qa
A]) within 100 112h} //from the list above, find functions, remove single letter[reserved] namespaces
q)setFuncs:{[handle;list] handle(set’;list;list)} //set list found above, across ipc, to the same names
example:
proc1) rlwrap q -p 5001
proc2) h:hopen 5001 ; .sean.a:10 ; .sean.f:{x+y} ; .sean.t:(10?10) ; .sean.b.c:{x*y};
//push from proc2 to proc1
q)setFuncs[h;findFuncs].sean.f
.sean.b.c
To save the functions just write them to disk, set them down to binary files, text files, whatever you may like to do with them once you have got them all in a nice list.
Let us know if you have issues with that.
HTH,
Sean
Add in for the root(or just
if it is just the root functions you are looking to copy over)
findFuncs:{funcs where ((type value@)@‘funcs:3(raze)/traverse’[ sv'
,',key[
]except $'raze .Q
a`A]) within 100 112h}
Also you may need to change setFuncs slightly:
setFuncs:{[handle;list] handle(set’;list;value’[list])}
btw, if you looking to directly copy over a namespace(as long as you know you are completely overwriting one with the other) you can do
h(set;.;value
.) //might be more useful for you
Sean