Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a template for generating slide templates with identifier #42

Open
pietroppeter opened this issue Mar 14, 2024 · 3 comments
Open

a template for generating slide templates with identifier #42

pietroppeter opened this issue Mar 14, 2024 · 3 comments

Comments

@pietroppeter
Copy link
Contributor

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
Copy link
Owner

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
Copy link
Contributor Author

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
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants