Skip to content

Commit c243caa

Browse files
committed
Macro Cond
1 parent e719e64 commit c243caa

File tree

4 files changed

+204
-1618
lines changed

4 files changed

+204
-1618
lines changed

spec/conditions.scm

+4-14
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,18 @@
1818
"world"
1919
-2))
2020

21-
(define-syntax my-cond
22-
(syntax-rules (else)
23-
((cond (else e ...)) (begin e ...))
24-
((cond (test e e1 ...))
25-
(if test
26-
(begin e e1 ...)))
27-
((cond (test e e1 ...) c ...)
28-
(if test
29-
(begin e e1 ...)
30-
(my-cond c ...)))))
3121
(display
32-
(my-cond
22+
(cond
3323
(#f 'false)
3424
(#t 'true)
3525
(else 'fail)))
3626
(display
37-
(my-cond
27+
(cond
3828
(#f 'false)
3929
(#t 'true)))
4030
(display
41-
(my-cond
31+
(cond
4232
(else 'ok)))
4333
(display
44-
(my-cond
34+
(cond
4535
(#f 'fail)))

src/Feersum/Bind.fs

-2
Original file line numberDiff line numberDiff line change
@@ -627,8 +627,6 @@ and private bindForm ctx (form: AstNode list) node =
627627
|> Result.map (BinderCtx.importLibrary ctx >> BoundExpr.Import)
628628
|> ResultEx.okOr BoundExpr.Error)
629629
|> BoundExpr.Seq
630-
| { Kind = AstNodeKind.Ident("cond") }::body ->
631-
unimpl "Condition expressions not yet implemented"
632630
| { Kind = AstNodeKind.Ident("case") }::body ->
633631
unimpl "Case expressions not yet implemented"
634632
| head::rest ->

src/Feersum/Builtins.fs

+17-1
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ module private BuiltinMacros =
210210

211211
/// Builtin `or` Macro
212212
let private macroOr =
213+
// TODO: re-write this when proper hygene is supported.
213214
"(syntax-rules ()
214215
((or) #f)
215216
((or test) test)
@@ -238,11 +239,26 @@ module private BuiltinMacros =
238239
expr1 ...))))"
239240
|> parseBuiltinMacro "unless"
240241

242+
let private macroCond =
243+
// TODO: This `cond` implementation doesn't support the `=>` 'pipe' form
244+
// of the macro yet. This is because we're waiting for hygene
245+
// support like `or`.
246+
"(syntax-rules (else)
247+
((cond (else e ...)) (begin e ...))
248+
((cond (test e e1 ...))
249+
(if test
250+
(begin e e1 ...)))
251+
((cond (test e e1 ...) c ...)
252+
(if test
253+
(begin e e1 ...)
254+
(cond c ...))))"
255+
|> parseBuiltinMacro "cond"
256+
241257
/// The list of builtin macros
242258
let coreMacros =
243259
{ LibraryName = ["scheme";"base"]
244260
; Exports =
245-
[ macroAnd ; macroOr; macroWhen; macroUnless ]
261+
[ macroAnd ; macroOr; macroWhen; macroUnless; macroCond ]
246262
|> List.map (fun m -> (m.Name, StorageRef.Macro(m))) }
247263

248264
// ------------------------ Public Builtins API --------------------------------

0 commit comments

Comments
 (0)