tomhrr / dale

Lisp-flavoured C
BSD 3-Clause "New" or "Revised" License
1.02k stars 48 forks source link

Overlapping enums? #149

Closed porky11 closed 7 years ago

porky11 commented 7 years ago

When using external libs (i.e. opengl) there are functions, that take different sets of the same constants as parameters. Example: function f1 can take a or b as parameter, function f2 can take a and c as parameter. Something like this using enums won't work:

(def-enum T1 extern int (a b))
(def-enum T2 extern int (a c))

(def f1 (fn extern-c void ((x T1))))
(def f2 (fn extern-c void ((x T2))))

So enums may not be a good choice in such cases. Would it be best in this case to define a general enum for all overlapping constants, and handling the type-checking in macro-versions of the functions, or may something like overlapping enums be implemented into the language? So the chosen function won't dispatch on the value type, but the chosen value will dispatch on the function parameter type instead.

porky11 commented 7 years ago

With the original version of enums this wasn't a problem. I think defining enums in own namespaces seems a good solution.