## Brings some quantum-like chaos to any Tcl program ## Author: Kristoffer Lawson, setok@setok.co ## Idea from Tiago Roberti Sampaio set ChaosFactor 0.5 set SchrodingerBody { ::chaos::if {rand() < $::ChaosFactor} { ::chaos::return } } proc chaosify {cmd} { rename $cmd ::chaos::$cmd proc $cmd {args} " $::SchrodingerBody ::chaos::uplevel \[::chaos::list ::chaos::$cmd \{*\}\$args\] " } foreach cmd [info commands] { if {$cmd ne "if" && $cmd ne "proc" && $cmd ne "rename" && $cmd ne "global" && $cmd ne "chaosify" && $cmd ne "set"} { chaosify $cmd } } rename if ::chaos::if proc if {args} " $::SchrodingerBody ::chaos::if \{*}\$args " rename global ::chaos::global proc global {args} " $::SchrodingerBody ::chaos::global \{*}\$args " rename rename ::chaos::rename proc rename {args} " $::SchrodingerBody ::chaos::rename \{*}\$args " ::chaos::rename proc ::chaos::proc ::chaos::proc proc {name arguments body} { set body $::SchrodingerBody$body ::chaos::proc $name $arguments $body } #chaosify puts set animal cat puts $animal puts $animal for {set i 0} {$i < 10} {incr i} { puts "The Internet is for $animal videos" } proc test {} { puts horse } test test test test test
arjen - 2017-12-08 08:53:03Somewhat pedantic comment: Schroedinger did not invent the idea of chaos - contrary to the suggestion made here, quantum mechanics is not a theory about chaos, but instead a very precise theory about possibilities that take shape once the system is observed. Perhaps rename this to LorentzTcl, as Edward Lorentz (so not Hendrik Lorentz, who is in fact connected to quantum mechanics) was one of the first to describe the chaotic dynamics of a seemingly ordinary system.
arjen - 2017-12-08 10:22:38On the other hand, now that I have seen it at work, the effect is really quantum-like, not chaotic though. How about introducing boson- and fermion-like commands? (Just kidding)