zsh-users
 help / color / mirror / code / Atom feed
* Prepend to array
@ 2022-05-09 20:30 Perry Smith
  2022-05-09 23:45 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Perry Smith @ 2022-05-09 20:30 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 664 bytes --]

I have no idea where I came up with this but reading the internet and the documentation leads me to think that this isn’t really supported.

> # Add in my own functions
> 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.

So, I thought I would ask:

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

2) What is the prescribed method of prepending to an array: e.g.

Before
fpath=( /a/b /c/d )

After
fpath=( /x/y /a/b /c/d )

Thank you for your time,
Perry


[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Prepend to array
  2022-05-09 20:30 Prepend to array Perry Smith
@ 2022-05-09 23:45 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2022-05-09 23:45 UTC (permalink / raw)
  To: Perry Smith; +Cc: Zsh Users

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.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-05-09 23:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-09 20:30 Prepend to array Perry Smith
2022-05-09 23:45 ` Bart Schaefer

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