Zulip Chat Archive

Stream: metaprogramming / tactics

Topic: How is TacticM lifted to TermElabM?


nrs (Dec 03 2024 at 03:57):

I'm trying to make a macro or elaborator that would produce the same term as does beta% clear% (by reduce x; exact x), so I'm trying to figure out how it is that a tactic block gets embedded within a term. Is there a coercion that lifts TacticM to TermElabM or something of the sort? Is there any place in source I should take a look at to further investigate the question?

nrs (Dec 03 2024 at 04:05):

looks like Term.Elab.Tactic.run is responsible for this

Kyle Miller (Dec 03 2024 at 13:58):

Was it not sufficient making a macro?

nrs (Dec 03 2024 at 14:04):

Kyle Miller said:

Was it not sufficient making a macro?

Was having a hard time using TSynx `Lean.Parser.Tactic.location to make ... => `(beta% clear% (by reduce $x; exact $x). Went to sleep straight after reading that you can make a coercion from term to that parser, will report back after testing this

nrs (Dec 03 2024 at 14:56):

hm even so, the problem with

syntax (name := reduce) "reduce%" term : term

@[macro reduce]
def reduceImpl : Macro
| `(reduce% $t:term) => `(beta% clear% (by reduce $t; exact $t))
| _ => Macro.throwUnsupported

seems to be that beta% and clear% are immediately elaborated within the syntax quotation, any clue how to prevent this? i.e. they need to be passed as literals instead (i think?)
edit: I think you can do this with the Syntax.mk... API

Kyle Miller (Dec 03 2024 at 16:06):

They're definitely not elaborated within the quotation, the issue is that reduce $t with t : Term is not syntax. In your other thread, you were using reduce at x

Kyle Miller (Dec 03 2024 at 16:09):

I'm also really not sure what clear% is meant to be doing here. Are you wanting to clear a variable, or is that a typo for clean%?

Kyle Miller (Dec 03 2024 at 16:09):

Anyway, without it, this is how you could make a macro:

macro "reduce%" t:term : term =>
  `(beta% (by have x := $t; reduce at x; exact x))

nrs (Dec 03 2024 at 16:10):

whoops yeah I meant %clean!

nrs (Dec 03 2024 at 16:10):

ah I see, thank you very much for taking the time!


Last updated: May 02 2025 at 03:31 UTC