Skip to content

A peer-to-peer stack for code collaboration

Clearer radicleisation of documented environment variables. (#184)

James Haydon03086502b645
diff --git a/exe/ReferenceDoc.hs b/exe/ReferenceDoc.hs
index 22f9de8..8cfa9e8 100644
--- a/exe/ReferenceDoc.hs
+++ b/exe/ReferenceDoc.hs
@@ -101,7 +101,7 @@ main = do
, "validator/and", "validator/or", "validator/key", "validator/keys"]
crypto = ["verify-signature", "default-ecc-curve", "gen-key-pair!", "gen-signature!"]
chainTools =
- [ "new-chain", "eval-in-chain", "enter-remote-chain", "update-chain", "add-quit", "add-send"
+ [ "new-chain", "@var", "eval-in-chain", "enter-remote-chain", "update-chain", "add-quit", "add-send"
, "load-chain", "pure-prelude-files", "pure-prelude-code", "store-exprs", "eval-fn-app"
, "state-machine-eval", "state-machine-input", "state-machine-new-trans"
, "state-machine-agree", "state-machine-disagree", "simple-trans", "update-chain-ref"]
diff --git a/rad/chain.rad b/rad/chain.rad
index 88aa3df..c35ab68 100644
--- a/rad/chain.rad
+++ b/rad/chain.rad
@@ -5,6 +5,11 @@
;; == base-eval')
;; - A sequence of inputs.
+(def @var
+ "A lens for variables in states of chains."
+ (fn [ident]
+ (... [(@ :env) (@ ident) (@ :val)])))
+
(def new-chain
(fn [url]
{:state (pure-env)
@@ -20,7 +25,7 @@
(def eval-in-chain
(fn [expr chain]
- (def chain-eval (view (... [(@ :state) (@ :env) (@ 'eval) (@nth 1)]) chain))
+ (def chain-eval (view (.. (@ :state) (@var 'eval)) chain))
(def x (chain-eval expr (lookup :state chain)))
(def result (nth 0 x))
(def new-state (nth 1 x))
@@ -122,7 +127,7 @@
(def store-exprs
(fn [evalfn]
(fn [expr env]
- (def env_ (over (... [(@ :env) (@ '_inputs) (@nth 1)]) (fn [x] (add-right expr x)) env))
+ (def env_ (over (@var '_inputs) (fn [x] (add-right expr x)) env))
(evalfn expr env_ ))))
(document 'store-exprs
@@ -134,8 +139,8 @@
(fn [oeval]
(fn [expr env]
(if (eq? expr :send)
- (do (def inpl (... [(@ :env) (@ '_inputs) (@nth 1)]))
- (def chainl (... [(@ :env) (@ '_cur-chain) (@nth 1)]))
+ (do (def inpl (@var '_inputs))
+ (def chainl (@var '_cur-chain))
(send! (view chainl env) map (view inpl env))
(def env_ (set inpl [] env))
(list :ok env_))
@@ -152,13 +157,13 @@
(def chain (load-chain url))
(def chain-state (lookup :state chain))
(def mod-state1
- (over (@ :env) (fn [x] (insert '_inputs [:Nothing []] x)) chain-state))
+ (over (@ :env) (fn [x] (insert '_inputs {:val []} x)) chain-state))
(def mod-state2
(over (@ :env)
- (fn [x] (insert '_cur-chain [:Nothing (lookup :url chain)] x))
+ (fn [x] (insert '_cur-chain {:val (lookup :url chain)} x))
mod-state1))
(def mod-state3
- (over (... [(@ :env) (@ 'eval) (@nth 1)])
+ (over (@var 'eval)
(fn [x] (add-send (add-quit env x)))
mod-state2))
(list :ok mod-state3)))
diff --git a/src/Radicle/Internal/Core.hs b/src/Radicle/Internal/Core.hs
index e8330cf..c5f0306 100644
--- a/src/Radicle/Internal/Core.hs
+++ b/src/Radicle/Internal/Core.hs
@@ -533,9 +533,11 @@ instance (CPA t, FromRad t a) => FromRad t [a] where
Vec xs -> traverse fromRad (toList xs)
_ -> Left "Expecting list"
instance CPA t => FromRad t (Doc.Docd (Annotated t ValueF)) where
- fromRad v = do
- (d, v') <- fromRad v
- pure (Doc.Docd d v')
+ fromRad (Dict d) = do
+ val <- kwLookup "val" d ?? "Expecting `:val` key"
+ doc <- traverse fromRad (kwLookup "doc" d)
+ pure (Doc.Docd doc val)
+ fromRad _ = Left "Expecting a dict."
instance FromRad Ann.WithPos (Env Value) where
fromRad x = case x of
Dict d -> fmap (Env . Map.fromList)
@@ -589,7 +591,9 @@ instance (CPA t, ToRad t a) => ToRad t [a] where
instance (CPA t, ToRad t a) => ToRad t (Map.Map Text a) where
toRad xs = Dict $ Map.mapKeys String $ toRad <$> xs
instance CPA t => ToRad t (Doc.Docd (Annotated t ValueF)) where
- toRad (Doc.Docd d v) = toRad (d, v)
+ toRad (Doc.Docd d_ v) = Dict $ Map.fromList $ ( Keyword (Ident "val"), v) : case d_ of
+ Just d -> [ (Keyword (Ident "doc"), toRad d) ]
+ Nothing -> []
instance ToRad Ann.WithPos (Env Value) where
toRad x = Dict . Map.mapKeys Atom . Map.map toRad $ fromEnv x
instance ToRad Ann.WithPos (Bindings m) where