Losing Metaphors: Zip and Paste

post by jefftk (jkaufman) · 2023-11-29T20:31:07.464Z · LW · GW · 6 comments

Contents

6 comments

In python (and several other languages) if I have two lists and want to process corresponding elements together I can use zip:

>>> for number, letter in zip(
...    [1,2,3,4], ["a", "b", "c", "d"]):
...  print(number, letter)
...
1 a
2 b
3 c
4 d

The metaphor is a zipper, taking the two sides and merging them together. It's not perfect, since a zipper interleaves instead of matching pairs, but it's pretty good.

In unix, there's a command line tool, paste that does the same thing:

$ paste <(echo 1 2 3 4 | tr ' ' '\n') \
        <(echo a b c d | tr ' ' '\n')
1 a
2 b
3 c
4 d

This time the metaphor is pasting: physically putting one column next to another.

I found a discussion on the origin of these terms, which traces paste back to at least 1978 at Bell Labs Center 127. The earliest use of zip I've found is 1988's Introduction to Functional Programming (p57).

What I find interesting about these names is that they've both "lost" in a sense: paste and zip generally mean something else to computer users:

Older names for this are less metaphorical: APL used the comma-operator, and in Lisp this would be done with the more general mapcar function.

6 comments

Comments sorted by top scores.

comment by the gears to ascension (lahwran) · 2023-11-30T02:38:50.010Z · LW(p) · GW(p)

it could have been transpose((a, b, c)) = zip(a, b, c)

comment by Samuel Hapák (hleumas) · 2023-11-29T21:08:06.219Z · LW(p) · GW(p)

I would say that zip and unzip can be understood as an equivalent to rar and unrar, tar and untar. I wouldn’t say that it necessarily needs anyone imagining a bag being zipped. But, it might as well be the fact that English isn’t my first language.

Replies from: jkaufman
comment by jefftk (jkaufman) · 2023-11-29T22:36:59.564Z · LW(p) · GW(p)

I think people mostly aren't imagining it, though you do see the metaphor in icons and hear it in explanations.

comment by Shankar Sivarajan (shankar-sivarajan) · 2023-11-30T03:50:10.999Z · LW(p) · GW(p)

In Python, you can zip more than two arrays: the metaphor of a zipper was always a stretch. The word "zip" is common, short, close enough in meaning to "interleave," and has a convenient inverse. "Pack" would probably work too, but "imbricate" would have been a fun choice!

Replies from: jkaufman
comment by jefftk (jkaufman) · 2023-11-30T12:02:58.859Z · LW(p) · GW(p)

Or transpose?

Replies from: shankar-sivarajan
comment by Shankar Sivarajan (shankar-sivarajan) · 2023-11-30T13:06:34.573Z · LW(p) · GW(p)

If you think of matrices as lists of vectors, yeah, that works. But I think that's akin to thinking of integers as strings of digits.