A general version of approach 1 is to append any temporary results to original 
argument in boxed form.

G0 =: 0 {:: ]
G1 =: 1 {:: ]G2 =: 2 {:: ]

[:  (G2 V~ G1 U G0 )  [ ( [ (] (,<)~ W) G1) ] ,&< Q
Can be streamlined a bit with:

NB. keeps y argument, though ensures it is boxed, and appends result of u to 
(boxopen y)
K =: 1 : '(boxopen@]) (, <) u'

[:  (G2 V~ G1 U G0 ) [ (W G1)K Q K
    On Thursday, August 10, 2023 at 10:48:01 a.m. EDT, Raul Miller 
<rauldmil...@gmail.com> wrote:  
 
 1) yes, but it might not be a good idea. (You can form x and y into a
sequence which can be passed as a single argument, and then extract
arguments from that sequence.)

2) If Q is expensive to compute, I am aware of two other options:

(a) use a name to refer to its result (as you have done here), or

(b) use the memoize (M.) adverb (assuming Q's arguments are
sufficiently constrained).

You might also combine (a) and (b) by constructing your own
reinterpretation of the M. adverb if that suits your design.

--
Raul



On Thu, Aug 10, 2023 at 9:14 AM Marcin Żołek
<marcin.zo...@students.mimuw.edu.pl> wrote:
>
> Let U, V, W, P, Q be dyads and
>
> F =: dyad define
>    (tmp U y) V x W y P tmp =. x Q y
> )
>
> Tacit form of F, for example, is
>
> F =: (Q U ]) V [ W ] P Q
>
> but in this definition Q is repeated.
>
> 1. Is it possible to convert definition of F to tacit form without repeating 
> Q in definition?
> 2. Does the interpreter recognize repetition of Q and evaluate Q only once? 
> How to make the interpreter not evalute Q twice?
>
> Thanks,
> Martin
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
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