1
1
mirror of https://github.com/github/semantic.git synced 2024-11-24 08:54:07 +03:00

Rename lambda to closure.

This commit is contained in:
Rob Rix 2018-05-08 10:54:32 -04:00
parent d9084f9f45
commit 97915e1410
5 changed files with 9 additions and 9 deletions

View File

@ -138,10 +138,10 @@ class Show value => AbstractValue location value effects where
scopedEnvironment :: value -> Evaluator location term value effects (Maybe (Environment location value))
-- | Build a closure (a binder like a lambda or method definition).
lambda :: [Name] -- ^ The parameter names.
-> Set Name -- ^ The set of free variables to close over.
-> Evaluator location term value effects value -- ^ The evaluator for the body of the closure.
-> Evaluator location term value effects value
closure :: [Name] -- ^ The parameter names.
-> Set Name -- ^ The set of free variables to close over.
-> Evaluator location term value effects value -- ^ The evaluator for the body of the closure.
-> Evaluator location term value effects value
-- | Evaluate an application (like a function call).
call :: value -> [Evaluator location term value effects value] -> Evaluator location term value effects value

View File

@ -92,7 +92,7 @@ instance ( Addressable location effects
, Reducer (Type location) (Cell location (Type location))
)
=> AbstractValue location (Type location) effects where
lambda names _ body = do
closure names _ body = do
(env, tvars) <- foldr (\ name rest -> do
a <- alloc name
tvar <- Var <$> raise fresh

View File

@ -349,7 +349,7 @@ instance ( Addressable location (Goto effects (Value location) ': effects)
| otherwise = throwValueError (Bitwise2Error left right)
where pair = (left, right)
lambda parameters freeVariables body = do
closure parameters freeVariables body = do
l <- label body
injValue . Closure parameters l . Env.bind (foldr Set.delete freeVariables parameters) <$> getEnv

View File

@ -23,7 +23,7 @@ instance Show1 Function where liftShowsPrec = genericLiftShowsPrec
instance Evaluatable Function where
eval Function{..} = do
name <- either (throwEvalError . FreeVariablesError) pure (freeVariable $ subterm functionName)
(v, addr) <- letrec name (lambda (paramNames functionParameters) (Set.fromList (freeVariables functionBody)) (subtermValue functionBody))
(v, addr) <- letrec name (closure (paramNames functionParameters) (Set.fromList (freeVariables functionBody)) (subtermValue functionBody))
modifyEnv (Env.insert name addr)
pure v
where paramNames = foldMap (freeVariables . subterm)
@ -47,7 +47,7 @@ instance Show1 Method where liftShowsPrec = genericLiftShowsPrec
instance Evaluatable Method where
eval Method{..} = do
name <- either (throwEvalError . FreeVariablesError) pure (freeVariable $ subterm methodName)
(v, addr) <- letrec name (lambda (paramNames methodParameters) (Set.fromList (freeVariables methodBody)) (subtermValue methodBody))
(v, addr) <- letrec name (closure (paramNames methodParameters) (Set.fromList (freeVariables methodBody)) (subtermValue methodBody))
modifyEnv (Env.insert name addr)
pure v
where paramNames = foldMap (freeVariables . subterm)

View File

@ -22,7 +22,7 @@ spec = parallel $ do
it "calls functions" $ do
(expected, _) <- evaluate $ do
identity <- lambda [name "x"] lowerBound (variable (name "x"))
identity <- closure [name "x"] lowerBound (variable (name "x"))
call identity [integer 123]
expected `shouldBe` Right (Value.injValue (Value.Integer (Number.Integer 123)))