pyret-lang icon indicating copy to clipboard operation
pyret-lang copied to clipboard

Better aliases for foldl and foldr?

Open justinpombrio opened this issue 11 years ago • 10 comments

In the lists module, there are .foldl and .foldr methods, but no foldl and foldr functions. These should be defined.

justinpombrio avatar Oct 20 '14 20:10 justinpombrio

And they probably should be called fold-left and fold-right, to avoid unnecessarily making things sound cryptic. That goes for the method names, too.

It might be better to call them fold-forward and fold-backward, given how hard it is to remember which is which by the name.

jpolitz avatar Oct 20 '14 20:10 jpolitz

Or perhaps "fold" and "fold-backward", then, just to make the one most likely to be used shorter?

Stevie

On Oct 20, 2014, at 4:35 PM, Joe Politz [email protected] wrote:

And they probably should be called fold-left and fold-right, to avoid unnecessarily making things sound cryptic. That goes for the method names, too.

It might be better to call them fold-forward and fold-backward, given how hard it is to remember which is which by the name.

— Reply to this email directly or view it on GitHub https://github.com/brownplt/pyret-lang/issues/353#issuecomment-59835240.

sstrickl avatar Oct 20 '14 20:10 sstrickl

Nice, I like that.

Is there any better word than fold to use here? That's the last remaining piece of jargon in the name.

jpolitz avatar Oct 20 '14 20:10 jpolitz

Some languages use "reduce", but I don't like that. "combine"? "mix"? I'm not sure if I can come up with a verb that's clearly descriptive of the process yet not jargony here, though.

Stevie

On Oct 20, 2014, at 4:48 PM, Joe Politz [email protected] wrote:

Nice, I like that.

Is there any better word than fold to use here? That's the last remaining piece of jargon in the name.

— Reply to this email directly or view it on GitHub https://github.com/brownplt/pyret-lang/issues/353#issuecomment-59837234.

sstrickl avatar Oct 20 '14 21:10 sstrickl

I don't think fold is too jargon-y, since it's not a made-up word and I always have the mental picture of folding up a list as a long strip of paper, one item at a time...

Plus, I think list.fold is indeed currently defined :-)

blerner avatar Oct 20 '14 21:10 blerner

Yeah, agreed. I think of it as folding in baking (which is why combine and mix came to mind for me if we wanted a replacement).

On Oct 20, 2014, at 5:11 PM, Ben Lerner [email protected] wrote:

I don't think fold is too jargon-y, since it's not a made-up word and I always have the mental picture of folding up a list as a long strip of paper, one item at a time...

Plus, I think list.fold is indeed currently defined :-) 
Reply to this email directly or view it on GitHub.

sstrickl avatar Oct 20 '14 21:10 sstrickl

Agreed. Also, people are going to expect to find fold. So Stevie's suggestion is best. May be good to alias foldl and foldr due to convention.

On Mon, Oct 20, 2014 at 5:28 PM, Stevie Strickland <[email protected]

wrote:

Yeah, agreed. I think of it as folding in baking (which is why combine and mix came to mind for me if we wanted a replacement).

On Oct 20, 2014, at 5:11 PM, Ben Lerner [email protected] wrote:

I don't think fold is too jargon-y, since it's not a made-up word and I always have the mental picture of folding up a list as a long strip of paper, one item at a time...

Plus, I think list.fold is indeed currently defined :-)
Reply to this email directly or view it on GitHub.

— Reply to this email directly or view it on GitHub https://github.com/brownplt/pyret-lang/issues/353#issuecomment-59842736.

shriram avatar Oct 21 '14 04:10 shriram

After lecturing on fold today, I realized that fold-backward might be kinda confusing, since (assuming we mean fold-right by fold-backward) it is the one that keeps the list in order if you use it with link. As in, I'm about to give out a programming assignment where the answer to "which one keeps the list in the same order" will be fold-backward. But fold-left demonstrably goes forward if you just print the elements in the combining function and watch the effects. Mmph.

Are left/right actually better, since one operation's "backward" is another's "forward"?

jpolitz avatar Jan 26 '15 21:01 jpolitz

Is this issue staying open because of the unresolved "better alias name" question? If so, can we change the title? And if not, can we close?

schanzer avatar Jun 09 '17 21:06 schanzer

I'm changing the title, since the original title is pretty confusing.

schanzer avatar Aug 12 '20 18:08 schanzer