Sujet : failing to understand/use lambda De : m.n.summerfield (at) *nospam* gmail.com (Mark Summerfield) Groupes :comp.lang.tcl Date : 25. Jun 2025, 09:05:51 Autres entêtes Organisation : A noiseless patient Spider Message-ID :<103gakv$2l8ta$1@dont-email.me> User-Agent : Pan/0.154 (Izium; 517acf4)
I want to create a class which I can provide a "reporter" callable so it can notify me of what it is doing. Unfortunately, I can't get it to work and don't understand what I'm doing wrong. Below is a cut-down example to illustrate.
package require lambda 1
oo::class create Store { variable Filename variable Reporter }
oo::define Store constructor {filename {reporter ""}} { set Filename $filename if {$reporter eq ""} { set Reporter [lambda {message} {}] } else { set Reporter $reporter } }
oo::define Store method add {args} { puts "action: adding [llength $args] new files" $Reporter "adding [llength $args] new files" }
set str [Store new test.dat [lambda {message} { puts "reporter: $message" }]]
$str add one.txt two.txt three.txt
Expected output:
action: adding 3 new files reporter: adding 3 new files
Actual output:
action: adding 3 new files invalid command name "::apply {message { puts "reporter: $message" }}" while executing "$Reporter "adding [llength $args] new files"" (class "::Store" method "add" line 3) invoked from within "$str add one.txt two.txt three.txt"