applyFromEnv :: Env -> Name -> Expr -> ThrowError Expr
applyFromEnv env name arg = do
    case findFunc env name of
        Nothing -> throwError $ SymbolNotFound name
        Just func -> do
            case funcArgCount func of
                0 -> matchAndEvalPatternExpr name env [] (funcPatterns func) >>= (\expr -> apply env expr arg)
                1 -> matchAndEvalPatternExpr name env [arg] (funcPatterns func)
                n -> return $ FuncCtx (Defined n func) [arg]

-- |Evaluate a pattern if it matches the given parameters.
applyFromEnv :: Env -> Name -> Expr -> ThrowError Expr
applyFromEnv env name arg = do
    case findFunc env name of
        Nothing -> throwError $ SymbolNotFound name
        Just func -> do
            case funcArgCount func of
                0 -> matchAndEvalPatternExpr name env [] (funcPatterns func) >>= (\expr -> apply env expr arg)
                1 -> matchAndEvalPatternExpr name env [arg] (funcPatterns func)
                n -> return $ FuncCtx (Defined n func) [arg]

-- |Evaluate a pattern if it matches the given parameters.
applyFromEnv env name arg = do
    case findFunc env name of
        Nothing -> throwError $ SymbolNotFound name
        Just func -> do
            case funcArgCount func of
                0 -> matchAndEvalPatternExpr name env [] (funcPatterns func) >>= (\expr -> apply env expr arg)
                1 -> matchAndEvalPatternExpr name env [arg] (funcPatterns func)
                n -> return $ FuncCtx (Defined n func) [arg]

-- |Evaluate a pattern if it matches the given parameters.