
Schrödinger’s Tcl – Values that differ if you look at them - networked
https://github.com/aidanhs/schrotcl
======
nickodell
This is an impressively bad idea. Good work.

~~~
myrandomcomment
+1, up thumb or whatever the current thing is.

Having spent my life in networking tech, Tcl...please die.

~~~
ptero
I am primarily working on algorithms and _love_ Tcl for building simple,
robust prototypes. It is not perfect (I wish UDP support was a part of a core
language or standard library), but I use it surprisingly often. YMMV

------
zwischenzug
This guy's done many impressive things:

[https://aidanhs.com/](https://aidanhs.com/)

------
tyingq
Somewhat related, for Perl:

[http://search.cpan.org/~dconway/Quantum-
Superpositions-1.03/...](http://search.cpan.org/~dconway/Quantum-
Superpositions-1.03/lib/Quantum/Superpositions.pm)

~~~
forinti
I used this for my Quantum Countdown Sort:

[http://alquerubim.blogspot.com.br/2011/10/quantum-
countdown-...](http://alquerubim.blogspot.com.br/2011/10/quantum-countdown-
sort.html)

------
zerr
If I understand correctly, that looks like a cheating. I'd expect this to be
done purely in Tcl, without diving to C-level.

~~~
aidanhs
Author here: doing this in any language is probably going to depend on some
implementation details of the language repl, which may require dropping down
to a level where you have access to these internals - for example, I can't
think of a way you could achieve it in strict mode JS.

Python may well be able to do it with just the stdlib since it has excellent
debugging capabilities, but Tcl is relatively weak. You _might_ be able to do
something with `tcl::unsupported::getbytecode` and checking the frame level,
but this was just a throw-away novelty so I'm not particularly motivated to
find out.

~~~
Darkenetor
Alas, for JS function.caller on a getter isn't standard but will work
everywhere and should do it.

~~~
tyingq
I don't think it's that easy. If the context is making javascript output
something different in it's REPL for just "foo" vs "console.log(foo)", there's
other pieces you would need.

Like overriding a built-in type and getting function.caller into valueOf(). As
far as I can tell, JS doesn't let you just tweak valueOf(), you would have to
re-implement all of, for example, the String class.

~~~
Darkenetor
Reimplementing whole classes wouldn't have been a problem, just replace the
original ones with a proxy to a copy.

Luckily console.log calls are actually excluded from the callers stack, so the
only way is to change console itself. Just as evil if you also intercept
console methods logging and return the original ones, but less of a mess at
least.

------
yodsanklai
Unrelated but genuine question: what's the appeal of Tcl nowadays? are there
applications where it'd make sense to use Tcl?

~~~
tyingq
When it was popular, the 2 big drivers were:

\- The cross platform UI, Tk. Even if you didn't like Tcl, it was, for a
while, one of very few open source ways to get a UI that worked on a variety
of platforms. Many things, mostly the web, killed this need. Also, there are
Tk bindings for other languages now.

\- Dead simple, lightweight, way to embed a user facing scripting engine into
your application. Especially when the end user might be "technical", but not a
developer by trade. This is still a need, but it looks like people are turning
to Lua, Javascript, etc. Tcl is still embedded in a lot of hardware devices
though...cisco routers, F5 load balancers, etc.

Edit: Related trivia. TCL's inventor, John Ousterhout, was also one of the co-
creators of the raft consensus algorithm.

~~~
moomin
The thing is: I know what I think of TCL now, and I know what I thought of it
at the time. They're pretty different.

I think ultimately we've come the conclusion that whole design space isn't
that productive. Pervasive string expansion in an era of untrusted input
probably killed it for the web before it even began.

------
devdoomari
wow this is a super troll idea...

getters that change value... muahahaha

------
jamesdutc
I can do this in Python with my `rwatch` module.

    
    
        >>> from datetime import datetime
        >>> x = lambda: f'{datetime.now()}'
        >>> x
        <function <lambda> at 0x7f9f435e4510>
        >>> x()
        '2017-09-17 02:14:12.834957'
        >>> from sys import setrwatch
        >>> setrwatch({id(x): lambda f, o: o()})
    
        >>> x # look, ma: no parens!
        '2017-09-17 02:14:16.306198'
        >>> x
        '2017-09-17 02:14:17.734965'

~~~
aidanhs
One thing that may be non-obvious to people unfamiliar with Tcl is that it's
syntactically a shell-like language, i.e. functions are invoked with a space-
separated list of arguments and no parens. So `schro` on a line by itself
executes the function and `[schro]` is equivalent to `$(schro)` in shell.

~~~
tyingq
Only when you're using the REPL. They call it "interactive mode". [ls], for
example, will generate an error if you put that in a tcl script run non-
interactively.

 _Another common cause can be the difference between interactive and command
modes for Tcl. When you start up a Tcl interpreter, get a prompt, and type in
commands to Tcl, this is called interactive mode. In this mode, Tcl does a few
extra things for you. For instance, if you type ls, and you have no proc
called ls defined, Tcl will try to exec a command called ls. This sometimes
misleads a new Tcl user into thinking that Tcl has ls defined. "_ [1]

[1] [https://wiki.tcl.tk/1630](https://wiki.tcl.tk/1630)

