7 ms·
I implemented something very similar a while ago, it's indeed too bad it's not built-in. I don't think you need such a "quasiquote" function, [list {*}$args] ca
by tracnar 1y ago
I implemented something very similar a while ago, it's indeed too bad it's not built-in. I don't think you need such a "quasiquote" function, [list {*}$args] can escape a single command, and then it's a matter of joining multiple commands using a newline. IIRC that's how I did it.
I also had further fun with wrapping "proc" by implementing a "pyproc" which called out to Python while looking like a normal Tcl proc.
- BoingBoomTschak 1y agoThe problem is mainly the square brackets that force one to go through strings, in my experience. Can't build something like "set foo [cmd $bar]" purely by using [list ...] shenanigans, since list will quote stuff you don't want quoted.
- tracnar 1y agoTrue, I believe I mostly worked around that limitation by splitting off quoted from unquoted code into separate commands. So in your example "[cmd $bar]" would be in a separate unquoted command, probably putting it in a temporary variable, which can cause problems as it's hard to have a private scope when doing metaprogramming. You can also use "[list]" in the middle of code, but it gets more error prone, for example "set foo \[[list cmd \$bar]\]" For sure there is a lack of proper "code as data" constructs in Tcl, like you would find in Lisp.
- BoingBoomTschak 1y agoActually, you can see the "backslash hell" version here if you want to estimate the clarity gains: https://git.sr.ht/~q3cpma/tcl-misc/tree/f613898c3dcfa3ca958aab9fe5be959fc45171dd/item/util.tcl#L59 https://git.sr.ht/~q3cpma/tcl-misc/tree/f613898c3dcfa3ca958a...