Noob question: Type check for HyExpression? #2152
-
Hi! I am learning Lisp and I definitely think that Hy is the way to go for me. I am writing a macro and would like to recursively iterate over the code passed. I want to check if a variable contains code I should iterate on, or not. At the moment I am using Thank you so much in advance. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
My solution |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
hy.models.Expression
(formerlyHyExpression
) is only one of several types that Hy uses for its code. The supertype that everything else inherits from ishy.models.Object
. Note however that checking(isinstance code hy.models.Object)
won't catch objects that could be promoted to models, such as5
, which would be promoted tohy.models.Integer
in e.g.(hy.eval 5)
. The most general approach is to callhy.as-model
and check if it raises an error.