Match with symbols #2366
-
I can't seem to figure out how get match to work with symbols. Here is my attempt with Hy 0.25.0 using CPython(main) 3.11.0:
It's not that quote is completely missing, because I can use it to define symbols outside of a match:
On the other hand, the same match works for strings:
Any ideas on what I'm doing wrong? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Python limits what is allowed as a pattern in a |
Beta Was this translation helpful? Give feedback.
-
@Kodiologist I believe the following is related, so asking here.
Above prints
prints We can match against any symbol object, but we cannot match against a specific symbol value. Would that be a bug? |
Beta Was this translation helpful? Give feedback.
Python limits what is allowed as a pattern in a
match
statement, and Hy doesn't try to extend this. In particular, Hy won't try to expand macro calls in a pattern, and'rock
is just syntactic sugar for calling the macroquote
. I don't know what your real situation is, but I bet you'd be happier with Hyrule'scase
orbranch
.