# recursive combinators in other languages

## Rahul — 2008-03-15 10:48:25

    I recently discovered that Nial (learning array languages because of

    this list :) ) recursive transformers were remarkably similar to the

    joy recursive combinators.

    The definition of factorial in Nial is given by

    factorial is recur [ 0 =, 1 first, pass, product, -1 +]

    the arguments to 'recur' are:

    test:checks that the argument meets an end condition,

    endf:is applied to the end argument before starting to build the

    result,

    parta:left value computed from the argument and stacked,

    joinf:combines the left and right values as the recursion unwinds, and

    partb:gives the value to be recurred on to produce the right value.

    Are there other languages that use the same form?

    Rahul

## Christopher Diggins — 2008-03-15 17:26:29

    > Are there other languages that use the same form?

     Well this isn't so much a language property, as a feature of the

    standard library. Some languages make it easy to define combinators of

    that form, but they aren't idiomatic (Haskell for example).

    - Christopher

     On Sat, Mar 15, 2008 at 6:48 AM, Rahul <blufox@...> wrote:

    > I recently discovered that Nial (learning array languages because of

    > this list :) ) recursive transformers were remarkably similar to the

    > joy recursive combinators.

    >

    > The definition of factorial in Nial is given by

    >

    > factorial is recur [ 0 =, 1 first, pass, product, -1 +]

    >

    > the arguments to 'recur' are:

    >

    > test:checks that the argument meets an end condition,

    > endf:is applied to the end argument before starting to build the

    > result,

    > parta:left value computed from the argument and stacked,

    > joinf:combines the left and right values as the recursion unwinds, and

    > partb:gives the value to be recurred on to produce the right value.

    >

    > Are there other languages that use the same form?

    >

    > Rahul

    >

    >

## rahul — 2008-03-16 08:15:24

    Christopher Diggins:

     >> Are there other languages that use the same form?

    >

    > Well this isn't so much a language property, as a feature of the

    > standard library. Some languages make it easy to define combinators of

    > that form, but they aren't idiomatic (Haskell for example).

     Well, it is certainly possible to achieve the same in any language that

    support lambdas, but none are as elegent as in Joy (AFAIK). I was

    surprised by the very consise definition and pervasive use of these

    in Nial. (Is it done the same way in K and J ?)

    see also Q5 in

    http://www.latrobe.edu.au/philosophy/phimvt/joy/faq1.html

    ...

     >> The definition of factorial in Nial is given by

    >>

    >> factorial is recur [ 0 =, 1 first, pass, product, -1 +]

## Stevan Apter — 2008-03-16 12:45:39

    ----- Original Message -----

    From: "rahul" <blufox@...>

    To: <concatenative@yahoogroups.com>

    Sent: Sunday, March 16, 2008 3:15 AM

    Subject: Re: [stack] recursive combinators in other languages

    > Christopher Diggins:

    >

    >>> Are there other languages that use the same form?

    >>

    >> Well this isn't so much a language property, as a feature of the

    >> standard library. Some languages make it easy to define combinators of

    >> that form, but they aren't idiomatic (Haskell for example).

    >

    > Well, it is certainly possible to achieve the same in any language that

    > support lambdas, but none are as elegent as in Joy (AFAIK). I was

    > surprised by the very consise definition and pervasive use of these

    > in Nial. (Is it done the same way in K and J ?)

    at one point i thought it might be useful to have a set of joy-style

    recursive combinators in k.  we have six iterators which cover most

    of the iteration cases encountered (e.g. */ for product, -': for

    pairwise difference, &c.), so the usefulness of a parallel set of

    "recursors" depends on how often nothing but recursion will do.  in

    many instances, an algorithm you'd normally define recursively has

    an iterative solution which can then be expressed with iterators, e.g.:

        fibonacci:(|+\)\1 1

    but it isn't difficult to define the recursors:

        rec:{[c;h;f;g;x]$[c x;h x;f[x;rec[c;h;f;g]g x]]}

        fac:rec[0=;{1};*/;-1+]

        fac 5

      120

    rec takes four arguments, each of which is a function, and a fifth

    argument, which is the data over which to recur.

    >

    > see also Q5 in

    > http://www.latrobe.edu.au/philosophy/phimvt/joy/faq1.html

    >

    >

    >

    >

    > ...

    >>> The definition of factorial in Nial is given by

    >>>

    >>> factorial is recur [ 0 =, 1 first, pass, product, -1 +]

    >

    > ------------------------------------

    >

    > Yahoo! Groups Links

    >

    >

    >