nim-lang / RFCs

A repository for your Nim proposals.
137 stars 23 forks source link

`macro customFor[T](a: T, b: ForLoopStmt): untyped = ...` #345

Open timotheecour opened 3 years ago

timotheecour commented 3 years ago

proposal

allow this: macro customFor[T](a: T, b: ForLoopStmt): untyped = ...

benefits

background

originally proposed in https://github.com/nim-lang/RFCs/issues/332#issuecomment-778433560

note

Araq commented 3 years ago

Too unspecific. What would the spec contain? When is customFor considered inside Nim's for loop handling?

Varriount commented 3 years ago

Is this problem due to the limitations of method-call syntax?
If so, would it be possible to improve the resolution logic instead? That way, not only would for-loop macros benefit, but general usability would too.

timotheecour commented 3 years ago

If so, would it be possible to improve the resolution logic instead?

that's a separate issue; without the RFC you can't have overloading.

Is this problem due to the limitations of method-call syntax?

actually that section needs to be updated now that https://github.com/nim-lang/Nim/pull/17196 was merged; var info = something().toSeq now does work; and all templates that can take iterable instead of untyped also do work with MCS/UFCS. But again, untyped params are still problematic for MCS/UFCS and I can't think of a way to fix this because the problem is essentially ambiguous (outside of https://github.com/timotheecour/Nim/issues/630). In short, this RFC is a separate topic.