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

[REBOL] Bug! - 'second on object containing ONE hash! has TWO hash! !! Re:

From: kgd03011:nifty:ne:jp at: 6-Oct-2000 15:36

Hi Larry,
>It is interesting that second shows the actual hash as having the value >[...] which is the new indicator for a recursive block, hash, list, object, >etc. Probe shows the actual value, as does > >>>mold second second o > >It would be nice to hear from RT as to whether the [...] in your example is >the intended behavior.
It seems the algorithm for detecting recursive blocks is a little too simple-minded. When REBOL is representing a value, anytime it re-encounters the same block, the contents of that block are replaced with [...] . So some things have become a little weird: /Core 2.3 :
>> head insert/only/dup [] [] 5
== [[] [] [] [] []] /View 0.10.38 :
>> head insert/dup/only [] [] 5
== [[] [...] [...] [...] [...]] But if you have the same block alternating within another block the ... don't show: /View 0.10.38 :
>> b: [[1] [2]]
== [[1] [2]]
>> bb: []
== []
>> insert/dup bb b 4
== []
>> bb
== [[1] [2] [1] [2] [1] [2] [1] [2]] Of course these really are the same blocks:
>> b/1/1: 3
== [3]
>> bb
== [[3] [2] [3] [2] [3] [2] [3] [2]]
>Here is a related fun puzzle ;-) > >>> b: [1 2] >== [1 2] >>> b/2: b >== [1 [...]]
I'm not quite sure what the puzzle is ... The ... here is only an artifact used to prevent stack overflow. AFAIK this hasn't been possible until the recent experimental releases. It causes a stack overflow with /Core 2.3 .
>>> save %junk.txt b >>> b2: load %junk.txt >== [1 [...] >] >>> second b >== [1 [...]] >>> second b2 >== [...] >>> first second b >== 1 >>> first second b2 >== ...
The ... here is now a word!
>So it is possible to create a block which cannot be saved and loaded. This >may be a bug in load. Only RT knows what lurks in the heart of REBOL. ;-)
Lots of things get converted to words when you save and load them: TRUE, FALSE, NONE and all the datatypes. Of course you can often reduce a block to get the original values back. '... doesn't usually have any value, and even if LOAD or REDUCE recognized this as a recursed block, it would often be impossible to tell at what level a block was being recursed. Also, LOAD has never been able to deal with the distinction between blocks that are the same, and those that are merely equal. Both same and identical blocks wind up as merely equal. And now there will be some same blocks reloaded with an extraneous word in them.
>Cheers >-Larry > >PS You can make a recursive block which cannot be saved and loaded. >The line: > >>>o/self/self/self/self/self/self/h > >certainly indicates recursion. What is curious is that the ... shows up for >the value block of the hash and has never showed up for the obvious >recursive self-reference of 'self.
As you explained to Andrew, mold avoids representing 'self and its value. With the ... convention, you could represent an object as: make object! [ self: make object! [ ... ] a: "some value" ] but that would make problems for LOAD. Eric