Friday, December 19, 2008

A small peeve

Whenever I write a function with an external wrapper and an internal recursive function (say, to add an accumulator), I can never come up with a name for the internal function that I find satisfying. This is totally picking nits, but it bugs me for all the recursive calls to be to foo/aux or foo/helper or something like that. Come to think of it, somehow the prime symbol in Haskell and ML feels more natural.


jpc said...

OTOH efficient implementation of optional parameters (I don't know how efficient mzscheme is) should allow you to use one name for both versions (and even allow different accumulator seeds when needed)

Dave Herman said...

An optional argument isn't always the right solution. In one case I have a function that needs to transform its argument in a particular way only once at the beginning; an extra boolean flag indicating whether this had been done yet would be overkill.

Robert Fisher said...

I usually use underscore as the name for these functions.

Anonymous said...

I like using gerunds for this. Like the internal loop for the 'mung' function is 'munging'.

Dan Villiom Podlaski Christiansen said...

I generally use ‘visit’ for that purpose; it's nice and functional, and clearly conveys the intent of the function. To me, it seems as natural as naming an accumulator ‘acc’ and a continuation ‘c’; I wouldn't use the names for anything else.

Mitch Wand said...

Dan usually writes foo^ as the nearest Scheme equivalent to foo' .

I've also used foo-loop or foo-inner.

Interesting how the smallest things get the most comments :-)

grant rettke said...

If you think of those internals as private, foo/private makes sense.

If you are using PLT's module system, then name the public functions foo/public and rename them on export. You can keep your code looking how you want privately and publicly.

Mike Machenry said...

Oh I relate to this a lot. The same issue also often exists with the argument to the external and internal function.

I've gone through a lot of phases in my life. Currently I've been doing _foo. It used to be just aux, before that: foo-aux, and others. I could never settle.

Actually I very often just write let-loop to avoid the naming issue. Then there was the most misguided of all, utilizing the fact that internal definitions shadow the external function.


Andrey Fedorov said...

The Seasoned Schemer uses upper-case one-letter names, which helps remind you that the function is very local.

This seemed weird at first, but seems to be working out.

Norton Setup said...

Thanks for Sharing. I am glad to know that I follow your blogs. it was very interesting. keep posting!

Install Norton Antivirus in your PC's and mobile to protect your systems from viruses.

norton setup with key
enter norton product key code to activate
Norton setup
norton setup enter product key