A peer-to-peer stack for code collaboration
Remove closures that don't have an env. (#114)
James Haydon6228b328753b
diff --git a/src/Radicle/Internal/Core.hs b/src/Radicle/Internal/Core.hsindex 73cb371..1249018 100644--- a/src/Radicle/Internal/Core.hs+++ b/src/Radicle/Internal/Core.hs@@ -110,7 +110,7 @@ data Value =---- The value of an application of a lambda is always the last value in the-- body. The only reason to have multiple values is for effects.- | Lambda [Ident] (NonEmpty Value) (Maybe (Env Value))+ | Lambda [Ident] (NonEmpty Value) (Env Value)deriving (Eq, Show, Ord, Read, Generic)instance Serialise Value@@ -263,9 +263,7 @@ eval val = do-- Primops get to decide whether and how their args are-- evaluated.fn [quote val]- Lambda _ _ Nothing -> throwError $ Impossible- "lambda should already have an env"- Lambda [bnd] body (Just closure) -> do+ Lambda [bnd] body closure -> dolet mappings = GhcExts.fromList [(bnd, val)]modEnv = mappings <> closureNonEmpty.last <$> withEnv (const modEnv)@@ -276,22 +274,15 @@ eval val = dobaseEval :: Monad m => Value -> Lang m ValuebaseEval val = case val ofAtom i -> lookupAtom i- kw@(Keyword _) -> pure kw- Ref i -> pure $ Ref iList (f:vs) -> f $$ vsList xs -> throwError$ WrongNumberOfArgs ("application: " <> show xs)2(length xs)- String s -> pure $ String s- Number n -> pure $ Number n- Boolean b -> pure $ Boolean b- Primop i -> pure $ Primop i- e@(Lambda _ _ (Just _)) -> pure e- Lambda args body Nothing -> gets $ Lambda args body . Just . bindingsEnvDict mp -> dolet evalSnd (a,b) = (a ,) <$> baseEval bDict . Map.fromList <$> traverse evalSnd (Map.toList mp)+ autoquote -> pure autoquote@@ -300,18 +291,7 @@ baseEval val = case val ofcallFn :: Monad m => Value -> [Value] -> Lang m ValuecallFn f vs = case f of- -- This happens if a quoted lambda is explicitly evaled. We then- -- give it the current environment.- Lambda bnds body Nothing ->- if length bnds /= length vs- then throwError $ WrongNumberOfArgs "lambda" (length bnds)- (length vs)- else do- let mappings = GhcExts.fromList (zip bnds vs)- NonEmpty.last <$> withEnv- (mappings <>)- (traverse baseEval body)- Lambda bnds body (Just closure) ->+ Lambda bnds body closure ->if length bnds /= length vsthen throwError $ WrongNumberOfArgs "lambda" (length bnds)(length vs)diff --git a/src/Radicle/Internal/Pretty.hs b/src/Radicle/Internal/Pretty.hsindex 9e81aee..c51a419 100644--- a/src/Radicle/Internal/Pretty.hs+++ b/src/Radicle/Internal/Pretty.hs@@ -23,7 +23,7 @@ instance Pretty Value wherepretty v = case v ofAtom i -> pretty iKeyword i -> ":" <> pretty i- Ref i -> parens $ "ref" <+> pretty i+ Ref i -> pretty iString t -> "\"" <> pretty (escapeStr t) <> "\""Number n -> pretty (show n :: Text)Boolean True -> "#t"diff --git a/src/Radicle/Internal/Primops.hs b/src/Radicle/Internal/Primops.hsindex aa23cdf..1b19f0c 100644--- a/src/Radicle/Internal/Primops.hs+++ b/src/Radicle/Internal/Primops.hs@@ -40,7 +40,7 @@ purePrimops = fromList $ first Ident <$>List atoms_ : b : bs -> doatoms <- traverse isAtom atoms_ ?? "lambda: expecting a list of symbols"e <- gets bindingsEnv- pure (Lambda atoms (b :| bs) (Just e))+ pure (Lambda atoms (b :| bs) e)xs -> throwError $ WrongNumberOfArgs "lambda" 2 (length xs) -- TODO: technically "at least 2"), ("base-eval", evalOneArg "base-eval" baseEval)@@ -86,8 +86,8 @@ purePrimops = fromList $ first Ident <$>[Atom name, val] -> doval' <- baseEval valcase val' of- Lambda is b (Just e) -> do- let v = Lambda is b (Just (Env . Map.insert name v . fromEnv $ e))+ Lambda is b e -> do+ let v = Lambda is b (Env . Map.insert name v . fromEnv $ e)defineAtom name vpure nil_ -> throwError $ OtherError "define-rec can only be used to define functions"diff --git a/test/spec/Radicle/Tests.hs b/test/spec/Radicle/Tests.hsindex 5345ae6..e609c0f 100644--- a/test/spec/Radicle/Tests.hs+++ b/test/spec/Radicle/Tests.hs@@ -631,15 +631,6 @@ parseTest t = parse "(test)" t (Map.keys $ bindingsPrimops e)e :: Bindings (Lang Identity)e = pureEnv--- | Environments are neither printed nor parsed, but are generated by the--- arbitrary instance.-removeEnv :: Value -> Value-removeEnv v = case v of- List xs -> List $ removeEnv <$> xs- Dict m -> Dict $ removeEnv <$> m- Lambda ids bd _ -> Lambda ids (removeEnv <$> bd) Nothing- x -> x-prettyEither :: Either (LangError Value) Value -> T.TextprettyEither (Left e) = "Error: " <> renderPrettyDef eprettyEither (Right v) = renderPrettyDef v