Rebol has a Protect function which allows your function to be redefined either by yourself or someone else. For example, I have a bunch of libraries that I preload in user.r like the zip library, when testing another script, I don’t want that my own zip library risks to be overrided so I can use the protect function like this:
protect 'zip
The problem is I may myself need this library somewhere else by reloading it in some script and this will create this disgracefull interruption:
** Script Error: Word zip is protected, cannot modify
So as to avoid this problem, I have created this set-once function:
set-once: func[word [word!] value /verbose][
if/else error? error: try [set word value][
disarm error
if verbose [
print [ "cannot set" word]
none
]
][value]
]
This function will either return the value or none if the word is protected:
>> set-once/verbose 'zip "test"
cannot set zip
== none
>>
This doesn’t solve all problems and the best would be to override the set function but it will be for next time as it’s too tedious to do so in current version of Rebol when there are multiple refinements (see here).
















No comments yet.