Zulip Chat Archive

Stream: lean4

Topic: macro problem


Joseph O (May 19 2022 at 15:12):

Why doesn't this macro work?

syntax "let" ident "=" term "=>" term : term

macro_rules
  | `(let $name:ident := $v:term in $e:term) =>
    `(let $name := $v; $e)

def test : Nat :=
  let x := 1 in x+1

getting the error expected term

Sébastien Michelland (May 19 2022 at 15:15):

Your syntax rule doesn't match the matching that you perform in macro_rules. There's = vs := and => vs in. Try this:

syntax "let" ident ":=" term "in" term : term

macro_rules
  | `(let $name:ident := $v:term in $e:term) =>
    `(let $name := $v; $e)

def test : Nat :=
  let x := 1 in x+1

#eval test -- 2

Arthur Paulino (May 19 2022 at 15:16):

Or maybe you meant this?

syntax "let" ident "=" term "=>" term : term

macro_rules
  | `(let $name:ident = $v:term => $e:term) =>
    `(let $name := $v; $e)

def test : Nat :=
  let x = 1 => x+1

#eval test -- 2

Notification Bot (May 20 2022 at 13:03):

Joseph O has marked this topic as unresolved.

Joseph O (May 20 2022 at 13:04):

Oh wait how come in this case i get the error expected term

| `(let* $name:ident := $v:term in $t:term) => `(let rec $name := $v; $t)

Last updated: Dec 20 2023 at 11:08 UTC