Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Gadget error!

2 views
Skip to first unread message

arlie

unread,
Aug 17, 2006, 12:14:34 AM8/17/06
to
I tried my hands on Gadgets and found it very interesting but I was not
successfull in running the shorter version of Larry Smith.
http://wiki.tcl.tk/909

proc gadget { unused type methods } {
set typeproc {
set typeproc {
upvar @var self
@type self $method $args
}
upvar $var self
if { "$method" == "" } {
return $self
}
switch $method {
@methods
}
regsub @var $typeproc $var typeproc
proc $var { { method "" } args } $typeproc
}
regsub @type $typeproc $type typeproc
regsub @methods $typeproc $methods typeproc
proc $type { var method args } $typeproc
}

Running the test code I got this output:

gadget type number {
= {set self [expr $args]}
++ {set self [expr $self+1]}
round {set self [expr round($self)]}
sqrt {expr sqrt($self)}
}
gadget type int {
= {set self [expr round($args)]}
++ {incr self}
}
gadget type Array {
= - += {eval array set self $args }
-= {catch {unset self($args)}}
@ {set self($args)}
empty {expr [array size self]==0}
names {array names self}
{} {array get self}
}
gadget type List {
= {eval set self $args}
+= {lappend self $args}
@ {lindex $self $args}
empty {expr [llength $self]==0}
sort {lsort $self}
length {llength $self}
}
gadget type File {
= {set self [eval open $args]}
>> {upvar $args var; expr [gets $self var]+1}
<< {puts $self $args}
eof {eof $self}
open? {expr ![catch {seek $self 0 current}]}
close {close $self}
}

1 % number N = 1.5
2 % Array A
wrong # args: should be "Array var method args"
3 % List L = {foo bar}
4 % N = [N] * $N
5 % set A(cat) Katze
Katze
6 % A names
wrong # args: should be "Array var method args"
7 % L += grill
8 % L = [L sort]
9 % puts "[L] has [L length] elements, second is [L @ 1]"
{} has elements, second is
10 %
10 % File F = "c:/gadget.tcl"
11 % int i = 1
12 % while {[F >> line]} {
> puts [i]:$line
> i ++
> }
variable "var" already exists
13 % F close
14 %

Can anyone help me on this?

Regards,

Arlie

Dan Smart

unread,
Aug 20, 2006, 11:01:24 PM8/20/06
to
On 2006-08-17 00:14:34 -0400, "arlie" <arl...@gmail.com> said:

> I tried my hands on Gadgets and found it very interesting but I was not
> successfull in running the shorter version of Larry Smith.
> http://wiki.tcl.tk/909


The short version is not functionally the same as the full version and
exhibits a number of "mis-features", several of which you have
discovered. I started to fix them, and realised that I ought to be in
bed.

I'll try and take another look tomorrow.

Dan "In particular methods that return values, don't" Smart

arlie

unread,
Sep 11, 2006, 11:25:44 PM9/11/06
to

I actually tried the longer but I kept getting an error that's why I
tried the shoter version which seems to work.

Regards,

Arlie

0 new messages