Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: Why are "push", "pop", "shift" and "unshift" so named?

by GrandFather (Sage)
on May 02, 2007 at 07:15 UTC ( #613130=note: print w/replies, xml ) Need Help??

in reply to Why are "push", "pop", "shift" and "unshift" so named?

The "cafeteria with spring-loaded trays" model is exactly right for stacks (LIFOs - Last in, First out) which are what push and pop apply to. And yes, you absolutely would both push and "pop" trays - push to add em in the first place,and pop to get one to use.

Perl extends the concept to include access to the "bottom" of the "stack" which allows a few more operational models. In particular the combination of push and shift (or unshift and pop) provide a queue (FIFO - First in, First out). Shift parallels an operation common in handling arguments in some OS batch/scripting languages. Unshift is a neat complement to shift for "putting back" an argument after taking a peek at it. At times there is an advantage to using a queue where you can add and remove elements to/from either end - can't think of an example right now in the software world, but it often happens in supermarket checkout queues!

Nomenclature adjusted for northern hemisphere usage. In the southern hemisphere stacks are the other way up. Queues can be either way and may be affected by the Coriolis effect.

DWIM is Perl's answer to Gödel
  • Comment on Re: Why are "push", "pop", "shift" and "unshift" so named?

Replies are listed 'Best First'.
Re^2: Why are "push", "pop", "shift" and "unshift" so named?
by graff (Chancellor) on May 02, 2007 at 23:11 UTC
    Nomenclature adjusted for northern hemisphere usage.

    For sure. I mean... if the world were flat, all the Australians would fall off!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://613130]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (9)
As of 2019-12-13 10:16 GMT
Find Nodes?
    Voting Booth?

    No recent polls found