Commits

Anonymous committed a7672aa

Implement metadata as (sort of) alists; break a bunch of tests.

Comments (0)

Files changed (3)

 >           | Macro Expr Expr Expr
 >           | Builtin String Bif
 >           | List [Expr]
->           | Metadata Expr Expr
+>           | Metadata (Expr, Expr) Expr
 
 Equality ignores metadata for now.  That's too deep a question for
 me to think about right now.
 Metadata Helpers
 ----------------
 
-> hasMetadata metadata (Metadata m x)
->     | m == metadata = True
->     | otherwise     = hasMetadata metadata x
+> hasMetadata metaName (Metadata (k, v) x)
+>     | k == metaName = True
+>     | otherwise     = hasMetadata metaName x
 > hasMetadata _ _ = False
 
+> getMetadata metaName (Metadata (k, v) x)
+>     | k == metaName = Just v
+>     | otherwise     = getMetadata metaName x
+> getMetadata _ _ = Nothing
+
 > stripMetadata (Metadata _ x) =
 >     stripMetadata x
 > stripMetadata x =

Robin/Metadata.lhs

 Metadata
 ========
 
-> robinWith env ienv (List [metadataExpr, expr]) cc =
->     eval env ienv metadataExpr (\metadata ->
->         eval env ienv expr (\value ->
->             cc $ Metadata metadata value))
+> robinWith env ienv (List [metaNameExpr, metaValueExpr, expr]) cc =
+>     eval env ienv metaNameExpr (\metaName ->
+>         eval env ienv metaValueExpr (\metaValue ->
+>             eval env ienv expr (\value ->
+>                 cc $ Metadata (metaName, metaValue) value)))
 > robinWith env ienv other cc = raise ienv (errMsg "illegal-arguments" other)
 
-> hasP env ienv (List [metadataExpr, expr]) cc =
->     eval env ienv metadataExpr (\metadata ->
+> robinGet env ienv (List [metaNameExpr, expr]) cc =
+>     eval env ienv metaNameExpr (\metaName ->
 >         eval env ienv expr (\value ->
->             cc $ Boolean $ hasMetadata metadata value))
+>             case getMetadata metaName value of
+>                 Just v  -> cc v
+>                 Nothing -> cc $ List []))
+> robinGet env ienv other cc = raise ienv (errMsg "illegal-arguments" other)
+
+> hasP env ienv (List [metaNameExpr, expr]) cc =
+>     eval env ienv metaNameExpr (\metaName ->
+>         eval env ienv expr (\value ->
+>             cc $ Boolean $ hasMetadata metaName value))
 > hasP env ienv other cc = raise ienv (errMsg "illegal-arguments" other)
 
 Module Definition
 > moduleDef = do
 >     return $ Env.fromList $ map (\(name,bif) -> (name, Builtin name bif))
 >       [
->         ("with",     robinWith),
->         ("has?",     hasP)
+>         ("with", robinWith),
+>         ("has?", hasP),
+>         ("get",  robinGet)
 >       ]

module/bind-args_0_1.robin

File contents unchanged.