Hey folks!

As the immediate pragma is deprecated, I'm updating my packages to remove references to it. I've got one situation where I'm curious about the best alternative. It's this template. Basically, I'm using a template to define a type with a few procs. When I remove {. immediate .}, my test fails.

I know I could achieve this using a macro instead, but since all I'm doing is some basic substitutions, a template feeks a bit more clear. What's the best way to achieve this?

2017-07-16 15:46:27

Try this prototype:

template defineIndex*(name, source, extractIt, cmpAB: untyped) = ...

2017-07-16 16:46:15

Yup, that works.

For anyone looking to spot the difference, here is original signature:

template defineIndex*(name, source: typedesc, extractIt, cmpAB: untyped) {.immediate.} = ...

When you just remove the immediate, it breaks. Here is the working signature:

template defineIndex*(name, source, extractIt, cmpAB: untyped) = ...

The difference is that _all of the arguments are untyped, versus using typedesc for the first two arguments.

@Araq, if you've got a moment (or anyone else that can offer details): why does this work?

2017-07-16 19:42:45
Because templates with not untyped (that is typed) arguments expand later, when types of actual arguments are known; they could not be called otherwise. And templates with only untyped arguments don't depend on types of actual arguments on call site (because of no type check) and can be expanded immediately, what {.immediate.} stands for.
2017-07-17 03:01:14