Skip to content

Commit 05256cb

Browse files
authored
change ! to * in resistor-color syntax (#174)
1 parent b7a424c commit 05256cb

File tree

5 files changed

+41
-41
lines changed

5 files changed

+41
-41
lines changed

exercises/practice/resistor-color/.docs/instructions.append.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
## Defining syntax
44

5-
In this exercise, you must define syntax for colors using the `c!` prefix, e.g., `c!black`.
5+
In this exercise, you must define syntax for colors using the `c*` prefix, e.g., `c*black`.
66
This syntax should expand at compile time to each color's corresponding value as a `Fin 10`, according to the instructions.
7-
In the same way, you must define syntax for an array of all color values using `c!all`.
7+
In the same way, you must define syntax for an array of all color values using `c*all`.
88

99
This task will likely require you to use either notations or macros.
1010
You might want to check a [reference][macro-reference].
Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
/-
2-
notation "c!black" => (0 : Fin 10)
3-
notation "c!brown" => (1 : Fin 10)
4-
notation "c!red" => (2 : Fin 10)
5-
notation "c!orange" => (3 : Fin 10)
6-
notation "c!yellow" => (4 : Fin 10)
7-
notation "c!green" => (5 : Fin 10)
8-
notation "c!blue" => (6 : Fin 10)
9-
notation "c!violet" => (7 : Fin 10)
10-
notation "c!grey" => (8 : Fin 10)
11-
notation "c!white" => (9 : Fin 10)
12-
notation "c!all" => (Array.finRange 10)
2+
notation "c*black" => (0 : Fin 10)
3+
notation "c*brown" => (1 : Fin 10)
4+
notation "c*red" => (2 : Fin 10)
5+
notation "c*orange" => (3 : Fin 10)
6+
notation "c*yellow" => (4 : Fin 10)
7+
notation "c*green" => (5 : Fin 10)
8+
notation "c*blue" => (6 : Fin 10)
9+
notation "c*violet" => (7 : Fin 10)
10+
notation "c*grey" => (8 : Fin 10)
11+
notation "c*white" => (9 : Fin 10)
12+
notation "c*all" => (Array.finRange 10)
1313
-/
1414

15-
syntax "c!" ident:term
15+
syntax "c*" ident:term
1616

1717
macro_rules
18-
| `(c!black) => `((⟨0, by decide⟩ : Fin 10))
19-
| `(c!brown) => `((⟨1, by decide⟩ : Fin 10))
20-
| `(c!red) => `((⟨2, by decide⟩ : Fin 10))
21-
| `(c!orange) => `((⟨3, by decide⟩ : Fin 10))
22-
| `(c!yellow) => `((⟨4, by decide⟩ : Fin 10))
23-
| `(c!green) => `((⟨5, by decide⟩ : Fin 10))
24-
| `(c!blue) => `((⟨6, by decide⟩ : Fin 10))
25-
| `(c!violet) => `((⟨7, by decide⟩ : Fin 10))
26-
| `(c!grey) => `((⟨8, by decide⟩ : Fin 10))
27-
| `(c!white) => `((⟨9, by decide⟩ : Fin 10))
28-
| `(c!all) => `((Array.finRange 10))
18+
| `(c*black) => `((⟨0, by decide⟩ : Fin 10))
19+
| `(c*brown) => `((⟨1, by decide⟩ : Fin 10))
20+
| `(c*red) => `((⟨2, by decide⟩ : Fin 10))
21+
| `(c*orange) => `((⟨3, by decide⟩ : Fin 10))
22+
| `(c*yellow) => `((⟨4, by decide⟩ : Fin 10))
23+
| `(c*green) => `((⟨5, by decide⟩ : Fin 10))
24+
| `(c*blue) => `((⟨6, by decide⟩ : Fin 10))
25+
| `(c*violet) => `((⟨7, by decide⟩ : Fin 10))
26+
| `(c*grey) => `((⟨8, by decide⟩ : Fin 10))
27+
| `(c*white) => `((⟨9, by decide⟩ : Fin 10))
28+
| `(c*all) => `((Array.finRange 10))

exercises/practice/resistor-color/ResistorColor.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/-
2-
You must define syntax for colors using the `c!` prefix, e.g., `c!black`.
2+
You must define syntax for colors using the `c*` prefix, e.g., `c*black`.
33
This syntax should expand to its corresponding value as a `Fin 10`, according to the instructions.
44
5-
You must also define syntax `c!all` that expands to an array containing all color values.
5+
You must also define syntax `c*all` that expands to an array containing all color values.
66
77
Macros and notations are not qualified by namespace.
88
For this reason, this exercise does not define a namespace.

exercises/practice/resistor-color/ResistorColorTest.lean

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ import ResistorColor
33

44
open LeanTest
55

6-
theorem h_black: c!black = (0 : Fin 10) := by rfl
7-
theorem h_brown: c!brown = (1 : Fin 10) := by rfl
8-
theorem h_red: c!red = (2 : Fin 10) := by rfl
9-
theorem h_orange: c!orange = (3 : Fin 10) := by rfl
10-
theorem h_yellow: c!yellow = (4 : Fin 10) := by rfl
11-
theorem h_green: c!green = (5 : Fin 10) := by rfl
12-
theorem h_blue: c!blue = (6 : Fin 10) := by rfl
13-
theorem h_violet: c!violet = (7 : Fin 10) := by rfl
14-
theorem h_grey: c!grey = (8 : Fin 10) := by rfl
15-
theorem h_white: c!white = (9 : Fin 10) := by rfl
16-
theorem h_all: c!all = #[c!black, c!brown, c!red, c!orange, c!yellow, c!green, c!blue, c!violet, c!grey, c!white] := by rfl
6+
theorem h_black: c*black = (0 : Fin 10) := by rfl
7+
theorem h_brown: c*brown = (1 : Fin 10) := by rfl
8+
theorem h_red: c*red = (2 : Fin 10) := by rfl
9+
theorem h_orange: c*orange = (3 : Fin 10) := by rfl
10+
theorem h_yellow: c*yellow = (4 : Fin 10) := by rfl
11+
theorem h_green: c*green = (5 : Fin 10) := by rfl
12+
theorem h_blue: c*blue = (6 : Fin 10) := by rfl
13+
theorem h_violet: c*violet = (7 : Fin 10) := by rfl
14+
theorem h_grey: c*grey = (8 : Fin 10) := by rfl
15+
theorem h_white: c*white = (9 : Fin 10) := by rfl
16+
theorem h_all: c*all = #[c*black, c*brown, c*red, c*orange, c*yellow, c*green, c*blue, c*violet, c*grey, c*white] := by rfl
1717

1818
def main : IO UInt32 := do
1919
runTestSuitesWithExitCode []

generators/Generator/Generator/ResistorColorGenerator.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ def genTestCase (_exercise : String) (case : TreeMap.Raw String Json) : String :
2222
let funName := getFunName (case.get! "property")
2323
match funName with
2424
| "colors" =>
25-
let result := expected.getArr?.map (·.map (·.compress |> toLiteral |> (s!"c!{·}"))) |> getOk
25+
let result := expected.getArr?.map (·.map (·.compress |> toLiteral |> (s!"c*{·}"))) |> getOk
2626
let theorems := result.toList.mapIdx fun i color =>
27-
let c := color.dropPrefix "c!" |>.copy
27+
let c := color.dropPrefix "c*" |>.copy
2828
s!"
2929
theorem h_{c}: {color} = ({i} : Fin 10) := by rfl"
3030
(String.join theorems) ++ s!"
31-
theorem h_all: c!all = {result} := by rfl"
31+
theorem h_all: c*all = {result} := by rfl"
3232
| _ => ""
3333

3434
def genEnd (_exercise : String) : String :=

0 commit comments

Comments
 (0)