A peer-to-peer stack for code collaboration
Refactor print! in terms of put-str! and show. Other small cleanups.
Luke Palmer53f9bdf872b3
diff --git a/.stylish-haskell.yaml b/.stylish-haskell.yamlindex a4cc491..ede97e9 100644--- a/.stylish-haskell.yaml+++ b/.stylish-haskell.yaml@@ -200,5 +200,6 @@ language_extensions:- ScopedTypeVariables- StandaloneDeriving- TupleSections+ - TypeApplications- TypeFamilies- TypeOperatorsdiff --git a/docs/source/reference.rst b/docs/source/reference.rstindex 6b4ee82..128262e 100644--- a/docs/source/reference.rst+++ b/docs/source/reference.rst@@ -175,6 +175,12 @@ Multiplies two numbers together.Substracts one number from another.+``/``+~~~~~++Divides one number by another. Throws an exception if the second+argument is 0.+``<``~~~~~@@ -259,6 +265,12 @@ Given a value ``x``, and two functions ``f`` and ``g``, checks if ``x``is a list with a head. If so applies ``f`` to the head, otherwise calls``g`` with no args.+``for-each``+~~~~~~~~~~~~++(for-each ls cb) calls ``cb`` for each element in the list ``ls``, for+its side effect. always returns ``nil``.+Vectors-------@@ -279,6 +291,12 @@ Adds an element to the left side of a vector.Adds an element to the right side of a vector.+``for-each-vec``+~~~~~~~~~~~~~~~~++(for-each-vec v cb) calls ``cb`` for each element in ``v``, for its side+effect. always returns ``nil``.+Sequences---------@@ -344,7 +362,8 @@ Functions for manipulating dicts.~~~~~~~~Given an even number of arguments, creates a dict where the ``2i``-th-argument is the key for the ``2i+1``\ th argument.+argument is the key for the ``2i+1``\ th argument. If one of the even+indexed arguments is not hashable then an exception is thrown.``lookup``~~~~~~~~~~@@ -359,7 +378,7 @@ thrown.Given ``k``, ``v`` and a dict ``d``, returns a dict with the sameassociations as ``d`` but with ``k`` associated to ``d``. If ``d`` isn't-a dict then an exception is thrown.+a dict or if ``k`` isn't hashable then an exception is thrown.``delete``~~~~~~~~~~@@ -537,6 +556,11 @@ Input/OutputEffectful functions. These functions are not available in 'pure' chains,but are available in the local REPL.+``put-str!``+~~~~~~~~~~~~++Outputs a string verbatim.+``print!``~~~~~~~~~~@@ -547,6 +571,12 @@ Pretty-prints a value.Reads a single line of input and returns it as a string.+``get-expression!``+~~~~~~~~~~~~~~~~~~~++Reads a line of input and returns it as a string. Takes a list of+completion words.+``load!``~~~~~~~~~@@ -766,6 +796,11 @@ functions before sending these to a remote chain.Return an empty chain dictionary with the given url.+``@var``+~~~~~~~~++A lens for variables in states of chains.+``eval-in-chain``~~~~~~~~~~~~~~~~~diff --git a/exe/RadicleExe.hs b/exe/RadicleExe.hsindex 44caaf4..f5baed5 100644--- a/exe/RadicleExe.hs+++ b/exe/RadicleExe.hs@@ -13,8 +13,8 @@ import Radicleimport Servant.Clientimport System.Directory (doesFileExist)-import qualified Radicle.Internal.Number as Numimport qualified Radicle.Internal.Input as Input+import qualified Radicle.Internal.Number as Numimport qualified Radicle.Internal.PrimFns as PrimFnsmain :: IO ()diff --git a/exe/ReferenceDoc.hs b/exe/ReferenceDoc.hsindex 0172608..0a1697c 100644--- a/exe/ReferenceDoc.hs+++ b/exe/ReferenceDoc.hs@@ -84,8 +84,8 @@ main = doseqs = ["nth", "foldl", "foldr", "map", "seq", "take", "drop"]lists =[ "list", "nil", "head", "tail", "empty?", "cons", "reverse", "length", "concat"- , "filter", "range", "list-with-head" ]- vecs = ["<>", "add-left", "add-right"]+ , "filter", "range", "list-with-head", "for-each" ]+ vecs = ["<>", "add-left", "add-right", "for-each-vec" ]dicts =["dict", "lookup", "insert", "delete", "dict-from-list", "keys", "values", "rekey", "map-values", "modify-map"]@@ -93,7 +93,8 @@ main = dorefs = ["ref", "read-ref", "write-ref", "modify-ref"]docs = ["help", "doc", "doc!", "apropos!", "document", "is-test-env"]io =- ["print!", "get-line!", "load!", "read-file!", "read-code!", "send-code!"+ ["put-str!", "print!", "get-line!", "get-expression!"+ , "load!", "read-file!", "read-code!", "send-code!", "send-prelude!", "subscribe-to!", "uuid!", "read-line!", "exit!"]lens = ["@", "@nth", "make-lens", "view", "view-ref", "set", "set-ref", "over", "over-ref", "id-lens", "..", "..."]validation =diff --git a/package.yaml b/package.yamlindex 560ccd4..1911afd 100644--- a/package.yaml+++ b/package.yaml@@ -204,5 +204,6 @@ default-extensions:- ScopedTypeVariables- StandaloneDeriving- TupleSections+- TypeApplications- TypeFamilies- TypeOperatorsdiff --git a/rad/prelude.rad b/rad/prelude.radindex df1501f..1ebc8e0 100644--- a/rad/prelude.rad+++ b/rad/prelude.rad@@ -1,5 +1,5 @@-(load! "rad/prelude/test.rad")(load! "rad/prelude/io.rad")+(load! "rad/prelude/test.rad")(load! "rad/prelude/bool.rad")(load! "rad/prelude/recursion.rad")(load! "rad/prelude/list.rad")diff --git a/rad/prelude/io.rad b/rad/prelude/io.radindex 221b857..d4218ac 100644--- a/rad/prelude/io.rad+++ b/rad/prelude/io.rad@@ -18,3 +18,7 @@(document 'send-code!'(("chain-id" string) ("filename" string))"Send code from a file to a remote chain.")++(def print!+ "Pretty-prints a value."+ (fn [x] (put-str! (show x))))diff --git a/rad/prelude/list.rad b/rad/prelude/list.radindex 60c5e4a..857de5e 100644--- a/rad/prelude/list.rad+++ b/rad/prelude/list.rad@@ -111,12 +111,18 @@;; imperative for each-(def-rec for-each (fn [ls cb]- (if (empty? ls)- nil- (do (cb (head ls))- (for-each (tail ls) cb)))))--(def for-each-vec (fn [v cb]- (for-each (range 0 (- (length v) 1)) (fn [i]- (cb (nth i v))))))+(def-rec for-each+ "(for-each ls cb) calls `cb` for each element in the list `ls`, for its side+ effect. always returns `nil`."+ (fn [ls cb]+ (if (empty? ls)+ nil+ (do (cb (head ls))+ (for-each (tail ls) cb)))))++(def for-each-vec+ "(for-each-vec v cb) calls `cb` for each element in `v`, for its side effect.+ always returns `nil`."+ (fn [v cb]+ (for-each (range 0 (- (length v) 1)) (fn [i]+ (cb (nth i v))))))diff --git a/rad/repl.rad b/rad/repl.radindex 4716d1a..6c77f95 100644--- a/rad/repl.rad+++ b/rad/repl.rad@@ -3,7 +3,8 @@;; The Repl(def render-exception! (fn [e stack]- (put-str! (string-append "Exception: " (show e)))+ (def show-e (if (eq? (type e) :string) e (show e)))+ (put-str! (string-append "Exception: " show-e))(for-each-vec stack put-str!)))(def repl (fn []@@ -12,11 +13,13 @@(def cur-eval (lookup :val (lookup 'eval (lookup :env st))))(if (eq? line nil)nil- (catch 'any (do (def ret (cur-eval (read line) st))- (print! (head ret))- (repl-rec (head (tail ret))))- (fn [e stack] (render-exception! e stack)- (repl-rec st))))))+ (do+ (def new-st (catch 'any (do (def ret (cur-eval (read line) st))+ (print! (head ret))+ (head (tail ret)))+ (fn [e stack] (render-exception! e stack)+ st)))+ (repl-rec new-st)))))(repl-rec (get-current-env))))(repl)diff --git a/scripts/ci-tests.sh b/scripts/ci-tests.shindex 4eb9216..6929023 100755--- a/scripts/ci-tests.sh+++ b/scripts/ci-tests.sh@@ -6,7 +6,7 @@set -e -xBASEDIR=$(dirname $BASH_SOURCE)/..cd $BASEDIR-hothasktags -XLambdaCase -XTypeFamilies -XScopedTypeVariables -XFunctionalDependencies -XTupleSections -XExplicitNamespaces -XStandaloneDeriving -XDefaultSignatures -R src > TAGS+./scripts/hottags.shstack exec hlint ../scripts/check-fmt.shstack test --fastdiff --git a/scripts/hottags.sh b/scripts/hottags.shindex 6bd4b53..62e40fe 100755--- a/scripts/hottags.sh+++ b/scripts/hottags.sh@@ -6,4 +6,4 @@BASEDIR=$(dirname $BASH_SOURCE)/..cd $BASEDIR-hothasktags -XLambdaCase -XTypeFamilies -XScopedTypeVariables -XFunctionalDependencies -XTupleSections -XExplicitNamespaces -XStandaloneDeriving -XDefaultSignatures -R src > TAGS+hothasktags -XLambdaCase -XTypeFamilies -XScopedTypeVariables -XFunctionalDependencies -XTupleSections -XExplicitNamespaces -XStandaloneDeriving -XDefaultSignatures -XTypeApplications -R src > TAGSdiff --git a/src/Radicle/Internal/Effects.hs b/src/Radicle/Internal/Effects.hsindex c04a208..8258244 100644--- a/src/Radicle/Internal/Effects.hs+++ b/src/Radicle/Internal/Effects.hs@@ -52,15 +52,7 @@ replBindings = addPrimFns replPrimFns pureEnvreplPrimFns :: ReplM m => PrimFns mreplPrimFns = fromList $ allDocs $- [ ( "print!"- , "Pretty-prints a value."- , \case- [x] -> do- putStrS (renderPrettyDef x)- pure nil- xs -> throwErrorHere $ WrongNumberOfArgs "print!" 1 (length xs))-- , ( "put-str!"+ [ ( "put-str!", "Outputs a string verbatim.", oneArg "put-str!" $ \caseString str -> putStrS str >> pure nildiff --git a/src/Radicle/Internal/Effects/Capabilities.hs b/src/Radicle/Internal/Effects/Capabilities.hsindex d0600e9..264b915 100644--- a/src/Radicle/Internal/Effects/Capabilities.hs+++ b/src/Radicle/Internal/Effects/Capabilities.hs@@ -2,8 +2,7 @@---- The intent is that any set of primops may wear on their sleaves (i.e.-- constraints) what effects they do.-{-# LANGUAGE CPP #-}-{-# LANGUAGE TypeApplications #-}+{-# LANGUAGE CPP #-}module Radicle.Internal.Effects.Capabilities whereimport Protoludediff --git a/src/Radicle/Internal/Input.hs b/src/Radicle/Internal/Input.hsindex 336fff3..a72305b 100644--- a/src/Radicle/Internal/Input.hs+++ b/src/Radicle/Internal/Input.hs@@ -42,7 +42,7 @@ wordCompletions whitespace words = Completions $ H.completeWord Nothing whitespago s = pure . fmap H.simpleCompletion. filter (s `isPrefixOf`)$ map T.unpack words-{-# ANN wordCompletions ("HLint: ignore Use String" :: [Char]) #-}+{-# ANN module ("HLint: ignore Use String" :: [Char]) #-}getInputLine :: (Monad m, MonadException m) => Completions m -> Text -> InputT m (Maybe Text)getInputLine compl prompt = InputT $