[REBOL] Re: Fun with literal blocks!
From: joel:neely:fedex at: 28-Oct-2000 18:12
Thanks for the very interesting techniques. I want to think carefully
about them before making any comments. (I might embarrass myself it
I didn't think hard enough!)
Ladislav Mecir wrote:
> Hi Joel,
> > If you mean
> > "Should Fibon be written as self-modifying code?"
> > then (see my answer to Ladislav's comments on the same post) I'd
> > answer that there are certainly some pros and cons to SMC. It is
> > certainly a technique that should be used with care. OTOH, there
> > are some very elegant things that can be done with functions that
> > either:
> > * maintain persistent state via SMC
> > (less overhead vs full-blown objects),
...and I'd be happy to have this list extended with techniques such
as those you supplied.
> I think, that you are mixing two issues here. One is a use of SMC
> and the second one is the ability of a function to maintain its
> state or to do other useful things...
Well, again, I simply think of SMC as being one (of a growing number,
thanks to you and others) way to maintain internal "state". Clearly
the use of objects is an important technique, whether explicitly
created, or supplied by an "object factory', etc.
> The most general version of the state-maintaining technique is a
> possibility to create a function having static local variables...
I tend to draw a distinction between:
* code such as Fibon, which modifies values stored inside itself,
but which only uses those values as stored state data, and
* monsters such as the following, which modify portions of them-
selves which then will actually be evaluated in a CODE-like
manner, and which therefore stress our minds (and, apparently,
the REBOL interpreter!) much harder.
>> a: [append a [+ 1] 1]
== [append a [+ 1] 1]
>> repeat i 30 [print [i do a]]
Note: 7 skipped, 14 duplicated, 15 skipped, 30 duplicated...
Something VERY bizarre is going on here. Is this a bug or an
undocumented feature? ;-)