Google Gruppi non supporta più i nuovi post o le nuove iscrizioni Usenet. I contenuti storici continuano a essere visibili.

Scoping Issue?

27 visualizzazioni
Passa al primo messaggio da leggere

Le Chaud Lapin

da leggere,
15 ago 2011, 02:48:3015/08/11
a
Hi All,

There is a third-party proc that I have been using, NANDFLASH::Init,
that I "source'd" from a file that contained it. NANDFLASH is
namespace rooted in global namespace.

#===============================================================================
# proc NANDFLASH::Init
#-------------------------------------------------------------------------------
proc NANDFLASH::Init {} {
global target
variable appletAddr
variable appletMailboxAddr
variable appletFileName

puts "-I- NANDFLASH::Init (trace level : $target(traceLevel))"

# Load the applet to the target
GENERIC::Init $NANDFLASH::appletAddr $NANDFLASH::appletMailboxAddr
$NANDFLASH::appletFileName [list $target(comType) $target(traceLevel)]
}

In my own code, I have been using this NANDFLASH::Init successfully
for a few weeks by invoking it from the global namespace. Last week, I
tried to invoke it from within a proc, burn_device:

proc burn_device {} {

::NANDFLASH::Init
....
}

The proc burn_device is called by another proc GO. GO is invoked upon
clicking a Tk button. Now, when I force the invocation of GO by
clicking the button, I get the following errors. I would like to avoid
editing the third-party function if possible. My guess is that there
is some kind of scoping I need to do. Any help appreciated.

-Le Chaud Lapin-

can't read "NANDFLASH::appletAddr": no such variable
can't read "NANDFLASH::appletAddr": no such variable
while executing
"GENERIC::Init $NANDFLASH::appletAddr $NANDFLASH::appletMailboxAddr
$NANDFLASH::appletFileName [list $target(comType)
$target(traceLevel)]"
(procedure "::NANDFLASH::Init" line 10)
invoked from within
"::NANDFLASH::Init"
(procedure "burn_device" line 85)
invoked from within
"burn_device"
(procedure "GO" line 8)
invoked from within
"GO"
invoked from within
".frame_primary.frame_secondary.button_go invoke "
invoked from within
".frame_primary.frame_secondary.button_go instate {pressed !disabled}
{ .frame_primary.frame_secondary.button_go state !
pressed; .frame_primary.frame_s..."
(command bound to event)

Arjen Markus

da leggere,
15 ago 2011, 05:27:3115/08/11
a
On 15 aug, 08:48, Le Chaud Lapin <jaibudu...@gmail.com> wrote:
> Hi All,
>
> There is a third-party proc that I have been using, NANDFLASH::Init,
> that I "source'd" from a file that contained it. NANDFLASH is
> namespace rooted in global namespace.
>
> #==========================================================================­=====
> #  proc NANDFLASH::Init
> #--------------------------------------------------------------------------­-----

You probably need to change $NANDFLASH::... to $::NANDFLASH::...
Namespaces without a leading :: are taken from the current namespace,
and that might not be the global one!

Regards,

Arjen

Emiliano

da leggere,
15 ago 2011, 08:36:3515/08/11
a
On 15 ago, 03:48, Le Chaud Lapin <jaibudu...@gmail.com> wrote:
> Hi All,
>
> There is a third-party proc that I have been using, NANDFLASH::Init,
> that I "source'd" from a file that contained it. NANDFLASH is
> namespace rooted in global namespace.
>
> #===============================================================================
> #  proc NANDFLASH::Init
> #-------------------------------------------------------------------------------
> proc NANDFLASH::Init {} {
>     global target
>     variable appletAddr
>     variable appletMailboxAddr
>     variable appletFileName
>
>     puts "-I- NANDFLASH::Init (trace level : $target(traceLevel))"
>
>     # Load the applet to the target
>     GENERIC::Init $NANDFLASH::appletAddr $NANDFLASH::appletMailboxAddr
> $NANDFLASH::appletFileName [list $target(comType) $target(traceLevel)]
>
> }


There's no need to qualify var names when you have used [variable]
inside
a procedure.
Replace the last line for

GENERIC::Init $appletAddr $appletMailboxAddr \
$appletFileName [list $target(comType) $target(traceLevel)]

and it will work.

Regards
Emiliano

John Seal

da leggere,
15 ago 2011, 09:42:5615/08/11
a
"Le Chaud Lapin" <jaibu...@gmail.com> wrote in message
news:1d2ebbc4-474b-4279...@h9g2000vbr.googlegroups.com...

> proc burn_device {} {
>
> ::NANDFLASH::Init
> ....
> }
>
> I would like to avoid
> editing the third-party function if possible.

Try this:

uplevel #0 ::NANDFLASH::Init

That executes the call in global scope rather than the current scope.
Perhaps Init will be able to resolve the missing variable there.


Le Chaud Lapin

da leggere,
15 ago 2011, 22:39:1215/08/11
a
On Aug 15, 8:42 am, "John Seal" <john_j_s...@raytheon.com> wrote:
> "Le Chaud Lapin" <jaibudu...@gmail.com> wrote in messagenews:1d2ebbc4-474b-4279...@h9g2000vbr.googlegroups.com...

>
> > proc burn_device {} {
>
> > ::NANDFLASH::Init
> > ....
> > }
>
> > I would like to avoid
> > editing the third-party function if possible.
>
> Try this:
>
> uplevel #0 ::NANDFLASH::Init
>
> That executes the call in global scope rather than the current scope.
> Perhaps Init will be able to resolve the missing variable there.

I read all the responses, but I reply to this one only.

The problem was my feeble knowledge of TCL. Essentially, a long
sequence of "source'ing" of files was broken because a global variable
that needed to be defined by my code was defined/declared after the
"source'ing" began. The error conditions were masked by my abuse of
catch.

One of the would-have-been-properly-sourced files contained the global
variable that the interpreter legitimately complained about not being
defined.

Thanks All,

-Le Chaud Lapin-

Arjen Markus

da leggere,
16 ago 2011, 04:42:5416/08/11
a

catch is a very useful command, but it tends to mask Tcl's sublime
error handling system :).

Regards,

Arjen

0 nuovi messaggi