I don't think we are saying the same thing.  My extra evaluation is your
+1,  and it only occurs for boxed arguments.  Sorry for any confusion.

Here is a minimal demonstration.

f=:3 : 0
smoutput 'f ';":y
>:y
)
g=:3 : 0
smoutput 'g ';":y
>:&.>y
)

   f^:(2 3) 1 2
+--+---+
|f |1 2|
+--+---+
+--+---+
|f |2 3|
+--+---+
+--+---+
|f |3 4|
+--+---+
3 4
4 5
   g^:(2 3) 1 2
+--+---+
|g |1 2|
+--+---+
+--+---+
|g |1 2|
+--+---+
+--+-----+
|g |+-+-+|
|  ||2|3||
|  |+-+-+|
+--+-----+
+--+-----+
|g |+-+-+|
|  ||3|4||
|  |+-+-+|
+--+-----+
+-+-+
|3|4|
+-+-+
|4|5|
+-+-+

Note also:

   g^:(1) 1;2
+--+-----+
|g |+-+-+|
|  ||1|2||
|  |+-+-+|
+--+-----+
+-+-+
|2|3|
+-+-+
   g^:(,1) 1;2
+--+-----+
|g |+-+-+|
|  ||1|2||
|  |+-+-+|
+--+-----+
+--+-----+
|g |+-+-+|
|  ||1|2||
|  |+-+-+|
+--+-----+
+-+-+
|2|3|
+-+-+

So if y is boxed and n is a list, u^:n y will be executed >:>./ n times,
one more than if y is unboxed.  This is also true in J504.

If u has no side effects, this will not give wrong results, but something
strange is going on.

Best wishes,

John





Fraser Jackson wrote:
> John Randall wrote:
>
>
>>> (a) There is a mysterious extra evaluation.
>>>
>>> (b) For f^:(n0 n1 n2 n3 ....nn) y, f gets evaluated an additional
>>> number
>>> of times equal to the maximum of n0,...,nn, regardless of the side
>>> effects.
>>>
>>> I think ^: is really designed for pure functions.
>
> Fraser Jackson commented:
>
>> (b) does not accord with my experiments.  I always get f evaluated
>> (1+>./n0,n1,n2,.,nn) times when the number of increments to INFO_base_
>> differs from the value of the power.
>
> On re reading what John wrote it can be interpreted to give the same total
> number of evaluations as in the expression above.  f clearly has to be
> evaluated  maximum of n0,...,nn times, but it is somewhat confusing to
> refer
> to them as an additional number of times.  Alas communicating clearly is
> seldom easy.
>
> Fraser
>
>

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

Reply via email to