RosettaCodeData/Task/Extend-your-language/Fennel/extend-your-language.fennel
2023-07-01 13:44:08 -04:00

18 lines
516 B
Fennel

;; Fennel, being a Lisp, provides a way to define macros for new syntax.
;; The "`" and "," characters are used to construct a template for the macro.
(macro if2 [cond1 cond2 both first second none]
`(if ,cond1
(if ,cond2 ,both ,first)
(if ,cond2 ,second ,none)))
(fn test-if2 [x y]
(if2 x y
(print "both")
(print "first")
(print "second")
(print "none")))
(test-if2 true true) ;"both"
(test-if2 true false) ;"first"
(test-if2 false true) ;"second"
(test-if2 false false) ;"none"