husk-scheme-2.4: R5RS Scheme interpreter program and library.

Language.Scheme.Core

Synopsis

Documentation

eval :: Env -> LispVal -> LispVal -> IOThrowsError LispValSource

Core eval function Evaluate a scheme expression. NOTE: This function does not include macro support and should not be called directly. Instead, use evalLisp

Implementation Notes:

Internally, this function is written in continuation passing style (CPS) to allow the Scheme language itself to support first-class continuations. That is, at any point in the evaluation, call/cc may be used to capture the current continuation. Thus this code must call into the next continuation point, eg:

eval ... (makeCPS ...)

Instead of calling eval directly from within the same function, eg:

eval ... eval ...

This can make the code harder to follow, however some coding conventions have been established to make the code easier to follow. Whenever a single function has been broken into multiple ones for the purpose of CPS, those additional functions are defined locally using 'where', and each has been given a cps prefix.

evalLisp :: Env -> LispVal -> IOThrowsError LispValSource

Evaluate lisp code that has already been loaded into haskell

FUTURE: code example for this, via ghci and/or a custom Haskell program.

evalString :: Env -> String -> IO StringSource

Evaluate a string containing Scheme code.

For example:

env <- primitiveBindings

evalString env (+ x x x)
3

evalString env (+ x x x (* 3 9))
30

evalString env (* 3 9)            
27

evalAndPrint :: Env -> String -> IO ()Source

Evaluate a string and print results to console

primitiveBindings :: IO EnvSource

Environment containing the primitive forms that are built into the Scheme language. Note that this 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).