From simon@kx.com  Mon Apr 18 08:18:25 2011
Received: from mx.cims.nyu.edu (mx.cims.nyu.edu [128.122.49.99])
	by mail.cims.nyu.edu (8.14.4+Sun/8.14.4) with ESMTP id p3ICIP5Z014994
	for <shasha@mail.cims.nyu.edu>; Mon, 18 Apr 2011 08:18:25 -0400 (EDT)
Received: from mail-gw0-f46.google.com (mail-gw0-f46.google.com [74.125.83.46])
	by mx.cims.nyu.edu (8.13.8+Sun/8.13.8) with ESMTP id p3ICIDGo024557
	for <shasha@courant.nyu.edu>; Mon, 18 Apr 2011 08:18:13 -0400 (EDT)
Received: by gwaa18 with SMTP id a18so1644013gwa.19
        for <shasha@courant.nyu.edu>; Mon, 18 Apr 2011 05:18:08 -0700 (PDT)
Received: by 10.236.187.70 with SMTP id x46mr3517305yhm.179.1303129088326;
 Mon, 18 Apr 2011 05:18:08 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.147.169.6 with HTTP; Mon, 18 Apr 2011 05:17:48 -0700 (PDT)
In-Reply-To: <201104180723.p3I7N7xJ017626@access1.cims.nyu.edu>
References: <201104180723.p3I7N7xJ017626@access1.cims.nyu.edu>
From: Simon Garland <simon@kx.com>
Date: Mon, 18 Apr 2011 14:17:48 +0200
Message-ID: <BANLkTimLCNZqtbcr-_x6N5A1jKscXCbU0Q@mail.gmail.com>
Subject: Re: debugging functions
To: Dennis Shasha <shasha@courant.nyu.edu>
Content-Type: multipart/alternative; boundary=20cf305b12c267fc3204a1306292
X-Scanned-By: MIMEDefang 2.71 on 128.122.49.99
X-Greylist: Sender DNS name whitelisted, not delayed by milter-greylist-4.2.6 (mx.cims.nyu.edu [128.122.49.99]); Mon, 18 Apr 2011 08:18:24 -0400 (EDT)
Status: RO
Content-Length: 4673

--20cf305b12c267fc3204a1306292
Content-Type: text/plain; charset=UTF-8

Hi Dennis,

it's just a utility to display the details from the bytecode representation
of a function in a more readable fashion
(see https://code.kx.com/trac/wiki/Reference/value)
taking advantage of the fact that when suspended .z.s will get you the
function you're suspended in - so:

q).q.wtf:.q.dotzs:{`d`P`L`G`D!(system"d"),v[1 2 3],enlist last v:value x}
q)foo:{aa:1;bb:1 2 3;x+999}
q)foo `fail
{aa:1;bb:1 2 3;x+999}
'type
+
`fail
999
q))wtf .z.s
`d`P`L`G`D!(`.;,`x;`aa`bb;,`;"{aa:1;bb:1 2 3;x+999}")

/ if you're inside a function then the display will fall back to k display,
so you might want to make it more accessible to humans by using .Q.s to
format

q))-1 .Q.s wtf .z.s;
d| `.
P| ,`x
L| `aa`bb
G| ,`
D| "{aa:1;bb:1 2 3;x+999}"

q))

general advice for debugging? it's still really hard
we shot ourselves in the foot with this when introducing multithreading -
and it can't really be fixed without a fairly major rewrite of core parts of
k
that's being looked at, but there won't be anything in a hurry.

I use 0N! sprinkled liberally around the code

a:0N!x+0N!y*2 / this sort of thing

and for more extensive digging around still debug4 from Eberhard Lutz

https://code.kx.com/trac/browser/contrib/simon/debug4/debug4.k

still back in the printf dark ages I'm afraid

/Simon

On Mon, Apr 18, 2011 at 09:23, Dennis Shasha <shasha@courant.nyu.edu> wrote:

