mirror of
https://github.com/open-goal/jak-project.git
synced 2024-10-20 11:26:18 -04:00
Add case
macro for switch-case constructs (#362)
This commit is contained in:
parent
9fbbe1a79c
commit
496f8a3fbb
|
@ -353,6 +353,20 @@
|
||||||
`(none)
|
`(none)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
(defmacro case (switch &rest cases)
|
||||||
|
"A switch-case construct. switch is saved onto a local variable and compared against each case, sequentially.
|
||||||
|
else can be used as the default case, but it must be the last one."
|
||||||
|
|
||||||
|
(with-gensyms (sw)
|
||||||
|
`(let ((sw ,switch))
|
||||||
|
(cond ,@(apply
|
||||||
|
(lambda (x) `(,@(if (eq? (first x) 'else) `(else ,@(rest x)) `((= sw ,(first x)) ,@(rest x)))))
|
||||||
|
cases)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;
|
||||||
;; Math Macros
|
;; Math Macros
|
||||||
;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
Loading…
Reference in a new issue