elves / elvish

Powerful scripting language & versatile interactive shell
https://elv.sh/
BSD 2-Clause "Simplified" License
5.53k stars 297 forks source link

New built-in function: cons #1723

Open da-tubi opened 9 months ago

da-tubi commented 9 months ago
~> conj [1 2] 3
▶ [1 2 3]

cons is similar to conj.

~> cons 3 [1 2]
▶ [3 1 2]

Why we need cons? For example:

set paths = (cons /opt/bin/ $paths)

For $paths, the order is crucial.

krader1961 commented 9 months ago

Isn't this a dup of #1694?

da-tubi commented 9 months ago

Not precisely a dup, because we have a different opinion on cons and conj.

krader1961 commented 9 months ago

Not precisely a dup, because we have a different opinion on cons and conj.

It is precisely a dup because both issues propose a more efficient mechanism for prepending to a list. The question is how that should be achieved. While I expressed a preference for naming an explicit command for doing so prepend rather than cons, in issue #1694, that is irrelevant to the question of whether there should be an explicit command for doing so.