Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

TCL has a feature which to me qualifies as a total "What the hell were they thinking?", not unlike the COME FROM command from Brainfuck, except, in a real language.

That statement is upvar [1]. Read its description and despair.

[1] https://www.tcl.tk/man/tcl/TclCmd/upvar.html



The upvar (and uplevel) mechanism is essential for the extensibility of the language and tremendously useful for creating new control constructs.

Think of it as similar to "passing value by reference", for example when you pass the address of a variable in C/C++.


As the decr example at the very bottom suggests, it’s to allow the equivalent of passing a mutable reference into a function in other languages.

upvar and uplevel seem scary/strange when you read about them, but once you start using them in code, they feel perfectly suited for the task.


I love upvar and uplevel.

I once did a web search to see whether there was an equivalent in PHP. I found a thread in at PHP forum, which told a poster that he was a bad person for wanting such a thing. (This was a long time ago, so perhaps I exaggerate. But they did say that PHP was just fine without it.)


As a fan of immutability (edit: I suppose I should say rather referential transparency is more relevant here), that horrifies me, but at the same time I have to commend the ingenuity.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: