Sounds like you want a way to trace the execution of a verb. I have wanted something like that ever since I first played with J and looked in J for something like the []TRACE that was in STSC APL but couldn't find it.

Got to playing with it and came up with this:

vtrace=: 1 : 0
NB. c=.<'((1!:2)&2)'
c=.<'(((1!:2)&2)20#''_'')]((1!:2)&2)'
y
t=.u f.
'f t'=.(<@{.,<@}.)<;._1]LF,5!:5<'t'
f=.<'z=.(',(>f),') y'
0!:100] ;((0,-.t e.;:':)')#&.>c),.(f,t),.<LF
z
:
NB. c=.<'((1!:2)&2)'
c=.<'(((1!:2)&2)20#''_'')]((1!:2)&2)'
x
y
t=.u f.
'f t'=.(<@{.,<@}.)<;._1]LF,5!:5<'t'
f=.<'z=.x (',(>f),') y'
0!:100] ;((0,-.t e.;:':)')#&.>c),.(f,t),.<LF
z
)

p=: 3 : 0
'Monadic'
+y
:
'Dyadic'
x+y
)

  p vtrace 3j4
____________________
Monadic
____________________
3j_4
3j_4
  7+1 p vtrace 3j4
____________________
Dyadic
____________________
4j4
11j4

  t trace 1
____________________
0 1 2 3 4 5 6 7 8 9
____________________
45
____________________
450
450

"vtrace" stands for "verb trace" as the name "trace" is already defined and "vtrace" will only trace verbs. It works a little differently than what you asked for as it does return a value, the result of the verb, and I put in a separator between the displayed output so it is easier to see where each statement's output begins. And it's an adverb so it takes the verb to trace as a left argument. And you need to supply "y" and "x" to get it to do anything.

Notice "c" in "vtrace". Replace it with whatever you want to do with the output. Send it to a file if you want. If you have a verb in the middle of a statement you want to trace, simply stick "vtrace" just after it and the statement should still execute as before, except now each statement will be listed as defined in "c".

I don't know what to do for tracing adverbs and conjunctions.

June Kim wrote:

Thanks, but it wouldn't work when t includes (3 : 0) style multi-line
definitions.

2007/1/3, June Kim <[EMAIL PROTECTED]>:

Is there an easy way of achieving the following?

  t=: 0 : 0
i.10
]a=.+/ i.10
10*a
)
  r=:capturerun t   NB. capturerun runs the script capturing solely
the results without displaying
  r
0 1 2 3 4 5 6 7 8 9
45
450

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm




----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to