uplevel question

0 views
Skip to first unread message

Tim Newsham

unread,
Apr 22, 1999, 3:00:00 AM4/22/99
to
I am trying to implement an 'mset' function, ie:

mset {x y z} $l

will:

set x [lindex $l 0]
set y [lindex $l 1]
set z [lindex $l 2]

ok.. fairly simple, mostly I just need to loop over two lists
and do an uplevel and a set.. but I am having problems with
the uplevel:

uplevel 1 set $var $val

works mostly, except it does a concat and eval on the string first
which does weird things if $val happens to have spaces or braces
or other oddities:

set val "1 2 { 3"
uplevel 1 set x $val

ok.. so how do I avoid this? Is there a quoting function that I can
use to protect $val before passing it to uplevel? Is there another
way to implement this?

I tried using itcl's "scope":

uplevel 1 set $var dummy
set svar [uplevel 1 scope $var]
set $svar $val

this works a little better, but doesnt quite work properly when called
from a method of an object to set one of the method's locals..

so.. someone gimme the magic incantations please?

Tim N.

Harald Kirsch

unread,
Apr 22, 1999, 3:00:00 AM4/22/99
to
In article <7flrvc$lbq$1...@mochi.lava.net> new...@lava.net (Tim Newsham) writes:
> but I am having problems with
> the uplevel:
>
> uplevel 1 set $var $val
>
> works mostly, except it does a concat and eval on the string first
> which does weird things if $val happens to have spaces or braces
> or other oddities:


uplevel 1 set [list $var] [list $value]

.. just in case the variable name also contains oddities. (tested
this with non-matching `"' and `{' in it)

Harald Kirsch

--
---------------------+------------------+--------------------------
Harald Kirsch (@home)| | Now I rebooted.
k...@iitb.fhg.de | | --- Jerry Pournelle, BYTE
gegen Punktfilitis hilft nur `chmod u-w ~'

Don Porter

unread,
Apr 22, 1999, 3:00:00 AM4/22/99
to
Harald Kirsch <k...@iitb.fhg.de> wrote:
> uplevel 1 set [list $var] [list $value]

Or

uplevel 1 [list set $var $value]

as suits your taste.

--
| Don Porter, D.Sc. Mathematical and Computational Sciences Division |
| donald...@nist.gov Information Technology Laboratory |
| http://math.nist.gov/mcsd/Staff/DPorter/ NIST |
|______________________________________________________________________|

Alexandre Ferrieux

unread,
Apr 22, 1999, 3:00:00 AM4/22/99
to
Tim Newsham wrote:
>
> I am trying to implement an 'mset' function, ie:
>
> mset {x y z} $l
>
> will:
>
> set x [lindex $l 0]
> set y [lindex $l 1]
> set z [lindex $l 2]

Others have answered your questions about quoting hell, uplevel and so
on. Now about the specific tool, are you aware of the following nifty
idiom:

foreach {x y z} $l break

A DN search (foreach break) should bring back the proper credit
information, along with an explanation if you need one.

-Alex

Reply all
Reply to author
Forward
0 new messages