[Jprogramming] Recursive verbs

Henry Rich henryhrich at gmail.com
Thu Nov 29 16:57:45 UTC 2018


Defining what $: refers to is hard to put into a definition, but I can 
tell you what the interpreter does.
During every execution of a verb there is a definition of what $: will 
mean if it is encountered. The value of $: is set (and the previous 
value pushed onto a stack) in 2 cases:
1. A name is executed. During the execution of the name, $: refers to 
the name
2. The parser executes a verb (as [x] v y). $: refers to the executed verb
In
2 +@:* 5
The parser executes only one verb: the anonymous compound +@:* . That's 
what $: would be during that execution.
Henry Rich
On 11/29/2018 11:49 AM, David Lambert wrote:
> 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
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm

---
This email has been checked for viruses by AVG.
https://www.avg.com


More information about the Programming mailing list

AltStyle によって変換されたページ (->オリジナル) /