An interpreted, lazy lisp.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

27 lines
839 B

module Rose.Data.Function
import Data.Error
import Data.Atom
import Data.SExpression
NonsymbolicArgumentsError : SE -> RoseError
NonsymbolicArgumentsError se = MkError $ "Functions can only have symbols as arguments: " ++ se
FnError : SE -> RoseError
FnError se = MkError $ "The function: " ++ show se ++ "is invalid."
data Fn : Type where
MkFn : List (SE Atomic) -> SE a -> Fn
InvalidFn : RoseError -> SE a -> Fn
Interpreted Fn where
invalid = InvalidFn
interpret (Expression (Expression (Atom (MkSymbol "fn")) Nil) (Expression args body)) =
if (any (not . isSymbol) args)
then invalid (NonSymbolicArgumentsError args) (Expression args body)
else MkFn (toList args) body
interpret se = invalid (FnError se) se
expression (MkFn args body) =
(Expression (MkSymbol "fn") (Expression (fromList args) body))