elves / elvish

Powerful scripting language & versatile interactive shell

Home Page:https://elv.sh/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

New built-in function: cons

da-tubi opened this issue · comments

~> 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.

Isn't this a dup of #1694?

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

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.