Last active
November 30, 2023 21:04
-
-
Save hiiamboris/2eabe452bf9c90b41831b3566ab42074 to your computer and use it in GitHub Desktop.
An experiment in ad-hoc protection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Red [title: "an experiment with adhoc protection"] | |
;; problem is that once it's assigned to a deep-reactor, protection is lost | |
;; and we can only protect series, not maps or objects like this (limitation of ownership system) | |
;; REQUIRES https://codeberg.org/hiiamboris/red-common | |
#include %common/tree-hopping.red | |
guard: object [ | |
own: func [s [series!]] [modify s 'owned reduce [self s]] | |
on-deep-change*: func [o w t a n i p] [ | |
do make error! rejoin ["Attempt to modify protected value "mold/flat/part w 40] | |
] | |
] | |
block-walker: make-series-walker [any-block! any-object! map!] | |
protect: function [data [series!]] [ | |
guard/own data | |
foreach-node data block-walker [ | |
if series? :node/:key [guard/own :node/:key] | |
:node/:key | |
] | |
] | |
protect s: [1 2 3 [4] #(5 [6])] | |
try [append s 7] | |
try [append s/4 7] | |
try [append s/5/5 7] | |
?? s | |
append s 4 |
Author
hiiamboris
commented
Nov 30, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment