簡體   English   中英

Ltac是否可能進行“ printf調試”?

[英]Is “printf-debugging” possible in Ltac?

有沒有辦法在Ltac程序的中間打印變量的值(假設,策略,術語)?

是的,請使用idtac策略。

您可以向idtac傳遞一個常量字符串以進行打印。 如果您對它們進行模式匹配,它也可以打印標識符(例如假設名稱),如果您通過模式匹配或type of訪問它們,則可以打印它們的類型。 您還可以打印術語或Ltac限界變量的內容。 最后,您可以傳遞idtac多個參數以將它們全部打印出來。 您提到了打印策略-不幸的是,這是您不能使用idtac打印的一件事。 如果嘗試這樣做,您只會得到<tactic Closure>。

這里有很多例子:

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.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM