Hi all I have ported over one of our applications from using itcl to using xotcl. I have a lot of code that already uses the itcl stuff, so the port must be backwards compatible. I have the following issue. Can anyone give me an idea how I can get around it? A script that shows my issue is as follows:
#!/usr/bin/tclsh package req XOTcl namespace import ::xotcl::*
::xotcl::Class Connect -parameter { {telnet} {ssh} {ip} } Connect instproc init {node args} { [self] instvar telnet [self] instvar ip }
Connect dev node -ip "127.0.0.1" -telnet
The above does not work, as it seems that the telnet arg must not be NULL, however, I need this to be NULL, as it is just a flag.
If I pass in: Connect dev node -ip "127.0.0.1" -telnet ³²
This works, however, this is not backwards compatible with how things were with itcl, and I have too many users/scripts to change how this is done. There are potentially 2 ways around this, however, I am unable to find information on if either of them are possible: 1. Allow the passing in of a NULL argument 2. Prevent the constructor parsing args so that I can parse my own
I would appreciate any assistance
Cheers Colin
Colin Ross schrieb:
There are potentially 2 ways around this, however, I am unable to find information on if either of them are possible:
- Allow the passing in of a NULL argument
One can call arbitrary methods via configure. You just have just to provide your own method to handle such a cases, as the default parameter handling expect always exactly one argument.
========================== ::xotcl::Class Connect -parameter { {ssh} {ip} } Connect instproc telnet {} { my set telnet true } Connect instproc init {node args} { my instvar telnet ip
# provide a default if {![info exists telnet]} { set telnet false }
puts telnet=$telnet # .... }
Connect dev node -ip "127.0.0.1" -telnet ==========================
- Prevent the constructor parsing args so that I can parse my own
This is as well an option:
========================== ::xotcl::Class Connect
Connect instproc configure args { # puts stderr "wanna interpret $args" # # do what ever you want to do with the arguments..... # } Connect dev node -ip "127.0.0.1" -telnet ==========================
All the best -gustaf neumann
Hi Gustaf - thanks so much for your prompt response. The "instproc configure" is perfect for what I need to do. I do appologise for not being able to find it in the documentation - I guess if you dont know what you are looking for then its difficult to find it.
Thanks again.
Cheers Colin
-----Original Message----- From: Gustaf Neumann [mailto:neumann@wu-wien.ac.at] Sent: Mon 4/27/2009 7:24 PM To: Ross, Colin Cc: xotcl@alice.wu-wien.ac.at Subject: Re: [Xotcl] Send NULL arg to Class constructor
Colin Ross schrieb:
There are potentially 2 ways around this, however, I am unable to find information on if either of them are possible:
- Allow the passing in of a NULL argument
One can call arbitrary methods via configure. You just have just to provide your own method to handle such a cases, as the default parameter handling expect always exactly one argument.
========================== ::xotcl::Class Connect -parameter { {ssh} {ip} } Connect instproc telnet {} { my set telnet true } Connect instproc init {node args} { my instvar telnet ip
# provide a default if {![info exists telnet]} { set telnet false }
puts telnet=$telnet # .... }
Connect dev node -ip "127.0.0.1" -telnet ==========================
- Prevent the constructor parsing args so that I can parse my own
This is as well an option:
========================== ::xotcl::Class Connect
Connect instproc configure args { # puts stderr "wanna interpret $args" # # do what ever you want to do with the arguments..... # } Connect dev node -ip "127.0.0.1" -telnet ==========================
All the best -gustaf neumann
Ross, Colin schrieb:
Hi Gustaf - thanks so much for your prompt response. The "instproc configure" is perfect for what I need to do. I do appologise for not being able to find it in the documentation - I guess if you dont know what you are looking for then its difficult to find it.
One can alway ask XOTcl, what's going on. The tiny script below shows the call-order for creates and recreates.
best regards -gustaf neumann
==== create CALL ::C ::xotcl::Class->create c1 CALL ::C ::xotcl::Class->alloc ::c1 EXIT ::C ::xotcl::Class->alloc (::c1) CALL ::c1 ::xotcl::Object->configure EXIT ::c1 ::xotcl::Object->configure (0) CALL ::c1 ::xotcl::Object->init EXIT ::c1 ::xotcl::Object->init () EXIT ::C ::xotcl::Class->create (::c1) ==== recreate CALL ::C ::xotcl::Class->create c1 CALL ::C ::xotcl::Class->recreate ::c1 CALL ::c1 ::xotcl::Object->cleanup EXIT ::c1 ::xotcl::Object->cleanup () CALL ::c1 ::xotcl::Object->configure EXIT ::c1 ::xotcl::Object->configure (0) CALL ::c1 ::xotcl::Object->init EXIT ::c1 ::xotcl::Object->init () EXIT ::C ::xotcl::Class->recreate (::c1) EXIT ::C ::xotcl::Class->create (::c1) DONE
=================================================== package req XOTcl namespace import -force ::xotcl::*
Object instproc F args { puts "CALL [self] [self calledclass]->[self calledproc] $args" set r [next] puts "EXIT [self] [self calledclass]->[self calledproc] ($r)" return $r }
Class C -instfilter F -filter F
puts "==== create" C create c1
puts "==== recreate" C create c1
puts DONE
Object instproc F args { puts "CALL [self] [self calledclass]->[self calledproc] $args" set r [next] puts "EXIT [self] [self calledclass]->[self calledproc] ($r)" return $r }
Better, imho
Object instproc F args { puts "CALL [self] [self calledclass]->[self calledproc] $args" catch next r o puts "EXIT [self] [self calledclass]->[self calledproc] ($r)" return -options $o $r }
Good idea for tcl 8.5!
-gustaf neumann
iifat@mail.ru schrieb:
Better, imho
Object instproc F args { puts "CALL [self] [self calledclass]->[self calledproc] $args" catch next r o puts "EXIT [self] [self calledclass]->[self calledproc] ($r)" return -options $o $r }
Xotcl mailing list Xotcl@alice.wu-wien.ac.at http://alice.wu-wien.ac.at/mailman/listinfo/xotcl