4 ms·
F-expressions are ancient (1960's era Lisp). newLisp dug them out from a Lisp landfill of discarded cruft; they do not chronologically belong in 1991. Tcl has t
by kazinator 12y ago
F-expressions are ancient (1960's era Lisp). newLisp dug them out from a Lisp landfill of discarded cruft; they do not chronologically belong in 1991. Tcl has them too, incidentally. That is to say, Tcl allows for user-defined interpretive operators that are very much like fexprs. Bash's eval can almost do something like this; an eval sees the surrounding scope. What's missing is the sugar to hide the eval.
"Text based fexpr":
gen_swap_code()
{
echo "local tmp=\$$1;"
echo "$1=\$$2;"
echo "$2=\$tmp;"
}
fun()
{
local a=3
local b=4
eval $(gen_swap_code a b) # sugar needed here
echo $a $b
}
$ fun
4 3
- jrapdx3 12y agoI've used Tcl and Scheme fairly extensively so it's interesting to compare them. Scheme has highly developed macros, and many implementations have non-hygienic macros along with syntax-rules. Most of the coders I know say it's rare to use anything other than the hygienic system, which is pretty easy to learn and quite powerful. Tcl doesn't have comparable macros, though some writers say in Tcl coding, the whole thing is like writing a bunch of macros anyway, but I'm not sure I buy that. I'm also not entirely clear what you meant by "user-defined interpretive operators ...". Current Tcl versions provide many facilities for specifying semantics of expressions (proc, ensembles, interpreters, lambdas, etc.) and the ability to redefine most any operator or built-in function if one so desires. The philosophy of "it means what I say it means" can lead to strange constructions, but that is a basis for describing Tcl as "macro-like" in its abundant, highly flexible features. The many ways it reflects Lisp/Scheme-like traits is truly part of its appeal.
- pnathan 12y agoTake a look at the vau-calculus work and the Kernel implementation. The author resurrected fexprs and studied their theory in depth.