Safe enumerations for codesets Lassi Kortela (13 Dec 2022 12:09 UTC)
Re: Safe enumerations for codesets Marc Nieper-Wißkirchen (14 Dec 2022 08:17 UTC)
Re: Safe enumerations for codesets Lassi Kortela (14 Dec 2022 09:05 UTC)
Re: Safe enumerations for codesets Lassi Kortela (14 Dec 2022 09:39 UTC)
Re: Safe enumerations for codesets Marc Nieper-Wißkirchen (14 Dec 2022 11:29 UTC)
Re: Safe enumerations for codesets Lassi Kortela (14 Dec 2022 12:42 UTC)
Re: Safe enumerations for codesets Marc Nieper-Wißkirchen (14 Dec 2022 18:26 UTC)
Re: Safe enumerations for codesets Lassi Kortela (15 Dec 2022 09:29 UTC)
Re: Safe enumerations for codesets Lassi Kortela (15 Dec 2022 09:48 UTC)

Re: Safe enumerations for codesets Marc Nieper-Wißkirchen 14 Dec 2022 08:16 UTC

The disadvantage of this approach is that you bind many identifiers in
your namespace.

For a better approach (which should be promoted instead), see
`define-enumeration' in R6RS and SRFI 209.

Marc

Am Di., 13. Dez. 2022 um 13:09 Uhr schrieb Lassi Kortela <xxxxxx@lassi.io>:
>
> Here's a simple way to roll your own enums:
>
> (define-syntax define-enum
>    (syntax-rules ()
>      ((define-enum enum symbol ...)
>       (begin (define symbol 'symbol) ...
>              (define enum '(symbol ...))))))
>
> (define-enum errno
>    EPERM
>    ENOENT
>    ESRCH
>    EINTR
>    EIO
>    ENXIO
>    E2BIG
>    ENOEXEC
>    EBADF
>    ECHILD
>    EDEADLK
>    ENOMEM
>    EACCES
>    EFAULT)
>
> Now typos such as (codeset-message 'errno ECHILE) will be caught.
>
> A safer version such as (codeset-message errno (errno ECHILE)) can
> probably be done with syntax-case.
>
> As discussed in an earlier email on this list, it's not appropriate to
> define standard enums since the full set of values seen in the wild
> cannot be standardized. Each application or library wishing to use safe
> enums should list the codes that it needs.
>