Subject: Re: bug#76618: 30.1.50; need an -unzip-lists function?

From: Stefan Kangas <[email-masked]>
Date: Thu, 27 Feb 2025 23:05:19 +0000

tags 76618 + notabug
thanks

Christopher Howard <[email-masked]> writes:

> Hi. The behavior of -zip and -unzip seems strange to me, though this is not exactly my complaint. -zip has the strange behavior that it always returns lists of lists, unless you provide it with two lists, in which case it returns cons cells instead.
>
> Okay, fine, but the documentation for -unzip says
>
> ```
> Unzip LISTS.
>
> This works just like ‘-zip’ but takes a list of lists instead of
> a variable number of arguments, such that
>
>   (-unzip (-zip L1 L2 L3 ...))
>
> is identity (given that the lists are the same length).
> ```
>
> But if you try zipping and unzipping two lists, like
>
> (-unzip (-zip '(1 a) '(2 b)))
>
> this throws an error, because -unzip only deals with lists.
>
> One can use -zip-lists, to avoid the error. But then, if your lists happen to be two elements long, you end up with a list of pairs!
>
> ELISP> (-unzip (-zip-lists '(1 a) '(2 b)))
> ((1 . a) (2 . b))
>
> In my case, what I really want to do is unzip and then zip back up. But I get different results (pairs vs. cons) from -unzip depending on the number of lists:
>
> ELISP> (-unzip '((1 a) (2 b) (3 c)))
> ((1 2 3) (a b c))
>
> ELISP> (-unzip '((1 a) (2 b)))
> ((1 . 2) (a . b))
>
> This doesn't quite work:
>
> ELISP> (setq foo (-unzip '((1 a) (2 b))))
> ((1 . 2) (a . b))
>
> ELISP> (-zip (first foo) (second foo))
> <throws error>
>
> Or this:
>
> ELISP> (-unzip '((1 . a) (2 . b)))
> <throws error>
>
> Maybe we just need an -unzip-lists function?

This seems to be about the dash.el library, which is not a part of
Emacs.  I'd recommend reporting this to the maintainers of that package
(see `C-h P dash RET`) instead.