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

[REBOL] Re: On mutability and sameness

From: lmecir:mbox:vol:cz at: 7-Jun-2001 11:02

The problem with the proof of DATE! mutability is, that it doesn't work. The same "proof" could e.g. prove, that integers are mutable: a: 11 bm [a/1] ; == 1 bm [a/1: 0] ; == 0 a ; == 9 block1: [11] block2: :block1 bm [block1/1/1] ; == 1 bm [block1/1/1: 0] ; == 0 block1/1 ; == 9 same? block2 block1 ; == true The bit-manipulation is described below: bit: func [ i [integer!] bitno [integer!] ] [ (to integer! i / (2 ** bitno)) // 2 ] bm: function [ block [block!] ] [path part-path integer bitno old-bit new-bit to-add len block-path] [ (path: copy first block) (block-path: to block! :path) len: (length? :block-path) - 1 (part-path: to path! copy/part block-path len) (integer: part-path) (bitno: last block-path) (old-bit: bit integer bitno) either path? :path [ return old-bit ] [ (part-path: load mold to set-path! copy/part block-path len) (part-path: first bind reduce [:part-path] first :path) new-bit: second block if old-bit <> new-bit [ to-add: to integer! 2 ** bitno if new-bit < old-bit [to-add: - to-add] part-path integer + to-add ] new-bit ] ]