Comments on: POP goes the series

Carl Sassenrath, CTO
REBOL Technologies
31-Aug-2006 18:32 GMT

Article #0041
Main page || Index || Prior Article [0040] || Next Article [0042] || 23 Comments || Send feedback

There is a common REBOL idiom when series are used for queues and stacks:

pop: func [series /local val]
    val: first series
    remove series

Note that it works for any position within the series (you can pop from head, tail, or inbetween).

This common expression should be added as an internal action (high performance). Implementation is trivial (and it may even be possible to back-port it to REBOL 2).

Is the pop name the best choice?

Also, it may be good to extend it with /part allowing extraction of a range of series elements.

We've talked about this informally before. The discussion is now "formal", so what do you think?



31-Aug-2006 15:08:59
I have no problem with word POP and /part refinement will be nice. Just some newcommers may be searching for PUSH if they will see POP.
Carl Sassenrath
31-Aug-2006 15:12:36
Yes, I considered that (beginners looking for PUSH). The dictionary will need to link from POP to INSERT (as equiv to PUSH).
31-Aug-2006 15:14:43
I was going to write that, but was unsure whether this rule applies to REBOL.

We have SAVE/LOAD, READ/WRITE, HEAD/TAIL but then we have INSERT/REMOVE, which would be ADD/REMOVE and INSERT/DELETE if correctly complemented, not taking into account for the meaning of the words.

If there is no formal adherence to such a rule, then I have no problem with POP.

31-Aug-2006 15:39:39
How about PULL instead ?

Also, lots of people have implemented stacks with POP already, or are using POP for mailboxes .. and this will break their code.

Carl Sassenrath
31-Aug-2006 15:57:16
Henrik: I understand what you are saying, but I do not agree with those complement names. The complement of ADD is SUBTRACT. The complement of DELETE is CREATE. So INSERT/REMOVE is correct.

Also, purity of naming does not assume only complemented name pairs. (For example, what is the complement of CLEAR?) It is always possible for there to be both holes and overlap in function definitions, due to the characteristics of the datatype.

In that regard, POP takes a series and returns a value. It is not like REMOVE that takes a series and returns a series.

Graham: yes, that is a concern. The word POP is heavily used already for such things. What do other's think of PULL?

31-Aug-2006 16:02:39
PULL is good if it won't be confused with EXTRACT by beginners. :-)
31-Aug-2006 16:19:33
And what about pick and poke? Pop and push seems to be good counterparts to them imo. Maybe like Graham suggest, pull instead of pop? I have few scripts where I use pop in regards to pop3 scheme, but I can easily change it in those scripts ...
31-Aug-2006 16:33:02
I would vote for POP. I don't have any script using naming POP and don't remember I used some which would. If there is a script using POP in a stack, I would say it would have same meaning as the POP which Carl wants to add. And if I have script where it will be an issue, it's not so difficult to find-and-replace to correct such a script for use in R3
Carl Sassenrath
31-Aug-2006 17:04:56
Also, I should point out that if you redefine the POP word, that is ok in R3.0. The redefinition only applies to your local module context (your script). The rest of the system is not affected by that change.

