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

[REBOL] Re: in a function => was {Re: Re: to-char}

From: lmecir:mbox:vol:cz at: 14-Feb-2002 11:14

Q: Why, at the console does someblock: [] create a fresh block, but
> within a script function someblock: [] persists and needs to be > remedied by copy [], clear [] or make block! 123 statements?
I think, that this really needs an explanation. The simplest answer to this is, that the Rebol interpreter doesn't create a fresh block when it evaluates the expression: someblock: [] How come, that we get two blocks when we type in the following console expressions? ; Expression # 1: someblock-1: [] ; Expression # 2: someblock-2: [] ; Probing the sameness: same? someblock-1 someblock-2 ; == false The answer is, that the Rebol interpreter does more than evaluating expressions. Its first job is to create a Rebol value that it can evaluate. The normal order of the interpretation looks as follows: ; the interpreter reads the input, which can be simulated as follows input-line-1: "someblock-1: []" ; the interpreter transforms the input to a block loaded-line-1: load input-line-1 ; this was when the empty block got created: type? second loaded-line-1 ; == block! ; now (finally) the expression gets evaluated like do loaded-line-1 ; we can easily make sure, that no block has been created during the evaluation of the expression: someblock-2: someblock-1 ; let's evaluate the expression once more: do loaded-line-1 same? someblock-1 someblock-2 ; == true If we compare this to any "paradoxical" cases, we will find out, that the behaviour is the same, and the behaviour looks "inconsistent" just because a block is evaluated more than once, while being created just once. Does this shed some light on the subject? Regards Ladislav