Skip to content

Commit

Permalink
Macro Cond
Browse files Browse the repository at this point in the history
  • Loading branch information
iwillspeak committed Oct 24, 2021
1 parent e719e64 commit c243caa
Show file tree
Hide file tree
Showing 4 changed files with 204 additions and 1,618 deletions.
18 changes: 4 additions & 14 deletions spec/conditions.scm
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,18 @@
"world"
-2))

(define-syntax my-cond
(syntax-rules (else)
((cond (else e ...)) (begin e ...))
((cond (test e e1 ...))
(if test
(begin e e1 ...)))
((cond (test e e1 ...) c ...)
(if test
(begin e e1 ...)
(my-cond c ...)))))
(display
(my-cond
(cond
(#f 'false)
(#t 'true)
(else 'fail)))
(display
(my-cond
(cond
(#f 'false)
(#t 'true)))
(display
(my-cond
(cond
(else 'ok)))
(display
(my-cond
(cond
(#f 'fail)))
2 changes: 0 additions & 2 deletions src/Feersum/Bind.fs
Original file line number Diff line number Diff line change
Expand Up @@ -627,8 +627,6 @@ and private bindForm ctx (form: AstNode list) node =
|> Result.map (BinderCtx.importLibrary ctx >> BoundExpr.Import)
|> ResultEx.okOr BoundExpr.Error)
|> BoundExpr.Seq
| { Kind = AstNodeKind.Ident("cond") }::body ->
unimpl "Condition expressions not yet implemented"
| { Kind = AstNodeKind.Ident("case") }::body ->
unimpl "Case expressions not yet implemented"
| head::rest ->
Expand Down
18 changes: 17 additions & 1 deletion src/Feersum/Builtins.fs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ module private BuiltinMacros =

/// Builtin `or` Macro
let private macroOr =
// TODO: re-write this when proper hygene is supported.
"(syntax-rules ()
((or) #f)
((or test) test)
Expand Down Expand Up @@ -238,11 +239,26 @@ module private BuiltinMacros =
expr1 ...))))"
|> parseBuiltinMacro "unless"

let private macroCond =
// TODO: This `cond` implementation doesn't support the `=>` 'pipe' form
// of the macro yet. This is because we're waiting for hygene
// support like `or`.
"(syntax-rules (else)
((cond (else e ...)) (begin e ...))
((cond (test e e1 ...))
(if test
(begin e e1 ...)))
((cond (test e e1 ...) c ...)
(if test
(begin e e1 ...)
(cond c ...))))"
|> parseBuiltinMacro "cond"

/// The list of builtin macros
let coreMacros =
{ LibraryName = ["scheme";"base"]
; Exports =
[ macroAnd ; macroOr; macroWhen; macroUnless ]
[ macroAnd ; macroOr; macroWhen; macroUnless; macroCond ]
|> List.map (fun m -> (m.Name, StorageRef.Macro(m))) }

// ------------------------ Public Builtins API --------------------------------
Expand Down

0 comments on commit c243caa

Please sign in to comment.