Home   Archive   Permalink



protect-system don't protect

protect-system cannot protect the words from being refinement.
    
     >> protect-system
     >> f: func [/repeat] [probe repeat]
     >> f
     == none ;repeat is gone
    


posted by:   Endo       30-Jul-2010/8:55:24-7:00



Endo, this example doesn't make sense to me. You created a function with the /repeat refinement, but you don't call it with that refinement.
    
>> f: func [/repeat] [probe repeat]
>> f/repeat
== true
>> protect protect-system
>> f/repeat
== true
>> f: 10
** Script Error: Word f is protected, cannot modify
** Near: f: 10
    
It works as I'd expect. Was there a typo in your function definition above?

posted by:   Nick       30-Jul-2010/12:18:04-7:00



Endo, protect-system has protected you from permanently changing the value of 'repeat.
    
But it has not stopped you locally reusing that word for another purpose.
    
When you pop out of your function, 'repeat will still have its original value.
    
You can also access that original value within the function like this (R2 code):
    
    source get in system/words 'repeat

posted by:   Sunanda       30-Jul-2010/14:34:37-7:00



@Nick: I was mentioning that why protect-system does not protect the repeat native. In my function repeat has no value (it is a refinement or local var., which should be protected, but it is not)
    
same situation for;
    
     >> f: has [repeat] [probe repeat]
     >> f
     == none
    
@sunanda: Yes I figured it out. But I was expecting that the repeat word will protected anyhow.
    
Not a big problem but can lead some problems like below, especially for beginners:
    
http://stackoverflow.com/questions/3339268/how-to-dynamically-use-compose-only/3341573#3341573


posted by:   Endo       2-Aug-2010/3:34:07-7:00



And PROTECT works on which context?
    
     >> o: context [x: 1 protect 'x]
     >> x: 4
     == 4 ;can be changed global x, which is ok
     >> o/x: 3
     == 3 ;not protected?
    
So x protected in which context? not global, not in O. A little bit confusing, how can I trust protect then?
    
(I know protect is a kind of hack, not a complete solution, I'm just thinking aloud)

posted by:   Endo       2-Aug-2010/4:20:30-7:00