6 ms·
You can use proc command in Tcl to replace existing commands and procedures, which gives you the possibility to implement different behaviour. An example that
by kbr2000 7y ago
You can use proc command in Tcl to replace existing commands and procedures, which gives you the possibility to implement different behaviour.
An example that shows this:
~$ tclsh
% rename while origwhile
% proc while {args} {
puts stderr "Debug: invoked while with arguments $args"
# do anything you want here
uplevel 1 origwhile $args
}
% set i 0
% while {$i < 5} {puts $i; incr i}
Debug: invoked while with arguments {$i < 5} {puts $i; incr i}
0
1
2
3
4
%
And in Forth the dictionary is searched backwards for a word (starting with the most recent definitions), so you can similarly override words. Powerful!
- yesenadam 7y agoIn Forth, not just new words - everything (except the stacks, I think) - as if in C you could redefine not only every reserved word but every symbol - (, ), +, *, ->, %, &, [,],{,},# = etc etc. Also there are 'defining words' (akin to typedef, struct, enum etc) and you can define new defining words... And so turn Forth into any other language you wanted, if you were crazy enough..