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

[REBOL] Re: WYSIWYG programming

From: joel:neely:fedex at: 4-Nov-2000 9:50

Hi, Ladislav, Holger, and list! [ Sorry for the length, folks! I tried to be as brief as possible, but this is a non-trivial topic, and I have to think in small steps. ] [rebol-bounce--rebol--com] wrote:
> Hi, > > Holger Kruse tried to explain his notion of what is legal/defined > in Rebol:
... i.e., what we can reason about without having access to the implementation details of the interpreter.
> ... > > > a: [append a [+ 1] 1] > > > > The above expression modifies a block while it is being > > evaluated. AFAICT at this time the result of such an operation > > should be considered "undefined" and "implementation-dependent". > > In other words: don't do that ! > .... > > A "legal" way to rewrite the above REBOL expression... > > > > a: [append last a [+ 1] do [1]] > > > > This way the main block does not get changed during evaluation. > > Only the block referenced from the main block (the one > > initialized to be [1]) gets changed. That is completely legal.
...and your example seems to raise questions about that, but let's remember that evaluation is a sequential process and potentially recursive process. A slight paraphrase of the quoted email (taking out the example) gives us Holger's Rule: An evaluation of a block is undefined if that evaluation causes modification of the same block while an evaluation of that block is underway. Your example (same code, different layout, for benefit of Bears With Small Brain such as I) l: 30 f: does [l: l - 1 insert back tail last second :f [+ 1] if l > 0 [ f print 1 ] ] is actually subject to the same effect -- per the rewording above which talks about "an evaluation" of "a block". The difference is that the block to which the rule applies is not the body of F, but rather the block which is the last element of F. During all (but the chronologically last) evaluations of that block, we have [ f print 1 ... ] - === a modification of THAT block affects the doubly-underlined area during the underlined evaluation of F. Given the recursive design of F, there are in fact MULTIPLE pending continuations which evaluate the modified region of this particular sub-block. I'm going out on a limb, writing this as I'm thinking through the issue, but let's try a little experiment here, and "hide" the printing in a nested block. (I'll also eliminate the one prefix application of '+, which shouldn't matter.) This would give us l: 30 f: does [ l: l - 1 insert tail last last second :f [+ 1] if l > 0 [ f do [ print 1 ] ] ] With this change, we get
>> f
31 ... 31 (I won't bother to display all 29 output lines...) We can simplify the test by eliminating any issues relating to hidden use of the function type by rewriting as explicit blocks, l: 10 f: [l: l - 1 insert tail last f [+ 1] if l > 0 [do f print 1]] do f 11 11 11 11 6 5 4 3 2 versus l: 10 f: [l: l - 1 insert tail last last f [+ 1] if l > 0 [do f do [print 1] ]] do f 11 ... 11 versus (another pitch for execution only of immutable blocks?) f: [l: l - 1 insert tail last f [+ 1] if l > 0 [do copy/deep f print 1]] l: 10 do copy/deep f 9 8 7 6 5 4 3 2 1 We might imagine that the issue is that evaluation proceeds INTO a region of the same block which has been modified during a pending evaluation (i.e., strengthen the test of Holger's Rule to apply only to "forward" modifications). A test of this conjecture (I'd hardly dignify it by calling it a "theory" at this point!) is to flip the loci of evaluation and modification around, something like this... l: 10 f: [print 1 l: l - 1 insert next f [1 +] if l > 0 [do f] ] do f 1 2 3 4 5 6 7 8 9 10 == none
>> f
== [print 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 l: l - 1 insert next f [1 +] if l > 0 [do f] ] We seem to be able to "get away with" that change, but that may only be because (some!) pending evaluations utilize a direct reference to pending expressions rather than a block+offset description, whose meaning would have been changed by the insertion. Now, I suspect that Holger is still cheating a bit. (No offense, Holger, but you're working from a position of more knowledge than we Small-Brained Bears have!) I wonder if his rule might be not conservative enough (e.g., what happens if an interpreter is looking ahead at referenced blocks as well as "in-line" words and scalar values...) Of course, I'd prefer that a knowledgable authority "cheat" and give us a specification which the REBOL interpreter is committed to honoring! Therefore, I'm comfortable with Holger's Rule as a preventer of Monsters. Of course, it's better to design with it in mind (by trying to prevent such cases from arising) than to determine after-the-fact whether it applies (in fact, I suspect it to be as computationally infeasible as the Halting Problem!) -jn-