Zulip Chat Archive
Stream: mathlib4
Topic: Delaborating !![] notation
Eric Wieser (Mar 02 2024 at 10:32):
I am trying to write a delaborator for !![]
notation, but I fairly immediately run into trouble when trying to generate syntax:
import Mathlib.Data.Matrix.Notation
open Lean PrettyPrinter.Delaborator SubExpr Qq
@[delab app.DFunLike.coe]
def delabMatrixOf : Delab :=
whenPPOption getPPNotation <| do
let e ← getExpr
let ⟨_, ~q(Matrix (Fin (OfNat.ofNat $n)) (Fin (OfNat.ofNat $m)) $α), ~q(Matrix.of $e)⟩ ← inferTypeQ' e | failure
let some m := m.natLit? | failure
let some n := n.natLit? | failure
if m = 0 then
let semicolons : Term := ⟨mkNullNode <| .mk <| List.replicate n <| Syntax.atom (← MonadRef.mkInfoFromRefPos) ";"⟩
return (← `(!![$semicolons]))
failure
#check !![;;]
Is there any way to use syntax quotations to build the repeated ;
s?
Mario Carneiro (Mar 02 2024 at 12:52):
Eric Wieser (Mar 02 2024 at 12:54):
Edited above, sorry
Mario Carneiro (Mar 02 2024 at 12:55):
for the case other than 0xN or Nx0 I would bet you can do it, but sequences of atoms don't really work well with syntax quotations
Mario Carneiro (Mar 02 2024 at 12:55):
I guess that's the case you are having issues with
Eric Wieser (Mar 02 2024 at 12:57):
I didn't even try the nondegenerate cases, but I agree that they sound a little easier
Mario Carneiro (Mar 02 2024 at 12:59):
actually, the same syntax used to parse them seems to work to generate them too:
if m = 0 then
let semicolons := Array.mkArray n (← getRef)
return (← `(!![$[;%$semicolons]*]))
failure
#check !![;;]
Eric Wieser (Mar 02 2024 at 13:00):
Wow, I would not have expected %
to accept an array
Mario Carneiro (Mar 02 2024 at 13:00):
well, it's the $[...]*
that generates an array
Mario Carneiro (Mar 02 2024 at 13:00):
all of the bindings inside that are array-ified
Eric Wieser (Mar 02 2024 at 13:05):
Mario Carneiro said:
well, it's the
$[...]*
that generates an array
What documentation could I read to learn this?
Mario Carneiro (Mar 02 2024 at 13:06):
good question
Mario Carneiro (Mar 02 2024 at 13:06):
I'm not aware of any documentation that covers quotation syntax, which is bad since it's so arcane
Mario Carneiro (Mar 02 2024 at 13:07):
well it's always bad not to have docs but it's especially bad when it's rarely used and sigil heavy
Last updated: May 02 2025 at 03:31 UTC