Replies: 3 comments 4 replies
|
a very very short answer is that enums a sometimes times replace string and integer constants, but Rye (like REBOL) has first class words, which are indexed items (integers behind the scenes). Enums are also used to enforce selection and exhaustive selection (for example some languages require you to switch on all possible values of enum, to prevent bugs). Since Rye is not statically typed, there are less mechanisms or convention to do that, since other things are not checked at "compuile time" either since there is no compile time. Havin a way to determine, X must be one of these { a b c } would also add information and be a tool in Ryelang, but it's a question if that if solved with sort of setup early binding way, like enums is. Or in a more late-binding way, what is more a direction of Rye and other dynamic languages. We would want to have a way to make sure certain value is of a limited set of values, but probably it would be solved in a Rye-ish way by using validation dialect. Validation dialect can be tied to kinds (something I haven't demonstrated much so far, but it's there, the whole kinds , validators , convertors thing) and Kinds sort of enable something like early bind enums, with possibility of all the other validation rules also. This means we should add to validation dialect something like validate { one-of { a b c } } (or any-of) and probably also { some-of { a b c } } for "multichoice" values. Then I should document kinds more, with examples how to use this. Do you have any Rye example where enums would benefit you? If you have, I would be glad to see it, so I can think about this more ... Thanks for making me think about this ... sometimes I need some external motivation! (I wanted to write a short answer first but got carried away) :) |
|
thanks for the detailed response :). I was just playing around with tables and realised there's no nice, and safe, way to specify valid table field values: context is too heavy for this, but even if there was a lightweight namespace word it's still too cumbersome to spell out You make a good argument though. And I do like the idea of a validation dialect. But enums to me are too ubiquitous so I always reach for them. And they are a very simple and powerful way to write safer code by default, which is what Rye aims for. A validation dialect you still need to remember to call it everywhere. I need to think about this some more. |
|
I will start with adding one-of and some-of to validation dialect. |
Uh oh!
There was an error while loading. Please reload this page.
Curious why there is no enum of any kind in Rye? Was this intentional or just hasn't arrived yet? If intentional what's the rationale?
All reactions