[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Quiz question
- From: Dirk Laurie <dirk.laurie@...>
- Date: Sat, 29 Mar 2014 06:51:43 +0200
2014-03-28 22:28 GMT+02:00 Coroutines <coroutines@gmail.com>:
> I do understand the perks to keeping local references, but I just get
> annoyed when I'm making a modification to the original global
> reference from elsewhere and third-party code doesn't make use of it
> :-) I like being able to affect the world, haha
In the early 1980's I went through a brief phase as a Forth addict.
(I was also an APL addict. Anything wildly different from Fortran,
which dominated my day job, was enticing.) In Forth you can write
the following program.
THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.
It would depend on the words having been defined earlier, and the
user can redefine any and still use this code. But — and this is the
point I laboriously making — if you redefine "OVER", which is one
of the most basic Forth words, you will confuse everybody.
In Lua, too, I went through a year of being enamoured of monkey
patching. Because it was there. My table.concat applied tostring
and allowed functions as separators (one call to table.concat could
reformat a chapter), my table.insert allowed me to insert a whole
vararg list of things, etc.
I came to realize, after some unpleasant sessions of debugging,
that when someone writes string.match it is not too unlikely that
what he really wants may be ... well, string.match.
Lua has object notation. So what I do now, haha, is to make
a whole module of routines named exactly like the system
libraries, and then one can enable the whole lot in one go:
debug.setmetatable("",{__index = mystring}). Then string.match
is still string.match, but ("typed_in"):match covertly also scans
the input for the string "bazinga" and if found immediately sends
an e-mail denouncing the user to the CIA.
And the use of the debug library (which I hope is still intact,
of course) alerts the reader of the program that there is some
monkey business afoot.