是否有一种方法可以在Ltac程序中间打印变量的值(假设,策略,术语)?
答案 0 :(得分:2)
是的,请使用idtac
策略。
您可以传递idtac
常量字符串以进行打印。如果您对它们进行模式匹配,它也可以打印标识符(例如假设名称),如果您通过模式匹配或type of
访问它们,则可以打印它们的类型。您还可以打印术语或Ltac限界变量的内容。最后,您可以传递idtac
多个参数以将它们全部打印出来。您提到了打印策略-不幸的是,这是您无法使用idtac
打印的一件事。如果尝试这样做,您只会得到
这里有很多例子:
Goal True -> False.
intro Htrue.
idtac "hello world". (* prints hello world *)
match goal with
| [ H: True |- _ ] => idtac H (* prints Htrue *)
end.
match goal with
| |- ?g => idtac g (* prints False *)
end.
let t := type of Htrue in idtac t. (* prints True *)
let x := constr:(1 + 1) in idtac x. (* prints (1 + 1) *)
idtac "hello" "there". (* prints hello there *)
(* note that this is an Ltac-level function, not a Gallina function *)
let x := (fun _ => fail) in idtac x. (* prints <tactic closure> *)
Abort.