how to pass a bound method to fileutil::traverse as a -prefilter

Liste des GroupesRevenir à cl tcl 
Sujet : how to pass a bound method to fileutil::traverse as a -prefilter
De : m.n.summerfield (at) *nospam* gmail.com (Mark Summerfield)
Groupes : comp.lang.tcl
Date : 23. Jul 2025, 12:11:39
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <105qg1b$tc0j$1@dont-email.me>
User-Agent : Pan/0.154 (Izium; 517acf4)
I want to pass a bound method to fileutil::traverse as a -prefilter.
I'm using `lambda` but it doesn't help. I can't work out what I'm
doing wrong based on the error output.

Below is a cut-down version of the code, followed by the error output.
To test it run as, say, `tclsh9 find.txt /tmp`

### Code

package require fileutil::traverse
package require lambda 1
package require textutil

proc main {} {
    set config [Config new]
    $config folders $::argv
    process $config
}

proc process config {
    set pre_filter [lambda {ignore dirname} {
                    dir_filter $ignore $dirname
                } [$config ignore]]
    foreach dir [$config folders] {
        fileutil::traverse iter -prefilter $pre_filter
        $iter foreach filename {
            puts $filename
        }
        $iter destroy
    }
    puts [$config to_string] ;# TODO delete
}

proc dir_filter {ignores dirname} {
    for ignore $ignores {
        if {[string match -nocase $ignore $dirname]} { return false }
    }
    return true
}

oo::class create Config {
    variable Ignore
    variable What
    variable Folders
}

oo::define Config constructor {} {
    set Ignore [list test*.* zOld]
    set What ".tcl"
    set Folders [list]
}

oo::define Config method ignore {{ignore ""}} {
    if {$ignore ne ""} { set Ignore $ignore }
    return $Ignore
}

oo::define Config method what {{what ""}} {
    if {$what ne ""} { set What $what }
    return $What
}

oo::define Config method folders {{folders ""}} {
    if {$folders ne ""} { set Folders $folders }
    return $Folders
}

oo::define Config method to_string {} {
    return "Config Ignore=$Ignore What=$What Folders=$Folders"
}

main

### Error

$ ./find.tcl /tmp/
unknown option "::apply {{ignore dirname} {
                    dir_filter $ignore $dirname
                }} {test*.* zOld}"
    while executing
"$self configurelist $args"
    (procedure "::fileutil::traverse::Snit_constructor" line 6)
    invoked from within
"::fileutil::traverse::Snit_constructor ::fileutil::traverse ::fileutil::traverse::Snit_inst1 ::iter ::iter -prefilter {::apply {{ignore dirname} {
   ..."
    ("eval" body line 1)
    invoked from within
"eval [linsert $arglist 0  ${type}::Snit_constructor $type $selfns $instance $instance]"
    (procedure "RT.ConstructInstance" line 9)
    invoked from within
"RT.ConstructInstance $type $selfns $name $args"
    (procedure "::snit::RT.type.typemethod.create" line 45)
    invoked from within
"fileutil::traverse iter -prefilter $pre_filter"
    (procedure "process" line 6)
    invoked from within
"process $config"
    (procedure "main" line 4)
    invoked from within
"main"
    (file "./find.tcl" line 66)

Date Sujet#  Auteur
23 Jul12:11 o how to pass a bound method to fileutil::traverse as a -prefilter1Mark Summerfield

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal