-
Notifications
You must be signed in to change notification settings - Fork 3
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
make proc nimQuery(setting: Setting): RootObj {.magic.}
=> return a type that depends on the enum
#9
Comments
Oh my, please ... no. I think it's a bad design, reminds me of |
i was half expecting that, and I kind of agree. Then this? proc nimVerCT*(): tuple(int,int,int)
proc getExperimental*(): seq[Experimental] # type Experimental = enum ...
proc getBackend(): Backend
when nimVerCT() < (1,3,5) : ...
when Experimental.notnil in getExperimental(): ... |
What's wrong with the existing solutions? |
# we shouldn't need serialization + deserialization
doAssert querySetting("nimverct").parseTo((int,int,int)) == (1,3,5)
doAssert querySetting("assertions").parseTo(bool) # or reach for `system.compileOption` ... but why and the compiler can't always help you if you misuse: doAssert "forLoopmacros" in querySetting("experimental") # bug (wrong style => you'll silently get wrong answer)
doAssert "forLoopMacros".normalize in querySetting("experimental") # still buggy if you mistype This is more user friendly, self documenting and impossible to misuse or you'll get CT error: # either the "sysctl"-like way i gave in top post, or as individual procs, I'm agnostic:
doAssert nimVerCT() == (1,3,5)
doAssert Experimental.forLoopMacros in getExperimental()
doAssert assertions() # or maybe `nimQuery(assertions)` still in this case
|
Well as long as it doesn't bloat system.nim further, I'm fine with more type-safe additions. |
@Araq ok with following?
proposal
compileOption
,querySettingSeq
andquerySetting
(or "soft" deprecate ie recommend the alternative here)why
RootObj
? because that's what used initerator fields*[T: tuple|object](x: T): RootObj
to allow returning a type that can depend on input argumentexample
note
compilesettings
stays a "low-level" module in the sense it's usable by low level modules (eg doesn't depend on iterators, dollars etc)implementation
no particular difficulty
The text was updated successfully, but these errors were encountered: