zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Perry Smith <pedz@easesoftware.com>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: Prepend to array
Date: Mon, 9 May 2022 16:45:17 -0700	[thread overview]
Message-ID: <CAH+w=7ZyL-pDaBeHkMLoZ3KP0N=4XxTjTcw11DGB5o0f71zP2g@mail.gmail.com> (raw)
In-Reply-To: <7BFD80EB-FA4C-446C-927E-FCBFDDA28246@easesoftware.com>

On Mon, May 9, 2022 at 1:30 PM Perry Smith <pedz@easesoftware.com> wrote:
>
> > fpath[1,0]=$ZDOTDIR/functions
>
> It does exactly what I want: it prepends $ZDOTDIR/functions to the front of the fpath array.  I can’t even find an example where the 2nd index is less than the first index.

Hm, the documentation for "Array Element Assignment" barely mentions
that you can use two comma-separated indices in an assignment at all.
It's implied by "... the element or range specified by EXP is replaced
... assigning a parenthesized list of values to an element or range
changes the number of elements in the array ..."

The documentation is also out of date with respect to "... only
single-element assignments may be made with typeset."  As of the
impending 5.9 release, it's probably also somewhat off when describing
escaping conventions for subscripts vis-a-vis associative array
assignment.

> 1) Is the above syntax supported or does it just happen to work currently?

It's supported in zsh native mode, but not in ksh_arrays or
ksh_zero_subscript modes.  IIRC it was introduced because of the
subscripting flags that allow searching for a value, where a failed
search can return an index of zero.

> 2) What is the prescribed method of prepending to an array

Aside from array=(new values $array), you found it.  You can also
insert new values before any individual element X with array[X,0]=(new
values) but I don't recall if that variation is intended to remain
supported.


      reply	other threads:[~2022-05-09 23:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-09 20:30 Perry Smith
2022-05-09 23:45 ` Bart Schaefer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAH+w=7ZyL-pDaBeHkMLoZ3KP0N=4XxTjTcw11DGB5o0f71zP2g@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=pedz@easesoftware.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).