Guides/Language FAQ/TracePhrase

From J Wiki
Jump to navigation Jump to search

Why does trace produce an error?

I got the following error. Can someone please elucidate?

   load 'trace'
   trace 'sp1 10'
--------------- 0 Monad ------
sp1
10
value error: sp1
|   t_z=.    (sp1)(10)

Trace currently does not support names which are unqualified by locale. (Update: trace now supports unqualified names defined in the base locale, though this issue can still arise, for example if trace is being run from some other locale.)

Ideally, trace should determine the locale of the caller and use that. Or, since that may not be possible, it should assume the locale 'base' and use that. However, since it currently does not do so, you need to either not use names, or qualifiy them properly.

These should work:

  sp1 =: (#~ 2 = #@q:) @ }. @ i.
  trace '(#~ 2 = #@q:) @ }. @ i. 10'
  trace 'sp1_base_ 10'

Finally, note that trace just shows the stages of parsing. It does not show you how derived verbs work. For that, you need to perform experiments with related verbs or use the dissect addon. For example:

  (#~ 2 = #@q:) @ }. @ i. 10
4 6 9
  (;~ 2 = #@q:) @ }. @ i. 10
+-----------------+-----------------+
|0 0 0 1 0 1 0 0 1|1 2 3 4 5 6 7 8 9|
+-----------------+-----------------+
  (;~ #@q:) @ }. @ i. 10
+-----------------+-----------------+
|0 1 1 2 1 2 1 3 2|1 2 3 4 5 6 7 8 9|
+-----------------+-----------------+

Contributed by @BrianSchott@ from a post by RaulMiller