Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Is this a bug?
I was using the tcllib::dns package and
couldn't get it to load. I traced the
problem down to this small example which
results in the error message
"Couldn't save command result in variable"

set msg(1) one ;# Turn msg into an array
namespace eval ::foo {
catch {package require notFound} msg
}

It appears the global msg and the ::foo msg
variables are getting .

It's easy to work around the bug--just fully
qualify the second msg--but this appears in
tcllib code.

Keith


Report this thread to moderator Post Follow-up to this message
Old Post
keithv
04-28-05 01:59 AM


Re: Is this a bug?
keithv wrote:
> I was using the tcllib::dns package and
> couldn't get it to load. I traced the
> problem down to this small example which
> results in the error message
>  "Couldn't save command result in variable"
>
>   set msg(1) one ;# Turn msg into an array
>   namespace eval ::foo {
>     catch {package require notFound} msg
>   }
>
> It appears the global msg and the ::foo msg
> variables are getting .
>
> It's easy to work around the bug--just fully
> qualify the second msg--but this appears in
> tcllib code.

The really safe solution is to add the line

variable msg

right before the 'catch ...', within the 'namespace eval ::foo' block.

Sadly, that is the way Tcl's variable resolution is specified: if a
variable is not found in the current namespace, it is looked up as a
global variable. If a global is found, it is used. Otherwise a variable
in the current namespace is created. Nasty, IMO. We will not be able to
fix this in the short run :(

So, the rule is: if you want to make sure that you are using a variable
in the current namespace, do "declare" it with [variable].

Miguel

Report this thread to moderator Post Follow-up to this message
Old Post
miguel sofer
04-28-05 01:59 AM


Re: Is this a bug?
keithv wrote:
> I was using the tcllib::dns package and
> couldn't get it to load. I traced the
> problem down to this small example which
> results in the error message
>  "Couldn't save command result in variable"
>
>   set msg(1) one ;# Turn msg into an array
>   namespace eval ::foo {
>     catch {package require notFound} msg
>   }

If you want namespace restricted resolution of a variable name,
use [variable] to set it up:

set msg(1) one ;# Turn msg into an array
namespace eval ::foo {
variable msg
catch {package require notFound} msg ;# Now this means ::foo::msg
}

Tcl prefers to resolve a variable name to any existing variable rather
than create a new one.

--
| Don Porter          Mathematical and Computational Sciences Division |
| donald.porter@nist.gov             Information Technology Laboratory |
| http://math.nist.gov/~DPorter/                                  NIST |
 |_______________________________________
_______________________________|

Report this thread to moderator Post Follow-up to this message
Old Post
Don Porter
04-28-05 01:59 AM


Re: Is this a bug?
"keithv" <kvetter@gmail.com>,
In a message on 27 Apr 2005 12:37:32 -0700, wrote :

"> I was using the tcllib::dns package and
"> couldn't get it to load. I traced the
"> problem down to this small example which
"> results in the error message
">  "Couldn't save command result in variable"
">
">   set msg(1) one ;# Turn msg into an array
">   namespace eval ::foo {
">     catch {package require notFound} msg
">   }
">
"> It appears the global msg and the ::foo msg
"> variables are getting .

Nope.  You did not declare the msg in the namespace to be a variable.
It is still the global msg and you are trying to set a scalar value in a
variable that was bound to an array.

">
"> It's easy to work around the bug--just fully
"> qualify the second msg--but this appears in
"> tcllib code.

Might be a bug in the tcllib or maybe something else.

">
"> Keith
">
">

\/
Robert Heller                        ||InterNet:   heller@cs.umass.edu
http://vis-www.cs.umass.edu/~heller  ||            heller@deepsoft.com
http://www.deepsoft.com              /\FidoNet:    1:321/153








Report this thread to moderator Post Follow-up to this message
Old Post
Robert Heller
04-28-05 01:59 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Tcl archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:30 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.