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

[REBOL] Re: Rebol Crash Was Mutability and sameness - a puzzle

From: lmecir:mbox:vol:cz at: 18-Jul-2001 12:54

Hi,
> 1) What is the answer to the puzzle?
In http://www.sweb.cz/LMecir/evaluation.html I wrote a function like: mut-equal?: function [ { a mutation discernibility test, should discern SERIES! values } a [series!] b [series!] ] [result] [ if not equal? length? :a length? :b [ return false ] ; perform a temporary mutation insert tail :a #"1" result: equal? length? :a length? :b ; perform the reverse mutation remove back tail :a result ] to use it instead of SAME? for SERIES! values, because SAME? crashes Rebol. BTW, I reported the crash to feedback on 23 July 2000 and received the tick #3509. If I try it for the given example, I get: a: [1] ; == [1] insert a reduce [a] ;== [1] b: [1] ;== [1] insert b reduce [b] ;== [1] mut-equal? a a/1 ;== true mut-equal? b b/1 ;== true mut-equal? a b ; == false This looks like the way how the SAME? function should have worked. The problem is, that there is still one case, where it doesn't produce a result we would want to get. See this: a: [1] b: tail a remove a length? b ; ** Script Error: Out of range or past end ; ** Where: halt-view ; ** Near: length? b same? b b ; ** Script Error: Out of range or past end ; ** Where: halt-view ; ** Near: same? b b mut-equal? b b ; ** Script Error: Out of range or past end ; ** Where: mut-equal? ; ** Near: if not equal? length? :a For the MUT-EQUAL? function to work more satisfactorily we need a better LENGTH? function. Here is my trial: indexz?: function [ series [series!] ] [orig-tail result] [ orig-tail: tail :series while [ error? try [result: (index? :series) - 1] ] [ if empty? head :series [ append :series #"1" ] append :series head :series ] clear :orig-tail result ] lengthz?: func [ series [series!] ] [ (indexz? tail :series) - (indexz? :series) ] now we can redefinne MUT-EQUAL? to use LENGTHZ? instead of LENGTH? and the results are: mut-equal?: function [ { a mutation discernibility test, should discern SERIES! values } a [series!] b [series!] ] [result] [ if not equal? lengthz? :a lengthz? :b [ return false ] ; perform a temporary mutation insert tail :a 1 result: equal? lengthz? :a lengthz? :b ; perform the reverse mutation remove back tail :a result ] a: [1] ; == [1] insert a reduce [a] ;== [1] b: [1] ;== [1] insert b reduce [b] ;== [1] mut-equal? a a/1 ;== true mut-equal? b b/1 ;== true mut-equal? a b ; == false a: [1] b: tail a remove a lengthz? b ; == -1 mut-equal? b b ; == true Regards Ladislav