zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-users@zsh.org
Subject: Re: easy calling of associative array?
Date: Mon, 2 Nov 2015 13:05:18 -0800	[thread overview]
Message-ID: <151102130518.ZM17830@torch.brasslantern.com> (raw)
In-Reply-To: <5637AC27.8010007@eastlink.ca>

On Nov 2, 10:32am, Ray Andrews wrote:
} Subject: Re: easy calling of associative array?
}
} On 11/02/2015 08:28 AM, Bart Schaefer wrote:
} >
} >      set_v () {
} >        typeset -g "${1}[$2]=$3"	# quotes so [ ] isn't globbing
} >      }
} 
} I've never seen 'typeset' used to refer to anything but a simple
} variable.

In the above,

    set_v ary idx val

is going to invoke

    typeset -g ary[idx]=val

because $1 $2 $3 are all expanded after parsing and before calling the
typeset command.  (Zyx has pointed out the lack of robustness.)  Note
that it is not affecting any positional parameters, they're all long
gone (replace by their values) before typeset begins.

} I note that the above does not work without the 'typeset -g' so what
} does that accomplish?

Ordinarly "typeset" inside a function body behaves like "local".  The
-g option tells it not to do that, so that the name "ary" is taken to
come from the calling context instead of the current function context.

} 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?

The above is what your text would look like if I didn't run it through
a reformatter.  It Used To Be that everyone assumed text should be
folded to be readable on an 80-column display, which, as a guy still
using the email program I wrote myself 20 years ago, I still do.  Then
along came HTML format email, and everybody assumed text should never be
wrapped at all (let the reader's UI deal with it).  Except there's still
this pesky thing about mailing lists preferring plain text, so we end up
with a hypbrid where text as you write it is folded to be readable at
whatever your display width is set, but then it gets re-folded to 80
when you send it -- except that it also keeps any real newlines you
entered, so if you were actually trying to make it look nice, it ends
up like the above instead.

Exactly what you SHOULD do depends on what you're using to write your
email.  In Thunderbird you should probably put literal line breaks only
at the ends of paragraphs, and let it wrap other stuff as it wills.


  parent reply	other threads:[~2015-11-02 21:05 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
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 [this message]
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=151102130518.ZM17830@torch.brasslantern.com \
    --to=schaefer@brasslantern.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).