>
> Dear Simon,
> In Jeff's book, he refers to a function you have written called
> zs:{`d`P`L`G`D!(system"d"),v[1 2 3],enlist last v:value x}
>
> How exactly do you use it?
>
> Does it work on kdb debugging?
>
> Do you have general advice on the debugging topic?
>
> Thanks,
> Dennis
>

--20cf305b12c267fc3204a1306292
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Hi Dennis,<div><br></div><div>it&#39;s just a utility to display the detail=
s from the bytecode representation of a function in a more readable fashion=
</div><div>(see=C2=A0<a href=3D"https://code.kx.com/trac/wiki/Reference/val=
ue">https://code.kx.com/trac/wiki/Reference/value</a>)</div>

<div>taking advantage of the fact that when suspended .z.s will get you the=
 function you&#39;re suspended in - so:</div><div><br></div><div><div>q).q.=
wtf:.q.dotzs:{`d`P`L`G`D!(system&quot;d&quot;),v[1 2 3],enlist last v:value=
 x} =C2=A0</div>

<div>q)foo:{aa:1;bb:1 2 3;x+999}</div><div>q)foo `fail</div><div>{aa:1;bb:1=
 2 3;x+999}</div><div>&#39;type</div><div>+</div><div>`fail</div><div>999</=
div><div>q))wtf .z.s</div><div>`d`P`L`G`D!(`.;,`x;`aa`bb;,`;&quot;{aa:1;bb:=
1 2 3;x+999}&quot;)</div>

<div><br></div><div>/ if you&#39;re inside a function then the display will=
 fall back to k display, so you might want to make it more accessible to hu=
mans by using .Q.s to format=C2=A0</div><div><br></div><div>q))-1 .Q.s wtf =
.z.s;</div>

<div>d| `.</div><div>P| ,`x</div><div>L| `aa`bb</div><div>G| ,`</div><div>D=
| &quot;{aa:1;bb:1 2 3;x+999}&quot;</div><div><br></div><div>q))</div><div>=
<br></div><div>general advice for debugging? it&#39;s still really hard=C2=
=A0</div>

<div>we shot ourselves in=C2=A0the foot with this when introducing multithr=
eading - and it can&#39;t really be fixed without a fairly major rewrite of=
 core parts of k=C2=A0</div><div>that&#39;s being looked at, but there won&=
#39;t be anything in a hurry.</div>

<div><br></div><div>I use 0N! sprinkled liberally around the code=C2=A0</di=
v><div><br></div><div>a:0N!x+0N!y*2 / this sort of thing=C2=A0</div><div><b=
r></div><div>and for more extensive digging around still debug4 from Eberha=
rd Lutz=C2=A0</div>

<div><br></div><div><a href=3D"https://code.kx.com/trac/browser/contrib/sim=
on/debug4/debug4.k">https://code.kx.com/trac/browser/contrib/simon/debug4/d=
ebug4.k</a></div><div><br></div><div>still back in the printf dark ages I&#=
39;m afraid</div>

<div><br></div><div>/Simon</div><div><br></div><div class=3D"gmail_quote">O=
n Mon, Apr 18, 2011 at 09:23, Dennis Shasha <span dir=3D"ltr">&lt;<a href=
=3D"mailto:shasha@courant.nyu.edu">shasha@courant.nyu.edu</a>&gt;</span> wr=
ote:<br>

<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex;"><br>
Dear Simon,<br>
In Jeff&#39;s book, he refers to a function you have written called<br>
zs:{`d`P`L`G`D!(system&quot;d&quot;),v[1 2 3],enlist last v:value x}<br>
<br>
How exactly do you use it?<br>
<br>
Does it work on kdb debugging?<br>
<br>
Do you have general advice on the debugging topic?<br>
<br>
Thanks,<br>
<font color=3D"#888888">Dennis<br>
</font></blockquote></div><br></div>

--20cf305b12c267fc3204a1306292--

