record usage in tcl

This is a discussion on record usage in tcl within the TCL forums in Programming Languages category; Hi, all. I encounter the following issue when using tcllib record func: package require struct::record namespace import ::struct::record::* record define sw { name version } record define host { name ip {record sw new_sw} } sw msn_messenger msn_messenger configure -name "msn live messenger" -version "9.0.0" host pc pc configure -name "www.google.com" -ip "10.x.x.x" -sw msn_messenger here, it doesn't work. pc cget -name "www.google.com" -ip "10.x.x.x" -sw {-name {} -version {}} msn_messenger failed to pass its value into instance pc. any one knows how to fix it? i tried -sw [msn_messenger cget] doesn't work. i know it works in this way: ...

Go Back   Application Development Forum > Programming Languages > TCL

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-20-2008, 10:50 PM
jarodzz
Guest
 
Default record usage in tcl

Hi, all.

I encounter the following issue when using tcllib record func:

package require struct::record
namespace import ::struct::record::*

record define sw {
name
version
}

record define host {
name
ip
{record sw new_sw}
}


sw msn_messenger
msn_messenger configure -name "msn live messenger" -version "9.0.0"

host pc
pc configure -name "www.google.com" -ip "10.x.x.x" -sw msn_messenger

here, it doesn't work.

pc cget
-name "www.google.com" -ip "10.x.x.x" -sw {-name {} -version {}}

msn_messenger failed to pass its value into instance pc.

any one knows how to fix it?

i tried -sw [msn_messenger cget] doesn't work.
i know it works in this way:
pc.sw.name="msn live messenger"
pc.sw.version="9.0.0"

i am wandering if there's any other way i can seperate info , pass
through reference

thanks

Jarod ZZ

Reply With Quote
  #2  
Old 08-25-2008, 12:56 PM
Glenn Jackman
Guest
 
Default Re: record usage in tcl

At 2008-08-20 10:50PM, "jarodzz" wrote:
> Hi, all.
>
> I encounter the following issue when using tcllib record func:
>
> package require struct::record
> namespace import ::struct::record::*
>
> record define sw {
> name
> version
> }
>
> record define host {
> name
> ip
> {record sw new_sw}
> }
>
>
> sw msn_messenger
> msn_messenger configure -name "msn live messenger" -version "9.0.0"
>
> host pc
> pc configure -name "www.google.com" -ip "10.x.x.x" -sw msn_messenger
>
> here, it doesn't work.
>
> pc cget
> -name "www.google.com" -ip "10.x.x.x" -sw {-name {} -version {}}
>
> msn_messenger failed to pass its value into instance pc.
>
> any one knows how to fix it?
>
> i tried -sw [msn_messenger cget] doesn't work.
> i know it works in this way:
> pc.sw.name="msn live messenger"
> pc.sw.version="9.0.0"



I see no-one's replies yet. So unless you've figured it out, read on...

First of all, you have to use:
pc configure ... -new_sw...
^^^^^^
because that's how you've defined your host record.

Unless the maintainers of struct::record are willing to fix it, you
can't just pass in the name of an existing sub-record -- Tcl by itself
has no way to tell that "msn_messenger" is just a string or an existing
object name. You have to extract the fields of the sub-records
manually.

Using tcl 8.5, you can do:

pc configure \
-name "www.google.com" \
-ip "10.x.x.x" \
{*}[string map {- -new_sw.} [msn_messenger show]]

Using tcl 8.4, you need [eva] -- http://wiki.tcl.tk/1017

I would abstract this into a proc:

proc create_host_record {inst_name name ip new_sw_inst} {
set inst [::host $inst_name]
$inst configure -name $name -ip $ip
foreach member [record show members sw] {
$inst configure -new_sw.$member [$new_sw_inst cget -$member]
}
return $inst
}

create_host_record pc www.google.com 10.x.x.x msn_messenger



--
Glenn Jackman
Write a wise saying and your name will live forever. -- Anonymous
Reply With Quote
  #3  
Old 08-26-2008, 06:28 PM
bs
Guest
 
Default Re: record usage in tcl

On Aug 25, 9:56 am, Glenn Jackman <gle...@ncf.ca> wrote:
> At 2008-08-20 10:50PM, "jarodzz" wrote:
>
>
>
> > Hi, all.

>
> > I encounter the following issue when using tcllib record func:

>
> > package require struct::record
> > namespace import ::struct::record::*

>
> > record define sw {
> > name
> > version
> > }

>
> > record define host {
> > name
> > ip
> > {record sw new_sw}
> > }

>
> > sw msn_messenger
> > msn_messenger configure -name "msn live messenger" -version "9.0.0"

>
> > host pc
> > pc configure -name "www.google.com" -ip "10.x.x.x" -sw msn_messenger

>
> > here, it doesn't work.

>
> > pc cget
> > -name "www.google.com" -ip "10.x.x.x" -sw {-name {} -version {}}

>
> > msn_messenger failed to pass its value into instance pc.

>
> > any one knows how to fix it?

>
> > i tried -sw [msn_messenger cget] doesn't work.
> > i know it works in this way:
> > pc.sw.name="msn live messenger"
> > pc.sw.version="9.0.0"

>
> I see no-one's replies yet. So unless you've figured it out, read on...
>
> First of all, you have to use:
> pc configure ... -new_sw...
> ^^^^^^
> because that's how you've defined your host record.
>
> Unless the maintainers of struct::record are willing to fix it, you
> can't just pass in the name of an existing sub-record -- Tcl by itself
> has no way to tell that "msn_messenger" is just a string or an existing
> object name. You have to extract the fields of the sub-records
> manually.
>
> Using tcl 8.5, you can do:
>
> pc configure \
> -name "www.google.com" \
> -ip "10.x.x.x" \
> {*}[string map {- -new_sw.} [msn_messenger show]]
>
> Using tcl 8.4, you need [eva] --http://wiki.tcl.tk/1017
>
> I would abstract this into a proc:
>
> proc create_host_record {inst_name name ip new_sw_inst} {
> set inst [::host $inst_name]
> $inst configure -name $name -ip $ip
> foreach member [record show members sw] {
> $inst configure -new_sw.$member [$new_sw_inst cget -$member]
> }
> return $inst
> }
>
> create_host_record pcwww.google.com10.x.x.x msn_messenger
>



Glenn's correct in what he says. I'll just add that it was my
intentions to make:

pc configure -new_sw [msn_messenger cget]

work...but alas I guess I never got around to it. I can look into it
to see if I can make it work...
Reply With Quote
  #4  
Old 08-28-2008, 03:35 AM
jarodzz
Guest
 
Default Re: record usage in tcl

thank you all for the help.

I did it pretty much like Glen way.
eval pc.new_ws configure [sw cget]

thanks

Jarod ZZ
Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 08:55 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.