Years Have Passed, Experience Has Been Gained
And today I was considering the question: why haven't I added an option to lock source to the script or module headers, yet?
The answer turns out to be an encouraging one. I haven't hit bugs that motivated me to think I'd ever need it.
I wrote a little bit of philosophy here: Why TRANSCODE Doesn't Lock Source (By Default)
I really believe that not being consistent between the console and scripts running should be heavily weighed. The console is kind of the place where you try out things and use as a sanity check when debugging.
Once I made peace that this was good and not bad:
>> x: [a b c]
>> append x 'd
== [a b c d]
I came to think that maybe the tricks like mutable access for statics were also good, not bad:
accumulate: func [x] [
accumulator: mutable []
return append accumulator x
]
>> accumulate 10
== [10]
>> accumulate 20
== [10 20]
In fact, we can use GETTER and SETTER technology in the "dual band" to level-up that method of defining statics in profound ways, where the variable uses the block for storage...without having to be the block itself:
accumulate: func [x] [
accumulator: static [1000 + 20]
return append accumulator x
]
>> accumulate 0
== 1020
>> accumulate 304
== 1234
STATIC simply runs the code, producing a recognizable pattern inside the block that it uses for storage of the lifted form of whatever you give it. (e.g. on the first run static transforms the block into [^static-storage] and then on successive runs it knows it's not the first run due to recognizing that pattern. It sets up the variable you are assigning as an ALIAS for that ^static-storage variable using dual-band tech (like what GETTER and SETTER use, but cheaper).
You couldn't do this kind of magic if the source were irrevocably locked.
Some have deemed it easy enough to learn to say
block: copy [](or even rationalize it as a feature: "it's a good thing, you can implement statics this way!")
My point is that once CONST is giving you your basic safety, the ability to write self-modifying code isn't necessarily bad. If you know that's what you're doing.
It's part of the madness but also part of the fun, and I'm fairly smitten with the above "magic statics". It's turned a bug into the feature it always desired to be. Though it's the first feature I've thought of to use the capability in a "good" way, that doesn't mean it will be the last...
So this leads me to think that maybe locking source shouldn't even be a formal option... if magic statics or other interesting features would be broken by it.