On Dec 11, 2010, at 3:34 AM, _Oz_ wrote:
> I’m putting together a little helper for q developers/users (hope to
> present solid beta for community sometime in January). One of its
> features will be - server workspace explorer.
>
> Tricky part that I ran into just now - is to get names of all
> workspaces, including nested ones. (key will give you only ones from \> root) \> \> So far I came up with those two lines for the task: \> f:{,/[except[x,{$[99=@:[.:[x]];$[(@[;0]!:[.:[x]];@[;0].:[.: \> [x]])~(
;::);f;];]}each sv[;]each x,:/:1\_key .:[x];::]]}; \> raze f each sv[
;]each,'
,key`
>
> But there’s a couple of problems I’m having with this solution:
> 1) Temporary lambda (with some more rare name than f) should be
> created and deleted afterwards.
> - Shouldn’t there be away to do inline recursion?
> 2) I just can’t help thinking that there should be a simpler way :).
>
> Since I acquainted with q for not that long yet, I wanted to ask
> advice from real gurus out there ;-).
here’s a few things i’ve been tweaking for the past couple years that
might help.
wtfcat gets the fully-qualified names of everything in or below its
argument (which is defaulted to do both . and key
, i.e. everything)
wtffd gets specifically all the lambdas in the workspace, then
recursively searches them for embedded lambdas and gives those
unambiguous names
wtf returns the name of a function matching its argument (intended use
is “wtf .z.s” from an error prompt)
callers is still a little buggy, but is meant to identify where a
function is called
(recursion in general is done with .z.s
https://code.kx.com/trac/wiki/Reference/dotzdots)
mapd:{y!x y,:()}
dfilter:{where[x y]#y,:()}
wtfcat:{$[$[null x;1;99=type get x;~first key x;0b]|
.~x;
(raze/).z.s each’x .Q.dd’'key each x:$[null x;.
;x];x]}
wtffd:{(!). flip raze
{enlist[(x;y)],raze .z.s’[(x,`lambda).Q.dd/:til count p;p@:where
100=type each p:get y]}.’
{key,'get x}dfilter[100=type each]mapd[get each]wtfcat x}
wtf:{wtffd?x}
callers:{where x{x in get[y]3}'wtffd}
Aaron Davies
aaron.davies@gmail.com