Use module scope for global scope in in module-prefixed functions

This commit is contained in:
darkf 2013-10-29 02:49:02 -07:00
parent cda4a8a345
commit d653902028
1 changed files with 5 additions and 0 deletions

View File

@ -290,9 +290,14 @@ eval (Access left (Var right)) = do
case lhs of
DictV dict ->
case M.lookup (StrV right) dict of
Just (FnV [] fn) -> -- use the module's global scope
return $ FnV (mapToEnv dict) fn
Just v -> return v
Nothing -> return $ TupleV [StrV "nothing"]
_ -> error $ "op/: need a dict, got " ++ show lhs
where
mapToEnv :: M.Map Value Value -> Env
mapToEnv m = [M.fromAscList $ map (\(StrV k,v) -> (k,v)) (M.toAscList m)]
eval (Access _ _) = error "op/: RHS must be an identifier"
eval (Call lhs arg) = do