where is upvar

Darren New dnew at san.rr.com
Thu Sep 21 20:50:09 EDT 2000


Kragen Sitaker wrote:
> It is natural, but it could also be considered a bad idea.  If it's a
> set of variables specified on the command line, it's definitely a bad
> idea; if it's a set of variables specified in the script, it is a good
> idea.  

No, the point is to not pass the variables at all. For example, in the code
I was writing, I was parsing RFC822 style messages. There was a call
   getHeaders $message
that would set a bunch of variables like
   msg-Subject
   msg-From
   msg-To
and so on. It would only set the variable if the header was there, and it
would put "msg-" on the front, so it was easy to avoid conflicts, and do
things like
  if {[info exists msg-Subject]} {
    set msg-Subject "Re: $msg-Subject"
  } else {
    set msg-Subject "No subject"
  }

Now, Python has more sophisticated types than Tcl natively does, so
returning a message object with getattr and setaddr overridden perhaps would
work better. I could have returned a hash as well, but the local variables
in Tcl are like a hash anyway, just as they are in Python.  But it's not at
all unnatural to set variables in the caller from Tcl.

OT-ly yours --

-- 
Darren New / Senior MTS & Free Radical / Invisible Worlds Inc.
San Diego, CA, USA (PST).  Cryptokeys on demand.
"No wonder it tastes funny. 
            I forgot to put the mint sauce on the tentacles."



More information about the Python-list mailing list