-
Notifications
You must be signed in to change notification settings - Fork 439
Metaprogramming for dummies
-
MetaM is the monad you want to use if you modify metavariables.
-
TacticM is the topmost monad for tactic-writing. You can get and set goals, etc
In a do
block (←) takes care of bumping to a stronger monad
- mapM
- (←)
- filterM
- elabTerm
- elabTermForApply
- elabTermEnsuringType
withLocalDeclD
open Lean.Expr
Check whether something is a metavariable: isMVar Create metavariable: Assign metavariable: Check whether it is assigned
Note about delayed assignments (and reference to meta-book)
isFVar fvarId! FVarId.getUserName
isBVar
isLambda lambdaTelescope
isForall forallTelescope
isApp getAppFn getAppNumArgs getAppArgs
open Lean.Elab.Tactic
getGoals getMainGoal setGoals
open Lean.Elab.Tactic
evalTactic withMainContext liftMetaTactic
Lean.MVarId.apply
Example:
If no universe levels: mvarId.apply (mkConst foo []) If known universe levels: mvarId.apply (mkConst
foo [u,v])
Otherwise: mvarId.apply (← mkConstWithFreshMVarLevels ``foo)
- The easy stuff
- dbg_trace "foo {var}" -- Very lowlevel works everywhere
- logInfo "foo" -- works in any monad that supports logging
- trace[identifier] "foo"
initialize registerTraceClass `identifier