# "fold" vs. "properfold"

## John Cowan — 2001-05-02 13:48:00

    There is a semantic distinction between "fold" as implemented by

    me and "properfold == [swap] dip step", when the aggregate argument

    is of size 1.  My version of "fold" just pushes the single member,

    whereas "properfold" executes the quotation using the single member

    and the base value.  Thus:

    [1] 2 [+] properfold == 3

    but

    [1] 2 [+] fold == 1

    Which is the more appropriate semantics?  If we think of the second

    argument as the base value for an induction, then "fold" seems like

    the right thing; whereas if we think of it as the identity for

    dyadic function captured in the quotation, then "properfold" seems

    like the right thing, since it makes no sense to employ a dyadic

    function on a single argument.

    --

    There is / one art             || John Cowan <jcowan@...>

    no more / no less              || http://www.reutershealth.com

    to do / all things             || http://www.ccil.org/~cowan

    with art- / lessness           \\ -- Piet Hein

## Manfred von Thun — 2001-05-03 07:53:28

    On Wed, 2 May 2001, John Cowan wrote:

     > There is a semantic distinction between "fold" as implemented by

    > me and "properfold == [swap] dip step", when the aggregate argument

    > is of size 1.  My version of "fold" just pushes the single member,

    > whereas "properfold" executes the quotation using the single member

    > and the base value.  Thus:

    >

    > [1] 2 [+] properfold == 3

    >

    > but

    >

    > [1] 2 [+] fold == 1

    >

    > Which is the more appropriate semantics?  If we think of the second

    > argument as the base value for an induction, then "fold" seems like

    > the right thing;

     The reason for having what in your example is 2 is this:

    The fold combinator doesn't/cannot know what the identity element

    for the binary operator in [+] is. At least for more complicated

    [...] that would be so. Thus fold needs to be told:

       sumlist      ==  0  [+]      fold

       productlist  ==  1  [*]      fold

       stringlist   ==  "" [concat] fold

       listlist     ==  [] [concat] fold

       weirdo       ==  ?  [......] fold

    But there is no need to always start with the identity element,

    Hence your

       [1] 2 [+] fold            should ==>  3

     > whereas if we think of it as the identity for

    > dyadic function captured in the quotation, then "properfold" seems

    > like the right thing, since it makes no sense to employ a dyadic

    > function on a single argument.

    >

     That is exactly right. I think the change to your fold in C will be

    quite easy to do.

      - Manfred

## John Cowan — 2001-05-03 15:35:24

    Manfred von Thun wrote:

     > That is exactly right. I think the change to your fold in C will be

    > quite easy to do.

     I tried to develop a unified "step" and "fold", but instead made

    "fold" fix the stack and invoke "step".  A side effect is that "fold"

    now works on strings and sets, whereas my previous implementation

    worked on lists only.

    I have also added support for making Joy scripts executable on

    Unix-like systems.  You can say "joy scriptfile" and it will

    execute it and quit; if the first line begins with "#", it is

    ignored.  This means that "chmod +x foo", where foo is a file

    beginning "#!/usr/local/bin/joy" (or wherever) will make

    foo executable directly.

    --

    There is / one art             || John Cowan <jcowan@...>

    no more / no less              || http://www.reutershealth.com

    to do / all things             || http://www.ccil.org/~cowan

    with art- / lessness           \\ -- Piet Hein

## Manfred von Thun — 2001-05-08 01:51:07

    On Thu, 3 May 2001, John Cowan wrote:

     > Manfred von Thun wrote:

    >

    >

    > > That is exactly right. I think the change to your fold in C will be

    > > quite easy to do.

    >

    > I tried to develop a unified "step" and "fold", but instead made

    > "fold" fix the stack and invoke "step".

     Yes, thatis one way.

     >                                         A side effect is that "fold"

    > now works on strings and sets, whereas my previous implementation

    > worked on lists only.

     That is right, and that is how it should be, too.

     > I have also added support for making Joy scripts executable on

    > Unix-like systems.  You can say "joy scriptfile" and it will

    > execute it and quit; if the first line begins with "#", it is

    > ignored.  This means that "chmod +x foo", where foo is a file

    > beginning "#!/usr/local/bin/joy" (or wherever) will make

    > foo executable directly.

     Great, thanks. I'm glad it could be done; I had hoped that

    Joy syntax would not interfere with devices such as that.

      - Manfred