blob: 08131e8fa731ea762764bc468511eee67255bf5d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
module Base (Expr (..)
, Env (..)
, Function (..)
) where
import Data.IORef
-- TODO: use LispNumber (src/Operators.hs) here instead of IntLiteral and FloatLiteral
-- TODO: add character literals: \#a \#b \#c \#space \#newline
-- TODO: add support for complex numbers, oct and hex numbers
data Expr = List [Expr]
| Vector [Expr]
| DottedList [Expr] Expr
| StringLiteral String
| IntLiteral Integer
| FloatLiteral Double
| BoolLiteral Bool
| Id String
deriving (Eq)
data Function =
Function {
params :: [String]
, body :: Expr
, environment :: Env
}
type Env = IORef [(String, IORef Expr)]
showLispList :: [Expr] -> String
showLispList = unwords . map show
instance Show Expr where
show (DottedList xs x) = "(" ++ showLispList xs ++ " . " ++ show x ++ ")"
show (List xs) = "(" ++ showLispList xs ++ ")"
show (Vector xs) = "#(" ++ showLispList xs ++ ")"
show (StringLiteral s) = "\"" ++ s ++ "\""
show (IntLiteral n) = show n
show (FloatLiteral n) = show n
show (BoolLiteral True) = "#t"
show (BoolLiteral False) = "#f"
show (Id i) = i
|