Hi,
addressing Eric, you wrote:
>you can easily modify it to be non-SMC .
[snipped]
>links: make block! 0
>
>get-linked-pages: func [
> {retrieve information from the web}
> /local link
>][
[snipped]
>]
Eric's function:
>> get-linked-pages: func [
>> {retrieve information from the web}
>> /local links link
>> ][
>> links: []
>> ]
I cannot believe that we have been so drastically warned of the dire
dangers lurking in self modifying code, only to be shown that by moving a
local word, links, which references a block, to the global context, (about
three lines higher) outside of the function, we convert a hard-to-read,
dangerous self modifying code to the comfortable haven of
none-self-modifying safety and stability. If that is what all the noise
about self modifying code is about then Eric, by all means, write as much
self modifying code as you want.
This example would really be one that would have been worth of being left
as is. Say "Well self modifying code (smc) is not always dangerous. In the
case that you presented it is really not a problem.", instead of blindly
applying a "rule" without second thought.
On the other hand, what is actually being demonstrated? Is it really that
simple? Is that the answer? Replace the local block reference by a global
one, and you no longer have self modifying code? Have we indeed conquered
the dangers of self modification by moving 'links outside of the function's
local and into the global context? Let's see:
words: [ print add write open ]
values: [ 1 "hi" ftp://ftp.rebol.com 2 %temp.txt ]
links: []
smc?: func [] [
forever [
insert links pick words random 4
append links pick values random 5
append links pick values random 5
if error? try [reduce links] [print "hmmm, not so safe."]
clear links
]
]
Well, I left links global. So, is this self modifying code or not?
Elan