Zulip Chat Archive

Stream: metaprogramming / tactics

Topic: Inaccessible names in tactic state


Eric Wieser (May 18 2021 at 14:56):

The tactic state at the comment in this code:

meta def what : tactic unit :=
do
  (a, 1)  pure (⟨2, 3 :  × ) | do {
    -- if I put my cursor at the start of this line, I can see `_x` and `_p`.
    -- why can't I refer to these except with `‹›`? Which one is being found?
    tactic.trace format!"where did this come from: {‹ℕ × ℕ›}"
  },
  tactic.skip

run_cmd what

is

what: tactic unit
_p:  × 
_do_match:  ×   tactic unit
_x:  × 
  × 

What are _x and _p, and is there any way for me to access them?

Jannis Limperg (May 18 2021 at 15:05):

These are artifacts of the equation compiler like the _do_match. I'm surprised you can even access them with the French quotes. You definitely shouldn't use them; conceptually there are no variables _x and _p in scope at that program point (or anywhere).

Eric Wieser (May 18 2021 at 15:09):

Well, conceptually there is an "object for which the match failed" which is not otherwise accessible with that | syntax

Eric Wieser (May 18 2021 at 15:12):

Looking at the output of #print, it looks like _x and _p are one and the same

Jannis Limperg (May 18 2021 at 15:26):

Right. If you need the matched object, I guess your least inelegant bet is

x <- ...,
(y, z) <- pure x | fail! "Matched object: {x}",

Or of course a good old match.


Last updated: Dec 20 2023 at 11:08 UTC