zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: Should (t)path = array-unique-special work this way
Date: Fri, 5 Feb 2016 09:15:43 -0800	[thread overview]
Message-ID: <160205091543.ZM29723@torch.brasslantern.com> (raw)
In-Reply-To: <CAKc7PVCDHQDc=sby5wGNEtWCA6omFhmP8uPWbsPXwTQv9tDqFw@mail.gmail.com>

On Feb 5,  2:45pm, Sebastian Gniazdowski wrote:
}
} typeset -U path
} PATH="$PATH:/component/nr1"
} path+="/component/nr2"
} PATH="/component/nr2:$PATH"
} print "${(t)path}"
} declare -p path

I'm not really sure what question(s) you're asking.

Aside:
 Although it works to append to an array with path+="/component/nr2",
 it's really not good form.  Get used to path+=("/component/nr2") and
 you'll have much less trouble later.

Back to main topic:

} Outputs:
} array-unique-special

So far so good.

} typeset -a path
} path=( /component/nr2 /usr/local/bin /usr/bin /bin /usr/games /component/nr1 /component/nr2 )

For 5.3, this will change to

typeset -a path=( /component/nr2 /usr/local/bin /usr/bin /bin /usr/games /component/nr1 /component/nr2 )

Other things you might be asking about:

Q: Why is nr2 repeated when path is declared -U ?
A: Because it's repeated in $PATH.  Array uniqueness of tied arrays is
   only applied when assigning to the array; when assigning to the tied
   scalar, the array faithfully copies the value of the scalar.  If this
   were not the case, you could end up with a feedback loop (scalar is
   changed -> array uniquifies -> scalar changes again -> etc.).  This
   in turn is because scalars don't have a "uniqueness" property, so if
   the user is explicitly assigning to the scalar then we presume it is
   expected to reflect the value so assigned.

Q: Why doesn't -U appear in the "declare -p" output?
A: Good question.  It doesn't appear for non-special arrays either.  It
   may be intentional because -U isn't a POSIX-supported option, but I
   suspect it's just an accidental omission.


  reply	other threads:[~2016-02-05 17:15 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-05 13:45 Sebastian Gniazdowski
2016-02-05 17:15 ` Bart Schaefer [this message]
2016-02-05 17:34   ` Sebastian Gniazdowski
2016-02-05 17:46     ` Peter Stephenson
2016-02-05 18:19       ` Peter Stephenson
2016-02-14 10:04   ` Sebastian Gniazdowski
2016-02-14 10:19     ` Sebastian Gniazdowski
2016-02-14 14:34     ` Daniel Shahaf
2016-02-14 18:44     ` Bart Schaefer
2016-02-15  8:25       ` Sebastian Gniazdowski

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=160205091543.ZM29723@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@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).