I wrote:
>  Model what, specifically?

Raul responded:
>   Optimizing tail calls.
>
>   Try it this way:  How would you (mechanically) describe J
>   sentences which are valid targets of TCO?  

Ah, now I understand.  I mistakenly thought you were diverting the topic from 
TCO.

>  I have not seen any such model implementations in J.

I was more or less taking you and Roger at your words, that these situations 
are easy to identify and rewrite using  ^:  .  Of
course, you were both speaking in the context of a human optimizer, but the 
implication was that the resolution was so obvious as to
be mechanical (hence, mechanizable, or so I inferred).

Yourself in [1]:
>  It seems to me that ^: already lets us deal adequately
>  with the easily [TC] optimizable cases?

And Roger, a bit more concretely, in [2]
>  In other words, "tail recursion" is in the form   basis ` ($: @: g) @. test  
>  
>  If you can get it into this form, you may as well write it non-recursively
>  yourself:    basis @: (g^:test^:_)

Aside from these, I have no more than an intuition that identifying a RTC is 
possible for a useful proportion of cases.  That
intuition stems from two observations:

   (A)  Other languages identify and optimize a useful proportion of RTCs.
   (B)  J (tacit J at least) is often subject to algebraic manipulation, often 
by automatic tools.

>From (B), I infer that the case of identifying a RTC reduces to the case of 
>identifying the set of verbs that could produce that
result of a given tacit verb, and noting if  $:  is among them.  My first 
instinct is that that isn't so hard.  In broad strokes,
given a fork, I would produce the middle tine, for a hook, the left tine, for a 
list of explicitly-composed verbs (a pipeline),
produce the leftmost*.  Of course, you'd have to  have some special cases for 
e.g.  @.  where you would produce the entire LHA, and
for  ^: where you'd produce the LHA and the verb to the right.  But we are not 
aspiring to identify every RTC, just a useful
proportion.

>  phase 2: how would you implement this mechanism 
>  in J, given the atomic representations of the sentences 
>  in question.

I don't know, how do other functional languages do it?  A while loop and a 
stack?

-Dan

[1]  http://www.jsoftware.com/pipermail/programming/2009-December/017355.html 
[2]  http://www.jsoftware.com/pipermail/general/2003-August/015571.html 

*  ironically, it would be natural to write this utility recursively.


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

Reply via email to