Skip to content

[Feature request]: Recursion scope adverb #203

@cchando

Description

@cchando

This would be backward compatible since no existing user code can contain R. (or whatever new adverb spelling/inflection is chosen), as it would've been a spelling error.

The following provides a motivation:

   ap  =: {{y`:6>x}}`{{y`:6&>/x}}@.(2=#@[)
   r   =: ($: 2&}.)`(ap 1&{)@.(ap {.)`ap@.(1=#@])
   Cond=: {{< :(,&<) r m"_}}

Here the recursive subexpression r is defined on its own line just because we don't want the < :(,&<) part of Cond to be part of the recursion; but r is not a very natural expression to separate from Cond and assign to a name.

Ideally this would be written inline using a recursion scoping adverb R.:

   ap  =: {{y`:6>x}}`{{y`:6&>/x}}@.(2=#@[)
   Cond=: {{< :(,&<) ($: 2&}.)`(ap 1&{)@.(ap {.)`ap@.(1=#@])R. m"_}}

where the scope of $: is limited to [the verb operand to the nearest adverb R.] which contains $:. The existing definition of $: holds if its no R. is present within the largest verb containing $: within the given sentence. R. can appear in multiple places within a verb, as in

   (… $: … ($: …)R. …)R.

As motivation, one of the benefits of J's terseness, and of tacit programming's absence of names, is the dispensation of the need to break up code into arbitrary (non-[conceptual/semantic]) pieces which will be used once only, and of the resulting need to create arbitrary names for these pieces. Anonymous recursion seems to be the only place where one is forced into doing so.

Z. would be my fallback naming suggestion since this adverb is like Z: in that each modifies the behavior of a particular primitive ($: and F(.:)(.:) respectively).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions