[J3] 21-120r2: Discussion on the feasibility of any future enhancement of Enumeration Type

Brad Richardson everythingfunctional at protonmail.com
Tue Mar 2 15:39:40 UTC 2021


All,

I think Malcolm does have a point that enumeration does mean a numbered list of things, i.e. strictly 1, 2, 3, ...
However, I don't know of any other language that has been so pedantic about the meaning of the word enumeration.
I think Vipul's idea of an ordered collection of named constants can be accomplished with the enumeration type without confusion.

I would propose introducing TWO intrinsic functions; ORDINAL and VALUE_OF.
With the capability to specify the underlying type and value, VALUE_OF can return it.
In the case that you don't specify any different underlying type or values, ORDINAL and VALUE_OF *happen* to return the same thing, but it is now clear that the intention is different.
I would not be in favor of adding any implicit type conversions.

What do others think?

Regards,
Brad

On Tue, 2021-03-02 at 13:02 +0000, John Reid via J3 wrote:

> Vipul,
>
> I have an outstanding problem with your idea. On the one hand you want
>
> Type safety: Users don't get a constant from the wrong collection by
> accident
>
> and on the other hand you want
>
> Convenience: Users can reference the constant without extra syntax
>
> Here are some suggestions for rules:
>
> For a binary operation with both operands of the type and no matching
> defined operation, both are regarded as of the underlying type.
>
> For a binary operation with one operand of the type and no matching
> defined operation, it alone is regarded as of the underlying type (don't
> convert two different enums to their underlying types).
>
> For an assignment with both variable and expr of the type and no
> matching defined assignment, both are regarded as of the underlying type.
>
> For a function reference with one or more actual arguments of the type
> and no generic resolution, just the arguments of this type are regarded
> as of the underlying type.
>
> Apart from this, I think explicit type conversion should be required to
> alert the user to the danger.
>
> What do you think?
>
> Cheers,
>
> John.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20210302/4e5791ad/attachment.htm>


More information about the J3 mailing list