Skip to content

case with two alternative options per command #1417

Answered by ianthehenry
MaxGyver83 asked this question in Q&A
Discussion options

You must be logged in to vote

Yeah, Janet's native macros can only expand to a single form, so there's not a direct way to do what you're trying to do.

case is a special-case of cond, and you could use cond directly:

(def subject 3)
(cond
  (or (= subject 1) (= subject 2)) (print "one or two")
  (or (= subject 3) (= subject 4)) (print "three or four"))

But that's clearly not as nice as case. It would be possible to write a custom case macro that understood your twocases form, but it's kinda sad that it wouldn't compose with built-in things. There are... ways... to define macros that would allow your general twocases macro to work. But... that's not really accessible.

I've written a library called pat that has a match

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@MaxGyver83
Comment options

@ianthehenry
Comment options

Answer selected by MaxGyver83
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants