-- `LambdaCase` as a macro, in five lines
(defmacro \case
(cases
(do {varId <- gensym}
(pure [`(\ (~varId)
(case ~varId ~@cases))]))))
(def main (IO Unit)
(() (putStrLn
((\case ("tada" "🎉")
(_ "Impossible!"))
"tada"))))
-- 🎉
With Axel, there's no need to rely on hard-coded compiler extensions to unlock the language's syntax. Everything from Axel's
do
-notation to list comprehensions are just macros, on the same level as those you'll imagine yourself.
(defmacro backwards (forms (reverse forms)))
(backwards 42 print) -- (print 42)
Macro definitions are compact, since Axel code can be easily converted into its corresponding AST. Just prefix an expression with one of the quotation operators to convert it into its abstract representation.
(+ 1 2) -- 3
'(+ 1 2) -- (AST.SExpression <metadata> [(AST.LiteralInt <metadata> 1) (AST.LiteralInt <metadata> 2)])