I wrote:
> That said, the interpreter does take special steps to allow for
> cap to have aliases, as in cap=:[:
Raul responded
> Yes.
Actually, I did find one use for this special-casing. We can combine it
with J's built-in performance monitoring tools, to compare how many times
the left tine of capped fork is invoked (vs an uncapped fork):
NB. Define a (uncapped) fork
f =: left middle right
left =: +/
middle =: %
right =: #
NB. Collect stats on how many times each name is called
1 (6!:10) 1e5$'x'
(6!:12) 1
f i. 10
(6!:12) _1
FORK =: 6!:11 ''
NB. Now cap the fork (using an alias for [:)
left =: [:
NB. Collect the same statistics for the capped fork
1 (6!:10) 1e5$'x'
(6!:12) 1
f i. 10
(6!:12) _1
CFORK =: 6!:11 ''
NB. Now compare the two
report =: format@:compare
format =: >@:((,. ' '&,.)&.>/)@:(<@:>"1)
compare =: (a:,;:' FORK CFORK') , count
count =: ((] ,. [: |: <@":@<:@:#/.~@:,~S:1)
/:~@:~.@:;)@:calls
calls =: ,&([: {&.>/ 0 6&{)
FORK report CFORK
f left middle right
FORK 2 2 2 2
CFORK 2 0 2 2
Study the last line, here.
Note the left tine of the capped fork was called literally zero times.
Meaning its definition is not used. Meaning (when not used to cap a fork)
it is arbitrary. Meaning it could be anything. Meaning its domain doesn't
have to be empty.
That it is, is just a nicety.
> Except that capped forks can include uncapped forks
> and this approach would change the interpretation
> of uncapped forks.
Exactly - which is why I don't use [: outside of capped forks.
-Dan
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm