10. 치트시트
Extract the goal:
Lean.Elab.Tactic.getMainGoal목표(goal) 추출:
Lean.Elab.Tactic.getMainGoalUse as
let goal ← Lean.Elab.Tactic.getMainGoalExtract the declaration out of a metavariable:
mvarId.getDeclwhenmvarId : Lean.MVarIdis in context. For instance,mvarIdcould be the goal extracted usinggetMainGoalExtract the type of a metavariable:
mvarId.getTypewhenmvarId : Lean.MVarIdis in context.Extract the type of the main goal:
Lean.Elab.Tactic.getMainTargetlet goal ← Lean.Elab.Tactic.getMainGoal형태로 사용메타변수에서 선언(declaration) 추출:
mvarId.getDeclmvarId : Lean.MVarId가 컨텍스트에 있을 때 사용. 예를 들어,mvarId는getMainGoal로 추출한 목표일 수 있음메타변수의 타입 추출:
mvarId.getTypemvarId : Lean.MVarId가 컨텍스트에 있을 때 사용.주 목표의 타입 추출:
Lean.Elab.Tactic.getMainTargetUse as
let goal_type ← Lean.Elab.Tactic.getMainTargetlet goal_type ← Lean.Elab.Tactic.getMainTarget형태로 사용Achieves the same as
아래와 동일한 결과를 얻음:
let goal ← Lean.Elab.Tactic.getMainGoal
let goal_type ← goal.getTypelet goal ← Lean.Elab.Tactic.getMainGoal
let goal_type ← goal.getTypeExtract local context:
Lean.MonadLCtx.getLCtx로컬 컨텍스트 추출:
Lean.MonadLCtx.getLCtxUse as
let lctx ← Lean.MonadLCtx.getLCtxExtract the name of a declaration:
Lean.LocalDecl.userName ldeclwhenldecl : Lean.LocalDeclis in contextExtract the type of an expression:
Lean.Meta.inferType exprwhenexpr : Lean.Expris an expression in contextlet lctx ← Lean.MonadLCtx.getLCtx형태로 사용선언의 이름 추출:
Lean.LocalDecl.userName ldeclldecl : Lean.LocalDecl이 컨텍스트에 있을 때 사용표현식의 타입 추출:
Lean.Meta.inferType exprexpr : Lean.Expr가 컨텍스트에 있을 때 사용Use as
let expr_type ← Lean.Meta.inferType exprlet expr_type ← Lean.Meta.inferType expr형태로 사용Convert a declaration into an expression:
Lean.LocalDecl.toExpr선언을 표현식으로 변환:
Lean.LocalDecl.toExprUse as
ldecl.toExpr, whenldecl : Lean.LocalDeclis in contextldecl : Lean.LocalDecl이 컨텍스트에 있을 때ldecl.toExpr형태로 사용For instance,
ldeclcould belet ldecl ← Lean.MonadLCtx.getLCtxCheck whether two expressions are definitionally equal:
Lean.Meta.isDefEq ex1 ex2whenex1 ex2 : Lean.Exprare in context. Returns aLean.MetaM BoolClose a goal:
Lean.Elab.Tactic.closeMainGoal exprwhenexpr : Lean.Expris in context예를 들어,
ldecl은let ldecl ← Lean.MonadLCtx.getLCtx로 얻은 값일 수 있음두 표현식이 정의적으로 동일한지 확인:
Lean.Meta.isDefEq ex1 ex2ex1 ex2 : Lean.Expr가 컨텍스트에 있을 때 사용.Lean.MetaM Bool을 반환목표 닫기:
Lean.Elab.Tactic.closeMainGoal exprexpr : Lean.Expr가 컨텍스트에 있을 때 사용meta-sorry:
Lean.Elab.admitGoal goal, whengoal : Lean.MVarIdis the current goalmeta-sorry:
Lean.Elab.admitGoal goal,goal : Lean.MVarId가 현재 목표일 때 사용Print a “permanent” message in normal usage:
Lean.logInfo f!"Hi, I will print\n{Syntax}"일반 사용 시 “영구적인” 메시지 출력:
Lean.logInfo f!"Hi, I will print\n{Syntax}"Print a message while debugging:
dbg_trace f!"1) goal: {Syntax_that_will_be_interpreted}".디버깅 중 메시지 출력:
dbg_trace f!"1) goal: {Syntax_that_will_be_interpreted}".Throw an error:
Lean.Meta.throwTacticEx name mvar message_datawherename : Lean.Nameis the name of a tactic andmvarcontains error data.오류 발생시키기:
Lean.Meta.throwTacticEx name mvar message_dataname : Lean.Name은 tactic의 이름이고mvar은 오류 데이터를 담음.Use as
Lean.Meta.throwTacticExtac goal (m!“unable to find matching hypothesis of type ({goal_type})”)where them!formatting builds aMessageData` for better printing of termsLean.Meta.throwTacticExtac goal (m!“unable to find matching hypothesis of type ({goal_type})”)형태로 사용. 여기서m!포매팅은 항(term)을 더 잘 출력하기 위한MessageData`를 생성함.
TODO: 추가?
- Lean.LocalContext.forM
- Lean.LocalContext.findDeclM?