Zulip Chat Archive

Stream: Is there code for X?

Topic: Quoting a TSepArray


Jeremy Salwen (May 09 2023 at 15:40):

How do you explicitly construct a value of type TSepArray using quotation?

For example

quote (#[`simp, `foo])

gives a TSyntax, not a TSepArray.

Kyle Miller (May 09 2023 at 15:46):

Could you give more context (maybe a #mwe)? The quote function is for creating syntax that would evaluate to #[`simp, `foo]. Is that what you want? Or are you wanting a TSepArray `ident to splice in somewhere?

Jeremy Salwen (May 09 2023 at 15:48):

I want to call a library function that takes TSepArray (addRelatedDecl), and I just want to construct the argument explicitly.

Jeremy Salwen (May 09 2023 at 15:49):

Constructing a TSyntax seemed close to my goal of constructing a TSepArray, but maybe that is the wrong path.

Kyle Miller (May 09 2023 at 15:52):

One thing you need to make sure to do is create a TSyntax `Lean.Parser.Term.attrInstance for each attribute, which isn't just a Name, so that takes a bit more work. quote is specifically for creating a TSyntax `term (a.k.a. a Term).

Kyle Miller (May 09 2023 at 15:53):

Do you need this to be programmatic, or will it be a fixed array?

Jeremy Salwen (May 09 2023 at 15:54):

It is just a fixed array.

Kyle Miller (May 09 2023 at 15:59):

I guess this is one way to do it:

example : MetaM (Syntax.TSepArray `Lean.Parser.Term.attrInstance ",") := do
  let arr : Syntax.TSepArray `Lean.Parser.Term.attrInstance "," := 
  let arr := arr.push ( `(Lean.Parser.Term.attrInstance|simp))
  let arr := arr.push ( `(Lean.Parser.Term.attrInstance|foo))
  return arr

Jeremy Salwen (May 09 2023 at 15:59):

Ah, thank you!


Last updated: Dec 20 2023 at 11:08 UTC