Zulip Chat Archive

Stream: lean4

Topic: eval expr in MetaM


James Gallicchio (Sep 09 2023 at 22:23):

first some #xy: I want to write a macro that is called as

getStatusCodes! [
  (a,b,c,d),
  (e,f,g,h),
...
]

because I assumed it would be easier to just use term parser instead of making a custom syntax for this. But I need the (evaluated) value within the macro implementation. Is there a function to run a term or elaborated expr?

I see #eval just adds a new declaration to the environment, calls evalConst, and then resets the environment. Is there a function that already does this somewhere in core/std?

James Gallicchio (Sep 09 2023 at 22:24):

and if I should just make a custom syntax category, then I will do that :p

James Gallicchio (Sep 09 2023 at 22:57):

(this would also be nice to have as an abstraction so that the evalConst unsafeness can be hidden)

Joachim Breitner (Sep 10 2023 at 00:10):

https://leanprover-community.github.io/mathlib4_docs/Lean/Meta/Eval.html#Lean.Meta.evalExpr maybe?

James Gallicchio (Sep 10 2023 at 00:10):

ooh that does look like the right signature

James Gallicchio (Sep 10 2023 at 00:11):

don't love that it's unsafe
EDIT: termUnsafe saves the day :)


Last updated: Dec 20 2023 at 11:08 UTC