fork(1) download
  1. # Experimenting with callbacks. (1.00)
  2. # @see sNGdfp
  3.  
  4. proc lambda {capturedList args body} {
  5. return [proc {} $args \
  6. [concat [list foreach {name value} $capturedList {
  7. set $name $value }] \; $body]]
  8. }
  9.  
  10. proc any {a pred} {
  11. foreach x $a {
  12. if {[$pred $x]} {
  13. return true
  14. }
  15. }
  16. return false
  17. }
  18.  
  19. proc stringAnyIs {class s} {
  20. return [any [split $s {}] [lambda [list class $class] {c} {
  21. return [string is $class $c]
  22. }]]
  23. }
  24.  
  25. while {[gets stdin line] >= 0} {
  26. foreach class {space graph punct} {
  27. puts "'$line' has $class: [stringAnyIs $class $line]"
  28. }
  29. }
Success #stdin #stdout 0.01s 5276KB
stdin
     
abcde
#$%^&
ab de
#$ ^&
stdout
'     ' has space: true
'     ' has graph: false
'     ' has punct: false
'abcde' has space: false
'abcde' has graph: true
'abcde' has punct: false
'#$%^&' has space: false
'#$%^&' has graph: true
'#$%^&' has punct: true
'ab de' has space: true
'ab de' has graph: true
'ab de' has punct: false
'#$ ^&' has space: true
'#$ ^&' has graph: true
'#$ ^&' has punct: true