[J3] Syntax for enumeration

Ondřej Čertík ondrej at certik.us
Tue Oct 15 17:50:49 EDT 2019



On Tue, Oct 15, 2019, at 8:39 AM, Ondřej Čertík via J3 wrote:
> Hi,
> 
> I would like to discuss some possible options for syntax for 
> enumeration. Currently the only proposed syntax is in:
> 
> https://j3-fortran.org/doc/year/19/19-232.txt
> 
>     TYPE,ENUMERATION,PUBLIC :: my_enum
>         ENUMERATOR a,b
>         ENUMERATOR c
>         INITIAL c
>     END TYPE
> 
>     TYPE,ENUMERATION,EXTENDS(my_enum),PRIVATE :: my_extra_enums
>         ENUMERATOR :: d
>         ENUMERATOR,PUBLIC :: e
>         ENUMERATOR,PRIVATE :: f
>         INITIAL :: a
>     END TYPE
> 
> 
> and it feels very verbose. I would like to propose and discuss some 
> simpler alternatives. First I think we should figure out the most 
> common case:
> 
>     TYPE,ENUMERATION :: my_enum
>         ENUMERATOR a,b
>         ENUMERATOR c
>     END TYPE
> 
> Here are some examples:
> 
> 1)
> 
>     TYPE,ENUM :: my_enum
>         a,b
>         c
>     END TYPE
> 
> 2)
> 
>     TYPE,ENUM :: my_enum
>         CASE a,b
>         CASE c
>     END TYPE
> 
> 3)
> 
>     ENUM :: my_enum
>         CASE a,b
>         CASE c
>     END ENUM
> 
> 4)
> 
>     ENUM :: my_enum
>         a, b, c
>     END ENUM

The number 4) is consistent with section 7.6
Enumerations and enumerators in the standard, where it says in Note 4:

ENUM, BIND(C)
    ENUMERATOR :: RED = 4, BLUE = 9
    ENUMERATOR YELLOW
END ENUM

Although the ENUMERATOR could perhaps be optional.

Ondrej


More information about the J3 mailing list