zsh-users
 help / color / mirror / code / Atom feed
From: Ray Andrews <rayandrews@eastlink.ca>
To: zsh-users@zsh.org
Subject: Re: easy calling of associative array?
Date: Mon, 02 Nov 2015 10:32:07 -0800	[thread overview]
Message-ID: <5637AC27.8010007@eastlink.ca> (raw)
In-Reply-To: <151102082808.ZM17640@torch.brasslantern.com>

On 11/02/2015 08:28 AM, Bart Schaefer wrote:
> }     #$3=${(P)${:-${1}[$2]}}     #nothing works

Pardon, that was an obvious mistake.  Too much thrashing around with 'eval'.
> Same assignment-syntax problem.
>
>      set_v () {
>        typeset -g "${1}[$2]=$3"	# quotes so [ ] isn't globbing
>      }
>
> Here you don't need the (P) indirection because ${1} and $2 are both
> expanded before being passed to typeset, so you already extracted the
> name that was passed in $1.

... and that's nicely readable too--the sort of syntax that seems 
intuitive, as I
mentioned.  I won't say this is all clear in my mind, but it's
at least tractable. One further question:  I've never seen 'typeset' 
used to refer
to anything but a simple variable.  I note that the above does not work 
without
the 'typeset -g' so what does that accomplish?   I've never thought of the
positional parameters and being typeset-able.  I get the feeling it is a 
future
problem solver.
>
> Also note I'm ignoring all possible error checking, e.g. if $1 is not
> an identifier (in the worst case, contains an "="), things go badly.

Sure, it's naive at this point.  I don't yet think past that.
> I'm not exactly sure what you're wanting as either output or exit
> status here, but except that I'd recommend [[ ]] instead of [ ] as
> the test syntax, what you wrote for "this works" is sensible.

Ok.  I don't pay enough attention to the difference.

BTW, as a point of list etiquette:  Responding to most posts I let my 
lines wrap
but resonding to yours, which seem to alway have fixed line width, I try to
match that style, but looking at the returned posts from the list, they 
sometimes
sproing badly. Should I  try to keep to your width, or just let lines wrap?
>


  reply	other threads:[~2015-11-02 19:02 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-01 23:12 Ray Andrews
2015-11-01 23:55 ` ZyX
2015-11-02  0:49   ` Ray Andrews
2015-11-02  3:08     ` Bart Schaefer
2015-11-02  3:33       ` Ray Andrews
2015-11-02  6:51         ` Bart Schaefer
2015-11-02 15:43           ` Ray Andrews
2015-11-02 16:28             ` Bart Schaefer
2015-11-02 18:32               ` Ray Andrews [this message]
2015-11-02 19:37                 ` ZyX
2015-11-02 22:10                   ` Bart Schaefer
2015-11-02 22:50                     ` Ray Andrews
2015-11-02 21:05                 ` Bart Schaefer
2015-11-02 23:01                   ` Ray Andrews
2015-11-03 15:57                     ` Bart Schaefer
2015-11-04 14:48                       ` Ray Andrews
2015-11-04 16:39                         ` Bart Schaefer
2015-11-04 18:31                           ` Ray Andrews
2015-11-02 19:33             ` ZyX
2015-11-02 23:04               ` Ray Andrews

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=5637AC27.8010007@eastlink.ca \
    --to=rayandrews@eastlink.ca \
    --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).