proc min {a b} { if {$a <= $b} {return $a} {return $b} } proc max {a b} { if {$a <= $b} {return $b} {return $a} } proc foreach_ {n FromTos} { while {$n} { set substs {} set indexTo 1 foreach {From To} $FromTos { while {[llength $From] > 0} { lappend substs [lindex $From 0] [lindex $To 0] # Tira o from e o to processados das listas dos caras # que falta processar. set From [lrange $From 1 end] set To [lrange $To 1 end] } # Devolve o "To" comido para a (nova) lista FromTos; # avan‡a o ¡ndice que diz de onde o "To" vem. set FromTos [lreplace $FromTos $indexTo $indexTo $To] incr indexTo 2 } lappend retlist $substs incr n -1 } return $retlist } # Teste: puts [foreach_ 2 {{a b} {a1 b1 a2 b2} c {c1 c2}}] proc mysubst_ {str substs} { foreach {from to} $substs { regsub -all $from $str $to str } return $str } proc mysubst {str args} { mysubst_ $str $args } proc runsubst0 {str args} { uplevel #0 [mysubst_ $str $args] } proc varsubst0 {str args} { uplevel #0 concat [mysubst_ $str $args] } # "for each substituted version run (at uplevel #0)" proc fesvr0 {code n args} { foreach substs [foreach_ $n $args] { uplevel #0 [mysubst_ $code $substs] } } # # Rotinas que eu uso pra entender # como as substitui‡äes funcionam: # proc id {x} { return $x } proc shev {string} { puts $string puts [concat " => " [eval $string]] } proc prev {args} { puts \{[join $args \}\ \{]\} } proc preve {args} { puts \{[join $args \}\ \{]\} eval $args } set PREV preve proc v@ {varname default} { upvar #0 $varname var if {[info exists var]} {puts ex; return $var} {puts nex; return $default} } # Globais: oldx oldy deltax deltay set oldx 0 set oldy 0 proc getdeltas {newx newy} { global oldx oldy deltax deltay set deltax [expr $newx - $oldx] set deltay [expr $newy - $oldy] set oldx $newx set oldy $newy return "$deltax $deltay" } # (find-tkexfile "items.tcl" "<3>") # O retƒngulo ‚ chamado de "area". # Como eu nÆo scrollo eu tirei os [canvasx ...], [canvasy ...]. # set corner1 "0 0" # set corner2 "0 0" # bind .c { {%x %y}} # bind .c <2> "anchorRect $c %x %y" # bind .c "dragRect $c %x %y" # bind .c "set B2Down 0" # proc anchorRect {c x y} { # global RectX1 RectY1 B2Down # puts "anch $x $y" # # if {$B2Down == 0} { # set RectX1 $x # set RectY1 $y # $c delete Rect # set B2Down 1 # # } # } # proc dragRect {c x y} { # global RectX1 RectX2 RectY1 RectY2 # puts "drag $x $y" # .c delete Rect # .c create rect $RectX1 $RectY1 $x $y -tag Rect -outline black # set RectX2 $x # set RectY2 $y # } # (find-fline "/usr/local/lib/tcltutor/lessons/") # (find-fline "/usr/src/TclTutor/") # (find-esfile "tcl.e" "# TclTutor") # (find-fline "/usr/local/bin/QuizChecker.tcl") # (find-fline "/usr/local/bin/TclTutor.tk") # (find-fline "/usr/local/bin/TclTutor.tk" "Widgets.tk") # (find-fline "/usr/local/bin/TclTutor.tk" " RunCode ")