Thanks all :)

> I realize now this is probably too much for your style guide :D

I realize that a macro might be the least bad option here :)

> if val in enmRange and val.E

@ElegantBeef this performs the E conversion before it's checked as being part 
of the set, which a little bit ... defeats the purpose ;) more to the point 
though, `enmRange` isn't valid for a holey enum - try your code with a valid 
ordinal :)

> fusion/astdsl

@planetis Nice! I'd probably go for a fusion-less version of that, fusion is 
difficult to depend on in a larger project. Another small detail is that the 
generated AST is in the form `var x; case .. of ..: x = ..` \- it doesn't 
_really_ matter for trivial cases like this, but I'd probably strive to keep 
the `let x = case ...` form for the generated code which lets the compiler know 
that this is a total conversion and for example avoid the zero-init.

> This is a basic pattern of a failable data conversion which calls for the 
> Result type.

Yes, I'd of course use a `Result`/`Option` but it's an unfortunate reality that 
the standard library uses `ValueError` for parsing failures in general, so it 
was easier to ask the question this way. The focus is really on good tricks to 
determine the valid set of ordinals in the presence of gaps - after that, the 
world is your oyster. <https://github.com/arnetheduck/nim-result>/ might be 
more convenient if you don't want all of stew (though stew comes with a bunch 
of `Result`-based utilities for all kinds of things like IO).

> raise newException(ValueError, "msg goes here")

I like to rant about this anti-pattern, so here goes: it hides the true type of 
the exception (`ref ValueError`), it doesn't allow conveniently setting other 
fields (`parent` or custom fields etc), _and_ it's more typing. 

Reply via email to