Copyright | Justin Ethier |
---|---|
License | MIT (see LICENSE in the distribution) |
Maintainer | github.com/justinethier |
Stability | experimental |
Portability | portable |
Safe Haskell | None |
Language | Haskell98 |
This module contains Core functionality, primarily Scheme expression evaluation.
- evalLisp :: Env -> LispVal -> IOThrowsError LispVal
- evalLisp' :: Env -> LispVal -> IO (ThrowsError LispVal)
- evalString :: Env -> String -> IO String
- evalAndPrint :: Env -> String -> IO ()
- apply :: LispVal -> LispVal -> [LispVal] -> IOThrowsError LispVal
- continueEval :: Env -> LispVal -> LispVal -> Maybe [LispVal] -> IOThrowsError LispVal
- runIOThrows :: IOThrowsError String -> IO (Maybe String)
- runIOThrowsREPL :: IOThrowsError String -> IO String
- nullEnvWithImport :: IO Env
- primitiveBindings :: IO Env
- r5rsEnv :: IO Env
- r5rsEnv' :: IO Env
- r7rsEnv :: IO Env
- r7rsEnv' :: IO Env
- r7rsTimeEnv :: IO Env
- version :: String
- findFileOrLib :: String -> ErrorT LispError IO String
- getDataFileFullPath :: String -> IO String
- replaceAtIndex :: forall a. Int -> a -> [a] -> [a]
- registerExtensions :: Env -> (FilePath -> IO FilePath) -> IO ()
- showBanner :: IO ()
- showLispError :: LispError -> IO String
- substr :: (LispVal, LispVal, LispVal) -> IOThrowsError LispVal
- updateList :: LispVal -> LispVal -> LispVal -> IOThrowsError LispVal
- updateVector :: LispVal -> LispVal -> LispVal -> IOThrowsError LispVal
- updateByteVector :: LispVal -> LispVal -> LispVal -> IOThrowsError LispVal
- hashTblRef :: [LispVal] -> IOThrowsError LispVal
- addToCallHistory :: LispVal -> [LispVal] -> [LispVal]
- throwErrorWithCallHistory :: LispVal -> LispError -> IOThrowsError LispVal
- meval :: Env -> LispVal -> LispVal -> IOThrowsError LispVal
Scheme code evaluation
evalLisp :: Env -> LispVal -> IOThrowsError LispVal Source #
Evaluate a lisp data structure and return a value for use by husk
evalLisp' :: Env -> LispVal -> IO (ThrowsError LispVal) Source #
Evaluate a lisp data structure and return the LispVal or LispError result directly
result <- evalLisp' env $ List [Atom "/", Number 1, Number 0] case result of Left err -> putStrLn $ "Error: " ++ (show err) Right val -> putStrLn $ show val
evalString :: Env -> String -> IO String Source #
Evaluate a string containing Scheme code
env <- primitiveBindings evalString env "(+ x x x)" "3" evalString env "(+ x x x (* 3 9))" "30" evalString env "(* 3 9)" "27"
:: LispVal | Current continuation |
-> LispVal | Function or continuation to execute |
-> [LispVal] | Arguments |
-> IOThrowsError LispVal | Final value of computation |
Call into a Scheme function
:: Env | Current environment |
-> LispVal | Current continuation |
-> LispVal | Value of previous computation |
-> Maybe [LispVal] | Extra arguments from previous computation |
-> IOThrowsError LispVal | Final value of computation |
A support function for eval; eval calls into this function instead of returning values directly. continueEval then uses the continuation argument to manage program control flow.
runIOThrows :: IOThrowsError String -> IO (Maybe String) Source #
Execute an IO action and return error or Nothing if no error was thrown.
runIOThrowsREPL :: IOThrowsError String -> IO String Source #
Execute an IO action and return result or an error message. This is intended for use by a REPL, where a result is always needed regardless of type.
Core data
nullEnvWithImport :: IO Env Source #
An empty environment with the %import function. This is presently just intended for internal use by the compiler.
primitiveBindings :: IO Env Source #
Environment containing the primitive forms that are built into the Scheme language. This function only includes forms that are implemented in Haskell; derived forms implemented in Scheme (such as let, list, etc) are available in the standard library which must be pulled into the environment using (load)
For the purposes of using husk as an extension language, r5rsEnv will probably be more useful.
Load the standard r5rs environment, including libraries, but do not create the (import) binding
Load the standard r7rs environment, including libraries
Note that the only difference between this and the r5rs equivalent is that slightly less Scheme code is loaded initially.
r7rsTimeEnv :: IO Env Source #
Load haskell bindings used for the r7rs time library
Utility functions
findFileOrLib :: String -> ErrorT LispError IO String Source #
Attempts to find the file both in the current directory and in the husk libraries. If the file is not found in the current directory but exists as a husk library, return the full path to the file in the library. Otherwise just return the given filename.
getDataFileFullPath :: String -> IO String Source #
Get the full path to a data file installed for husk
replaceAtIndex :: forall a. Int -> a -> [a] -> [a] Source #
Replace a list element, by index. Taken from: http://stackoverflow.com/questions/10133361/haskell-replace-element-in-list
registerExtensions :: Env -> (FilePath -> IO FilePath) -> IO () Source #
Register optional SRFI extensions
showBanner :: IO () Source #
A utility function to display the husk console banner
showLispError :: LispError -> IO String Source #
This is the recommended function to use to display a lisp error, instead of just using show directly.
substr :: (LispVal, LispVal, LispVal) -> IOThrowsError LispVal Source #
A helper function for the special form (string-set!)
updateList :: LispVal -> LispVal -> LispVal -> IOThrowsError LispVal Source #
A helper function for (list-set!)
updateVector :: LispVal -> LispVal -> LispVal -> IOThrowsError LispVal Source #
A helper function for the special form (vector-set!)
updateByteVector :: LispVal -> LispVal -> LispVal -> IOThrowsError LispVal Source #
A helper function for the special form (bytevector-u8-set!)
hashTblRef :: [LispVal] -> IOThrowsError LispVal Source #
Retrieve the value from the hashtable for the given key. An error is thrown if the key is not found.
Note this had to be made an EvalFunc because a thunk can be passed as an optional argument to be executed if the key is not found.
Arguments:
- Current continuation
- HashTable to copy
- Object that is the key to query the table for
Returns: Object containing the key's value
Error handling
throwErrorWithCallHistory :: LispVal -> LispError -> IOThrowsError LispVal Source #
Rethrow given error with call history, if available