Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Etymology of chomp?

by tankee (Novice)
on Feb 26, 2012 at 10:29 UTC ( #956244=perlquestion: print w/ replies, xml ) Need Help??
tankee has asked for the wisdom of the Perl Monks concerning the following question:

Hi! I'm not a native speaker of English, and am wondering why the 'chomp' function was termed so. Is there any more reason than that it sounds and looks like 'chop'? I understand that 'chomp' means to chew noisily (according to dictionaries), but am not sure about what that word sense has to do with the 'chomp' function.

Could anyone kindly point out to me why the name 'chomp' was chosen, or the image of the name as it is used to denote a Perl function?

Thank you very much in advance.

Postscript: Thanks a lot for the opinions and suggestions. The real etymology seems to be unclear, but I think I have a much better grasp of the term now.

Replies are listed 'Best First'.
Re: Etymology of chomp?
by ww (Bishop) on Feb 26, 2012 at 12:36 UTC
    "'chomp' means to chew noisily (according to dictionaries)"

    While 'chew noisily' is one meaning that's still in common use, another is something on the order of 'bite down hard.' Chomp is often uttered with the intent to evoke the action of very large teeth seizing or biting off part of some target entity... such as a piece of steak or -- in a figurative sense -- a target's posterior, in the course of excoriating the target's failure to perform to some standard. From there, it's not to hard (for me, YMMV) to associate the name with removal of a trailing (and often 'useless' or'un-acceptable') newline.

    And re eyepopslikeamosquito's comment on "(c)arp module function names: carp, croak, confess and cluck":

    • 'Carp's utility seems to me to match the standard definition of the name itself -- to complain about something, sometimes in a petty manner.
    • 'croak' can be used as slang for 'die.'
    • 'confess' seems self-evident (but maybe my mind has been twisted by too much etymology).
    • 'cluck' -- an onomatopoetic word for the sound of a contented hen -- is also, at least in NE US-ian slang -- used to mean 'remonstrate' (and often used in the context of a sexist, age-ist remark involving an elderly female -- 'old hen' in the same slang).

    Now, were any of the above even considered in naming the Perl functions? I can't say, but the associations seem suggestive.

Re: Etymology of chomp?
by eyepopslikeamosquito (Chancellor) on Feb 26, 2012 at 11:59 UTC

    I expect many native English speakers would get a chuckle out of "chomp". At least, I find it mildly amusing. The other day I found an experienced Java/C# programmer, who is currently learning Perl, rolling on the floor laughing at the Carp module function names: carp, croak, confess and cluck. He loved these names, finding them hilarious, perhaps because you would never see such names in more serious "politically correct" "corporate" languages like Java and C#. Good luck with the etymology of those four. :)

    You may need to ask Larry (I tried googling just now without luck), but my guess is that some of the early names were chosen simply because Larry found them amusing. Remember, these names were chosen by the guy who wrote Black Perl in 1990. It was a different era back then and perhaps these amusing early names are just a reflection of those times. I doubt they would be chosen today because I've noticed that Larry has recently been outvoted (or changed his mind) on a number of "amusing" or at least "cute" names. For example, the Perl 5 porters objected to "err" and in Perl 6 land "comb" (to "comb" the words out of a string, get it?) was later changed to the less amusing and less evocative "words".

      I think 'carp' came into existence after a misspelling. Someone switched two letters when typing what he intended to type, and 'carp' was born.

      It's now on the Internet, so it must be true!

Re: Etymology of chomp?
by davido (Archbishop) on Feb 26, 2012 at 14:12 UTC

    You can chop just about anything with form, but you would be more selective about what you're willing to chomp on. Chop up dog poop, as a macerator does for example, but nobody will chomp on it. It seems fitting that chomp will only consume its preferred diet as specified by $/.


Re: Etymology of chomp?
by Anonymous Monk on Feb 26, 2012 at 10:40 UTC

    In a linux terminal, in a far away decade, ye olde larry cat some dos.txt before he dos2unix, so he saw some ^M at the end of line, and larry thought , it is common to need to chop these, but chop already chops , eurkea! chomp

      To be clear.

      Programing Perl describes chomp as "This function (normally) deletes a trailing newline from the end of a string contained in a variable. This is a slightly safer version of chop"

      chop itself is "This function chops off the last character of a string variable and returns the character chopped."

      IOW, chop does what it means, it chops off the end. chomp is a very similar one, that only (before version 5.6) chops off ^M

        Actually, chomp, by default, removes a newline. Which is actually ^J, not ^M. ^M is a carriage return, and will be left alone by chomp (unless $/ is set to something that contains it).

      I know Larry visits Australia from time to time, and he probably ate what is possibly the best flavour to dollar ratio chocolate bar in the world, the Cadbury Chomp.


      I assume he named the chomp operator in honour.

      chomp removes newlines. Which, if $/ isn't set, is ^J, not ^M, which will be left alone by chomp.

        Are you making fun of me?

Re: Etymology of chomp?
by JavaFan (Canon) on Feb 26, 2012 at 13:42 UTC
    I'd be surprised if chomp was named as it is, without consideration of chop. The functions act similar, and the names look similar. chop is older, but in a lot of places, where chop was used, chomp would be better. The change is minimal, add just one character. It does not surprise me if Larry did consider that fact when looking for a name for the function. And I'd bet Larry has looked for a similar, 4 character word as a replacement, but didn't find a better one.
      I'm betting it was for ease in editing. It's easy to s/chop/chomp/; and even easier to just insert one character.
        That's what I said, didn't I?
Re: Etymology of chomp?
by tangent (Priest) on Feb 26, 2012 at 17:06 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://956244]
Approved by Eliya
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2016-07-01 00:17 GMT
Find Nodes?
    Voting Booth?
    My preferred method of making French fries (chips) is in a ...

    Results (405 votes). Check out past polls.