unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* setenv and let-binding process-environment
@ 2016-03-20  1:25 Michael Heerdegen
  2016-03-20 14:10 ` Wolfgang Jenkner
  0 siblings, 1 reply; 3+ messages in thread
From: Michael Heerdegen @ 2016-03-20  1:25 UTC (permalink / raw)
  To: emacs-devel

Hello,

I've fallen into a trap.  I had expected that (something like)

(progn
  (setenv "A" "1")
  (let ((process-environment process-environment))
    (setenv "A" "2"))
  (getenv "A"))

would return "1", but it returns "2".  A similar expression and the
false assumption about it's semantics introduced a weird issue in my
code.

But I think others could come to the same conclusion that I came to
after reading the docs (e.g. setenv doc: "This function works by
modifying ‘process-environment’").

Should we document that case, or change the behavior, or do I miss
something?


BTW, after having located the cause of the trouble, I changed the code
to use

  (let ((process-environment (cons additional-binding process-environment)))
    { start the process })

following an advice in the manual.  That works without problems.


Thanks,

Michael.




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: setenv and let-binding process-environment
  2016-03-20  1:25 setenv and let-binding process-environment Michael Heerdegen
@ 2016-03-20 14:10 ` Wolfgang Jenkner
  2016-03-20 14:39   ` Michael Heerdegen
  0 siblings, 1 reply; 3+ messages in thread
From: Wolfgang Jenkner @ 2016-03-20 14:10 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: emacs-devel

On Sun, Mar 20 2016, Michael Heerdegen wrote:

>   (let ((process-environment process-environment))
>     (setenv "A" "2"))

This just establishes a new binding to the same object, so the code
works as expected.

The following would give the desired result (but, as you said, consing
the new value to the beginning of process-environment is better).

(let ((process-environment (copy-sequence process-environment)))
  (setenv "A" "2"))



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: setenv and let-binding process-environment
  2016-03-20 14:10 ` Wolfgang Jenkner
@ 2016-03-20 14:39   ` Michael Heerdegen
  0 siblings, 0 replies; 3+ messages in thread
From: Michael Heerdegen @ 2016-03-20 14:39 UTC (permalink / raw)
  To: emacs-devel

Wolfgang Jenkner <wjenkner@inode.at> writes:

> On Sun, Mar 20 2016, Michael Heerdegen wrote:
>
> >   (let ((process-environment process-environment))
> >     (setenv "A" "2"))
>
> This just establishes a new binding to the same object, so the code
> works as expected.

Ah!  Shame on me - of course!  I though this is somehow related to how
`sentenv' internally works, but it's just all normal Lisp.


Thanks,

Michael.



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-03-20 14:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-20  1:25 setenv and let-binding process-environment Michael Heerdegen
2016-03-20 14:10 ` Wolfgang Jenkner
2016-03-20 14:39   ` Michael Heerdegen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).