Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Fun with literal blocks!

From: joel:neely:fedex at: 28-Oct-2000 18:12

Hi, Ladislav, 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]]
1 1 2 2 3 3 4 4 5 5 6 6 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 14 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 30 Note: 7 skipped, 14 duplicated, 15 skipped, 30 duplicated... Something VERY bizarre is going on here. Is this a bug or an undocumented feature? ;-) -jn-