Chapter 1 · Foundations

When Lean says no

You are reading the whole lesson on one page. Back to one step at a time

Step 1 of 22 · Concept

A message has a place and a text

In this lesson you learn to read every message Lean gives, and which one to fix first.

A message starts with a header such as Main.lean:2:31: error:. It names the file, the line, the column (counted from 0) and the kind: error or warning. Then comes the text, and often the goal.

Some errors also give their name in brackets: error(lean.unknownIdentifier):.

theorem four : 2 + 2 = 4 := by rfl
theorem nine : 4 + 4 = 9 := by rfl
#eval 10
theorem again : 4 + 4 = 9 := nine
theorem twelve : 6 + 6 = 12 := twelf
#print axioms again
theorem four : 2 + 2 = 4 := by rfl
theorem again : 2 + 2 = 4 := fuor
#print again
example (n : Nat) : n + 0 = n := by rfl
example (n : Nat) : 0 + n = n := by rfl
def double (n : Nat) : Nat := n + n
-- nine : 4 + 5 = 9
theorem nine : 4 + 5 = 10 := by rfl
-- again : 4 + 5 = 9
theorem again : 4 + 5 = 9 := nien
-- ten : double 5 = 10
theorem ten : double "5" = 10 := by rfl
-- small : 9 < 10
theorem small : 10 < 9 := by decide
def double (n : Nat) : Nat := n + n
-- twelve : 6 + 6 = 12
theorem twelve : 6 + 6 = 12 by rfl
-- twelve_again : 6 + 6 = 12
theorem twelve_again : 6 + 6 = 12 := twelf
-- ten_double : double 5 = 10
theorem ten_double : double "5" = 10 := by
  sorry
def add (a b : Nat) : Nat := a + b
def result : Nat → Nat := add 2
#eval result
Terminal
Step 1 of 6Two mistakes

Keyboard shortcuts

The step

ContinueEnter
Previous / next stepAlt+[ · Alt+]
Move along the steps bar← → Home End, then Enter
From a quiz's title to its answers↓
Skip to the stepTab, then Enter (first on the page)
Course outlineAlt+O
These shortcuts?

The workspace

Run the stepCtrl+Enter (⌘↵ on a Mac)
Lesson → editor → consoleF6 (Shift+F6 back)
Output ↔ TerminalCtrl+`
Focus the editorCtrl+. (⌘. on a Mac)
Hide or show the lessonAlt+L
Restore, close a messageEsc (outside the editor and the terminal)

The editor

Leave the editorF6 (Shift+F6 back); or Ctrl+M (⌃⇧M on a Mac), then Tab moves the focus (not in the vim mode)
Open a file by nameCtrl+P (⌘P on a Mac)
All commandsCtrl+Shift+P (⌘⇧P on a Mac) or F1
Go to a lineCtrl+G (⌃G on a Mac)
Show or hide the filesCtrl+B (⌘B on a Mac)
Previous / next file tabCtrl+Shift+[ · Ctrl+Shift+] (⌘⇧[ · ⌘⇧] on a Mac)
The file tabs← → Home End on a tab; Delete closes it
Save the files nowCtrl+S (⌘S on a Mac)
Go to a symbol in the fileCtrl+Shift+O (⌘⇧O on a Mac)
Go to the definitionF12
Format the fileCtrl+Shift+F (⌘⇧F on a Mac), or Shift+Alt+F
Go back / forward after a jumpAlt+← · Alt+→ (⌃- · ⌃⇧- on a Mac)