How to protect object fields in Rebol?

O: [a: 1 b: 2]
Protect 'O

protects only the O character, not O / a. How do I also protect O / a?

Thanks.

+3
source share
1 answer

Well, your example doesn't actually use an object. This is just a block called O. So:

O: reduce [a: 1 b: 2]
protect [o a b] ; assuming you wanted to protect b as well

Now, if you want to create a real object, you should do it like this:

O: make object! [
    a: 1
    b: 2
    protect [a b]
]
protect 'O

R3 will have additional interesting things that you can do with PROTECT, for example PROTECT/HIDE.

+1
source

Source: https://habr.com/ru/post/1712989/


All Articles