(I will post a separate note on how you change system definitions, as I'm sure you are now curious about that difference.)

31-Aug-2006 17:09:02
pop: func [series /local val]
    val: first series
    remove series
pull: func [series /local val]
    val: last series
    remove back tail series
push: func [series val]
    insert series val
31-Aug-2006 19:12:50
I am unhappy with pop, because pop should work on the tail IMHO. Then with append/last/pop native we have a nice and efficient stack. (I like 'last as top of stack, the last thing i put there).

But then what name? i like pull. technically it could be dequeue? Or pop/at, tail is default?

Gregg Irwin
31-Aug-2006 19:35:30
I call it PULL myself, and mine has a /part refinement, which can be very handy.

I would vote *not* to use POP, because the expected behavior for people coming from other languages would be that it operates against the head or tail of the series, not the current position. PULL, or some other name, makes it more obvious that it's different.

I also have a dialected EXCERPT function, that let's you specify which "columns" you want returned. e.g.

excerpt/only block [to 2   4 to 6   8   10   12 to end]
It doesn't remove the items, so it's more like a dialected EXTRACT.
Carl Sassenrath
31-Aug-2006 21:11:12
The nice feature of POP is that it can be used at either end of the series, or inbetween.

Perhaps the POP isn't the best word for this kind of copy and remove idiom. Would MOVE be a more precise word?

Note: Stacks work best with APPEND and POP at TAIL. Queues in 3.0 work fine either way (remove/insert are optimized at head index now).

PS: This discussion relates only to low-level native speed operations. Certainly you can build variations on top of such a native.

1-Sep-2006 0:12:43
I don't like POP.

1. It implies that PUSH and TOP are available as well 2. It implies we are talking about a Stack structure

How about SLICE?

Maxim Olivier-Adlhoch
1-Sep-2006 0:46:25
I vote for PULL.

2 reasons:

  • Just like Robert points out, people will expect PUSH and TOP .

  • Because REBOL is a messaging language, I think more people will assume POP as being a mail related function.
1-Sep-2006 2:27:25
If insert at head is as fast as at end, i vote for pop. A stack is then insert/first/pop, and "push: :insert top: :first" solves Roberts problem. About building variations, 'pop is a "valuable" word, i would not waste it for something low-level which is hidden most of the time. But as i said, if stacks at head are fast, its a good choice.

Will it allow none, as remove does? Maybe "if pop find series value[..]" is usefull?

Gregg Irwin
1-Sep-2006 3:46:19
I wouldn't use MOVE. To me, MOVE implies changing the location of items in a series, not removing them (though the assocation of MOVE with *RE*MOVE is something you may have thought of).

Save MOVE for something like this:

MOVE dialect ( is an offset, and denote a range)

move block [ 3]
move block [ back 3]
move block [ to head | to tail | to ]
move block [ to  back ]
move block [ to  forward ]
move block [ to  to ]
Gregg Irwin
1-Sep-2006 3:50
Garrrhhhhh! The tag stripper strikes again. Too quick on the preview/post click.

MOVE dialect (x is an index/offset, m and n denote a range) 
move block [x 3]
move block [x back 3]
move block [x to head | to tail | to x]
move block [m to n back x]
move block [m to n forward x]
move block [m to n to x]
Carl Sassenrath
1-Sep-2006 14:01:40
Changing locations does require a remove. That is, MOVE: copy, remove, then "insert".

Of course, in those terms, MOVE "feels" like it should take two series as arguments. So, it's probably not a good name.

I'm currently leaning toward PULL.

Isn't naming fun!?

Pierre Johnson
2-Sep-2006 2:59:16
Carl says: "Henrik ... I do not agree with those complement names. The complement of ADD is SUBTRACT. The complement of DELETE is CREATE. So INSERT/REMOVE is correct. "

Look at any QWERTY keyboard for all-time (not just yesterday, but for as long as keyboard-based computing has existed) and the complement pair is INSERT:DELETE not any of the attribution errors mentioned in this thread by all others.

Carl continues, "...POP takes a series and returns a value."

The key words are 'take' and 'return'. Words that label such either part or all such concepts (take and return) are 1) provide 2) grab 3) give 4) handover 5)swipe 6) toss 7)give-back 8) get-back

Using POP is a horrible idea. The connotation for all-time related to High Priests of Academia and Computer Science are far too embedded to be moveable.

Once again, the so-called, self-proclaimed "rebel" clings so desperately on convention, speedily trying to make REBOL an also-ran, computer jargon oriented product.

What? Use words consistently like "everyday English"? Ah, the idea is so simple, no "rebel" can conceive of it.

After all, English is the true Esperanto of the globalization era world.

But go ahead, make yet another mistake with REBOL. The race to kill the product is on and seems to be the desire of every person connected with decision-making.

Gregg Irwin
2-Sep-2006 11:49:27
Another name I've used for this function in the past (just found a reference to it), is TAKE.
Anton Rolls
9-Sep-2006 4:16:35
I think I would be happy with the first POP proposal. Additionally, I would like PUSH with the same functionality as INSERT, just because it's a shorter word. Actually, if a shorter word could also be found for APPEND too, that would be cool.
Gregg Irwin
9-Sep-2006 12:22:18
I started out with PUSH and POP, like most programmer's would; then I changed to PULL--probably due to the effect of thinking more like REBOL. TAKE is the latest name I'm trying, though I've used PULL for quiet a while.

TAKE makes sense in that it's short and meaningful to non-programmers. To me, that's an important aspect, because it makes it more like pseudo-code, which is handy for programmers.

So, what are the downsides to TAKE? How else will we use it?

Let's also consider that push/pop are nearly always used for stacks; queue's usually use different method names. Eiffel's designer believes that a consistent (Linnaean) naming convention is best, so both stacks and queues use ADD and REMOVE. But we have to look at things in the context of REBOL.

We don't have stack and queue structures and, if we did, would the meaning of FIRST and LAST be different for them? They would, wouldn't they? And what is the mental picture you get when you visualize how things work? The common description for a stack, is a stack of dishes; for a queue, it may be a line of people; what should it be when it can do either?

For a block, I picture a line of items, with a spring pushing against the last item (the tail; on the right). When you take an item, any items that come after it are "pushed over" by the spring, so there is no empty space. For a list, I see items with hook-and-eye connectors; when you take an item, you have to unhook the items after it, unhook it, and "re-attach" the tail to the head. You don't think like that all the time though, only when you're learning, or when things go wrong; but we should look for a word that makes sense in both contexts.

Post a Comment:

You can post a comment here. Keep it on-topic.


Blog id:



 Note: HTML tags allowed for: b i u li ol ul font span div a p br pre tt blockquote

This is a technical blog related to the above topic. We reserve the right to remove comments that are off-topic, irrelevant links, advertisements, spams, personal attacks, politics, religion, etc.

Updated 26-Mar-2017 - Edit - Copyright REBOL Technologies -