This manual page is for Mac OS X version 10.6.3

If you are running a different version of Mac OS X, view the documentation locally:

  • In Terminal, using the man(1) command

Reading manual pages

Manual pages are intended as a quick reference for people who already understand a technology.

  • For more information about the manual page format, see the manual page for manpages(5).

  • For more information about this technology, look for other documentation in the Apple Reference Library.

  • For general information about writing shell scripts, read Shell Scripting Primer.



code(n)                                          [incr Tcl]                                          code(n)



____________________________________________________________________________________________________________

NAME
       code - capture the namespace context for a code fragment

SYNOPSIS
       itcl::code ?-namespace name? command ?arg arg ...?
____________________________________________________________________________________________________________


DESCRIPTION
       Creates a scoped value for the specified command and its associated arg arguments.  A scoped value is
       a list with three elements:  the "@scope" keyword, a namespace context,  and  a  value  string.   For
       example, the command
              namespace foo {
                  code puts "Hello World!"
              }
       produces the scoped value:
              @scope ::foo {puts {Hello World!}}
       Note  that the code command captures the current namespace context.  If the -namespace flag is speci-fied, specified,
       fied, then the current context is ignored, and the name string is used as the namespace context.

       Extensions like Tk execute ordinary code fragments in the global namespace.  A scoped value  captures
       a  code  fragment together with its namespace context in a way that allows it to be executed properly
       later.  It is needed, for example, to wrap up code fragments when a Tk widget is used within a names-pace: namespace:
       pace:
              namespace foo {
                  private proc report {mesg} {
                      puts "click: $mesg"
                  }

                  button .b1 -text "Push Me"         -command [code report "Hello World!"]
                  pack .b1
              }
       The  code  fragment  associated  with  button .b1 only makes sense in the context of namespace "foo".
       Furthermore, the "report" procedure is private, and can only be accessed within that namespace.   The
       code command wraps up the code fragment in a way that allows it to be executed properly when the but-ton button
       ton is pressed.

       Also, note that the code command preserves the integrity of arguments  on  the  command  line.   This
       makes  it  a  natural  replacement for the list command, which is often used to format Tcl code frag-ments. fragments.
       ments.  In other words, instead of using the list command like this:
              after 1000 [list puts "Hello $name!"]
       use the code command like this:
              after 1000 [code puts "Hello $name!"]
       This not only formats the command correctly, but also captures its namespace context.

       Scoped commands can be invoked like ordinary code fragments, with or without the eval  command.   For
       example, the following statements work properly:
              set cmd {@scope ::foo .b1}
              $cmd configure -background red

              set opts {-bg blue -fg white}
              eval $cmd configure $opts
       Note that scoped commands by-pass the usual protection mechanisms; the command:
              @scope ::foo {report {Hello World!}}
       can be used to access the "foo::report" proc from any namespace context, even though it is private.


KEYWORDS
       scope, callback, namespace, public, protected, private



itcl                                                 3.0                                             code(n)

Reporting Problems

The way to report a problem with this manual page depends on the type of problem:

Content errors
Report errors in the content of this documentation to the Tcl project.
Bug reports
Report bugs in the functionality of the described tool or API to Apple through Bug Reporter and to the Tcl project through their bug reporting page.
Formatting problems
Report formatting mistakes in the online version of these pages with the feedback links below.

Did this document help you? Yes It's good, but... Not helpful...