Skip to content
Turtle Kitty edited this page Jan 28, 2016 · 1 revision

seal

This procedure make objects immutable. By default, it wraps the object sent to it in another, forwarding all messages except those ending with a bang (!) - by convention, these are mutators.

The programmer can instruct seal to hide other messages with the hide: keyword.
The type name can be shadowed with new-type:.
The secret: option allows the sealed object to be unsealed at a later time.

(def r (: x 1 y 2))
r.messages
    -> (view size clone to-bool get put set! rm del! has? apply keys values pairs to-list to-opt to-text merge fold reduce map filter)

(def sealed-r (seal r))
sealed-r.messages
    -> (type unseal has? pairs view put to-opt merge values to-bool map to-list filter to-text size rm apply reduce get clone fold keys)

(def secret-r (seal r hide: '(get put rm has? keys values) new-type: 'secret secret: "1337h4x0r"))
secret-r.messages
    -> (unseal type apply pairs clone to-list size to-text to-bool filter to-opt merge reduce map view fold)

sealed-r.type
    -> record

sealed-r.set!
    -> null

secret-r.type
    -> secret

secret-r.keys
    -> null

(secret-r.unseal "password?")
    -> (Uncaught error:  (ACCESS-DENIED))

(def unsealed-r (secret-r.unseal "1337h4x0r"))
unsealed-r.messages
    -> (view size clone to-bool get put set! rm del! has? apply keys values pairs to-list to-opt to-text merge fold reduce map filter)

(sealed-r.unseal "???")
    -> (Uncaught error:  (ACCESS-DENIED))
Clone this wiki locally