Re: What's the magic to using Incr Tcl



On Jun 29, 9:41 am, Troy.Tan...@xxxxxxx wrote:
You probably need to either qualify the commands with the itcl::
namespace:

itcl::class myClass {...}

or import the itcl commands like so:

namespace import ::itcl::*

You can make sure Itcl is loaded and whether you need to do this by
looking at the result of the following commands:

info commands class
info commands itcl::class

Some (early?) versions of Itcl I used didn't require the namespace
import. I never figured it out - whether it was my installation, or
some change to the Itcl package - but some installations worked with
just a package require Itcl, some didn't. I'd guess the tutorials
were written where the import was not necessary.

Troy

On Jun 29, 10:01 am, Andrew Falanga <af300...@xxxxxxxxx> wrote:

Hi,

I'm trying to learn to use the [incr Tcl] package and I seem to be
having some difficulty. I've downloaded a tutorial of sorts that I
found a link to from the main [incr Tcl] web site. It's called,
"Object-Oriented Programming with [incr Tcl]." I've figured out that
I must use a "package require Itcl" in my script to load the package.
however, then the interpreter bails saying that the command "class" is
unknown. I've also tried "Class" although none of the examples in
this tutorial use an upper case C in the word class.

So, after one brings in the functionality with "package require", how
does one actually use the package? I'm also using the manual pages on-
line fromhttp://www.tcl.tk/man/itcl3.1/index.htmlandthere it is
mentioned that the command name for class is "class". So, below is
the very simple script I've put together to familiarize myself with
this package, please tell me what I'm doing wrong.

Oh, nearly forgot, in case it's important, I'm using ActiveState TCL
on Windoze. Is it possible I'm getting the wrong package?

Thanks,
Andy

puts [package require Itcl]

Class myClass {
variable int

constructor { i } {
puts "C-tor for myClass called: setting int to $i"
set int $i
}

destructor {
obliterate
}

method SetInt { i } {
set int $i
}

method ShowInt { } {
puts $int
}

method obliterate { } {
puts "inside destructor: obliterate"
unset int
}

}

myClass mc1 78
mc1 ShowInt
mc1 SetInt 33421
mc1 ShowInt

delete object mc1

Thanks everyone. At least I wasn't too far off.

Andy

.



Relevant Pages

  • Re: Whats the magic to using Incr Tcl
    ... You probably need to either qualify the commands with the itcl:: ... just a package require Itcl, ... mc1 ShowInt ...
    (comp.lang.tcl)
  • Re: How do I access ICTL on my WINDOWS 2000 box?
    ... > I've been learning tcl/tk and now want to give ITCL a go. ... > To now go ahead with ITCL, is it just a matter of adding a "package ... All itcl commands are in the itcl namespace, ...
    (comp.lang.tcl)
  • Re: Finding installed package files
    ... >, and who is going to supply this documentation. ... > is a package with the common man pages for the thousand odd common commands ... tell me, as an installation option for some large packages, what was ... >>a set of commands and 'man' pages, could produce such a directory to make it ...
    (alt.os.linux.redhat)
  • Re: Finding installed package files
    ... is a package with the common man pages for the thousand odd common commands ... Seeing as how 18 percent of the package is documentation - have you looked ... >a set of commands and 'man' pages, could produce such a directory to make it ... There are 16 books in front of me between the monitors, ...
    (alt.os.linux.redhat)
  • Re: New list commands ... What do you think ?
    ... That's the risk of every developer writing basic commands. ... allow some discussion about some of them, that are really good for core ... runtime consuming and could be done more efficiencly in C using the tcl ... Critcl builds a package which is loaded. ...
    (comp.lang.tcl)