HugoGranstrom / nimiSlides

A Reveal.js theme for nimib for making slideshow presentations in Nim
https://hugogranstrom.com/nimiSlides
MIT License
80 stars 6 forks source link

a template for generating slide templates with identifier #42

Open pietroppeter opened 6 months ago

pietroppeter commented 6 months ago

I am yet again making a new set of slides with nimislides (public soon) and as usual I try to innovate a bit my workflow.

For this feature request it is harder to make a title for this feature (and even harder to understand the title) than an example:

import nimib, nimislides

template slide(ident: untyped, body: untyped) =
  template `slide ident` =
    slide:
      body

# I use this idiom currently
template slideTitleAlt =
  slide:
    nbText: "## My title slide"

# and this is sugar for this idiom
slide(Title):
  nbText: "## My title slide (but using a template)"

when isMainModule:
  nbInit(theme = revealTheme)
  setSlidesTheme(Serif)
  # having slides called here makes it easier to add them and remove them while creating a presentation
  slideTitle
  slideTitleAlt
  nbSave

the proposal is to introduce the template slide(ident: untyped, body: untyped) as above to allow the isMainModule workflow with reduced indentation. Ah in the example above I did not use it but I would probably export the template by default (since it can be used from different sets of slides).

HugoGranstrom commented 6 months ago

Hmm, can you come up with another name for the template than slide? Overloading of templates with untyped bodies is already a bit of a mess so would like to avoid that. Otherwise I like the idea 😄

pietroppeter commented 6 months ago

I was bitten right after with problems with the overload! Agree that is scary but it should not be. At some point I would want to investigate all these issues with templates and try to find some minimal reproducible examples.

Will try to think of an alternative name

HugoGranstrom commented 6 months ago

There isn't really anything to reproduce in these cases really. It is just the fact that the compiler needs to decide which overload to use. So if the first argument to a template can be either untyped or string for example, then it must type-check it to find out what it is. And if it isn't a string, well then it has already type-checked that code which could error if it is invalid.

There was a feature in Nim 1.6 that allowed optional parameters in templates before an untyped block. But it was moved behind an experimental switch in a later version because it caused weird behaviors.