zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@zsh.org
Subject: Re: typeset -p output gives shows variables which can't be read back in
Date: Tue, 01 Mar 2011 07:15:20 -0800	[thread overview]
Message-ID: <110301071520.ZM8224@torch.brasslantern.com> (raw)
In-Reply-To: <AANLkTimkAbTrwS0YB9OckDhc1hgyWWKVGR0dBhbn1T+K@mail.gmail.com>

On Mar 1,  1:49am, Rocky Bernstein wrote:
} 
} Thanks for the information. The only thing I still don't understand or
} disagree with is the "doomed from the start comment".

You agree but don't know why? :-)

E.g., if the shell you're debugging is six levels deep in function call
stack at the point where you decide to break out to a new shell, the
variables you dump are going to have several different dynamic scopes
which it will be impossible to recreate in the new shell.  It will
have defined functions which the new shell won't have (though allowing
$functions from zsh/parameter to be dumped and restored will get most
of them).  The option settings may not make sense in a top-level shell
and the traps certainly won't be restored.  Etc.
 
} In [dynamic] scope, it's sufficient to set the variable somewhere down
} the call chain such as in the trace hook and that persists back to
} outside the trace hook. I've tested this already in my nested shell
} example and it works as expected. But of course here you have to be
} careful not to run some sort of command that *defines* the variable
} again before the assignment or else that will now be the point of a
} new scope for the variable's value.

All true, but you can't simply assign to the name of an associative
array variable and have it behave like an associative array.  You MUST
declare it first, and you can't control whether it's already been
declared in some surrounding dynamic scope, so even typeset -g is not
enough to assure it will persist (and if it's been declared in some
surrounding scope, simple assignment will also change it in that scope
and not in the global one).

Hence "doomed" -- it's literally impossible to guarantee that you can
store variable state in a file and then restore it again, even to
replicate the state in a new shell.
 
} So although on entry to the nested shell a definition of the type is
} either necessary or useful, when writing a file on exit for later
} source'ing it is not and is harmful: at the point in the debug hook
} where the values are source'd back in to pick up changed values, an
} associative array's value has already been defined scope-wise.

I'm not sure how you assure the truth of that last statement, but you
must be working in a more constrained context than I'm imagining.


      reply	other threads:[~2011-03-01 15:15 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-27 11:44 Rocky Bernstein
2011-02-27 21:01 ` Bart Schaefer
2011-02-28  5:08   ` Rocky Bernstein
2011-02-28  7:09     ` Bart Schaefer
2011-03-01  3:09       ` Rocky Bernstein
2011-03-01  5:59         ` Bart Schaefer
2011-03-01  6:49           ` Rocky Bernstein
2011-03-01 15:15             ` Bart Schaefer [this message]

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=110301071520.ZM8224@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).