Zulip Chat Archive
Stream: general
Topic: parse location for multiple locations
Saif Ghobash (May 05 2021 at 20:46):
I have been reading the tactic writing guide and have been following along, however I am playing around with trying to extend the mul_left tactic to take more than one location and I am having a difficult time understanding similar tactics like change and how it manages to accomplish multiple locations, how could I extend mul_left to do this?
meta def tactic.interactive.mul_left (q : parse texpr) : parse location → tactic unit
| (loc.ns [some h]) := do
e ← tactic.i_to_expr q,
H ← tactic.get_local h,
`(%%l = %%r) ← tactic.infer_type H,
«have» h ``(%%e*%%l = %%e*%%r) ``(congr_arg (λ x, %%e*x) %%H),
tactic.clear H
| l := -- I do not really know what to do here
Patrick Massot (May 05 2021 at 20:55):
It will be easier if you write a non-interactive tactic that does the work at one place and then call it on a list of locations using a monadic iteration.
Patrick Massot (May 05 2021 at 21:01):
There is a monadic loop section in the tutorial.
Patrick Massot (May 05 2021 at 21:04):
Patrick Massot (May 05 2021 at 21:06):
If you are serious about learning tactic writing, you should also watch Rob's full series of tutorials at https://www.youtube.com/watch?v=o6oUjcE6Nz4&list=PLlF-CfQhukNnq2kDCw2P_vI5AfXN7egP2
Saif Ghobash (May 05 2021 at 21:08):
Sorry for the delay, I was implementing your suggestion, I came up with this
meta def mul_left_other (e : expr) : option name → tactic unit
| none := return ()
| (some h) := do
H ← tactic.get_local h,
`(%%l = %%r) ← tactic.infer_type H,
«have» h ``(%%e*%%l = %%e*%%r) ``(congr_arg (λ x, %%e*x) %%H),
tactic.clear H
meta def tactic.interactive.mul_left (q : parse texpr) : parse location → tactic unit
| (loc.ns l) := do
e ← tactic.i_to_expr q,
l.mmap' (λ h, mul_left_other e h)
| _ := tactic.fail "no wildcards yet"
Thank you for the help @Patrick Massot
Saif Ghobash (May 05 2021 at 21:08):
I'll look at Robs tutorials as well :)
Last updated: Dec 20 2023 at 11:08 UTC