[Jprogramming] Recursive verbs
David Lambert
b49p23tivg at gmail.com
Thu Nov 29 16:49:43 UTC 2018
Wonderful example. I might be able to explain to someone else!
On 11/29/18 7:00 AM, programming-request at forums.jsoftware.com wrote:
> Date: 2018年11月28日 17:17:24 -0500
> From: Jose Mario Quintana<jose.mario.quintana at gmail.com>
> To:programming at jsoftware.com
> Subject: Re: [Jprogramming] Recursive verbs
> Message-ID:
> <CABtFPKu4bFwxO7k3g8vZJ7m_fitPmWC2euh+RJL=YSM07mGxPQ at mail.gmail.com>
> Content-Type: text/plain; charset="UTF-8"
>> David, the trick is to keep in mind: "$: denotes the longest verb that
> contains it." This is important because J does not provide a primitive for
> the scope of $: (although one can write a wicked tacit adverb to set the
> scope directly to keep everything tacit).
>> This is what I think is happening,
>> f =: complete`f_odd`f_even at .agenda
> 5 f 4
> |stack error: f_even
> | 5 f 4
>> Why? Because
>> 5 agenda 4
> 2
>> and
>> 5 f_even 4
> |stack error: f_even
> | 5 f_even 4
>> Why? Because "the longest verb that contains it." is
>> f_even
> $: (, (_1 2 p. {:))
>> thus,
>> 2 ($: (, (_1 2 p. {:))) 4
> |stack error
> | 2 ($:(,(_1 2 p.{:)))4
>> A similar reasoning applies to,
>> 5 (complete`f_odd`f_even at .agenda f.) 4
> |stack error
> | x $:(,(_1 2 p.{:))y
>> Why does the interpreter produce,
>> complete`f_odd`f_even at .agenda f.
> ]`(3 : '$: (, (1 2 p. {:)) y' :(4 : 'x $: (, (1 2 p. {:)) y'))`(3 : '$: (,
> (_1 2 p. {:)) y' :(4 : 'x $: (, (_1 2 p. {:)) y'))@.((> * [: >: 2&|) #)
>> ? A simple example can illustrate the rationale. Assume that given the
> recursive factorial verb,
>> fac=. 1:`(* $:@:<:)@.*
>> one wants to produce a verb which calculates the factorial plus one.
> Naturally,
>> facplusone=. 1 + fac
> facplusone 5
> 121
> facplusone f. 5
> 121
> facplusone f.
> 1 + 3 : '1:`(* $:@:<:)@.* y' :(4 : 'x 1:`(* $:@:<:)@.* y')
>> (i.e., the interpreter is using an explicit envelope to force a natural
> scope)
>> whereas,
>> facplusone=. 1 + fac f.
> facplusone 5
> 446
>>> gives the wrong answer (in this case).
>> I hope it helps
More information about the Programming
mailing list