From: Ray Andrews <rayandrews@eastlink.ca>
To: zsh-users@zsh.org
Subject: Re: proxy name for array
Date: Wed, 10 Jan 2024 12:26:28 -0800 [thread overview]
Message-ID: <4e5aa5cf-dfad-4e0c-ac38-8631d1c4ccbc@eastlink.ca> (raw)
In-Reply-To: <CAH+w=7Z7fHsimxLEhpVyc-BCVrCVJ9ZTK8hhMsWi8bYiYLHxDQ@mail.gmail.com>
This works. Double indirection, but she runs.
function called ()
{
# Am I tempting the wrath of the Gods? :
temp=( ${(P)${(P)1}[pages]} ) # Temporary array will be used to
hold content of 'Pages' (or whatever else).
temp[2]=50 # Set some test values.
temp[3]=100
temp[4]=150
echo 10: $temp # How are we doing?
echo 11: $temp[3] # So far so good.
set -A "${${(P)1}[pages]}" $temp # The hard part: write 'temp'
back to 'Pages' via the named input array.
}
typeset -A main=() # The main structure. Contains a dozen elements
but we only need one here ...
main[pages]=Pages # The name of the pages array.
Pages=( 1 ) # Initialize. This is going to end up as an
array of numbers.
# Now we jump into the function that will modify 'Pages' -- or whatever
other name is held in '[pages]' of whatever structure name is passed.
called main # Push the button. Don't look at the flash.
echo 13: ${(P)main[pages]} # It's Alive! It's alive, it's alive,
it's alive!
echo 14: ${(P)main[pages][3]} # Now I know what it's like to be Mark!
;-))
echo "Who said zsh doesn't have structures? She does, they're just a
bit tricky to build."
----------------------------------------------
... subject to improvement of course. Or can 'temp' be avoided by
direct access to 'Pages' but via similar indirection? Probably too
complicated.
next prev parent reply other threads:[~2024-01-10 20:27 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-09 18:59 Ray Andrews
2024-01-10 0:21 ` Bart Schaefer
2024-01-10 0:54 ` Ray Andrews
2024-01-10 2:29 ` Bart Schaefer
2024-01-10 2:58 ` Ray Andrews
2024-01-10 3:05 ` Bart Schaefer
2024-01-10 13:44 ` Ray Andrews
2024-01-10 20:26 ` Ray Andrews [this message]
2024-01-10 21:11 ` Bart Schaefer
2024-01-10 21:22 ` 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=4e5aa5cf-dfad-4e0c-ac38-8631d1c4ccbc@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).