Re: SRFI 284: define-typed Artyom Bologov 26 Sep 2026 22:05 UTC

Arne,

>>> I’m not well-versed in writing grammars, but I would gladly integrate
>>> one. I can’t expect you to write it, but I’d be grateful if you did …
>>
>> It doesn’t have to be like Uber-Bachus-Naur-Super-Normal-Form-Grammar,
>> it can be quite informal. Informal grammars are even more useful, I
>> think—their crudeness and incompleteness forces you to express things in
>> a simpler way.
>
> Then I don’t think I really understood what you mean.
>
> Can you give an example?
>
> (I may be able to make something quickly from that)

Well, you can write an informal-ish thing, something like this (mostly
borrowed from R7RS section 7
<https://standards.scheme.org/r7rs-html5/index.html#7>, but broken
liberally)

<define-typed> = (define-typed (<name> <arg> ...) <types> <form>*)
<arg> = symbol
<name> = symbol
<form> = s-expression
<types> = (<argtype> ... (-> <rettype> ...)) ; 1: args with multiple returns
        | ((<rettype> ...) <argtype> ...) ; 2: args with multiple returns, sph-sc style
        | (<argtype> ... -> <rettype>) ; 3: args with a single return type
        | (<rettype> <argtype> ...) ; 4: args with a single return, sph-sc style
        | (<argtype> ...) ; 5: args only
<artype> = #f | symbol | #f | (lambda <formals> <body>)
<rettype> = #f | symbol | (lambda <formals> <body>)
<formals> = as per R7RS section 4.1.4 https://standards.scheme.org/r7rs-html5/index.html#4.1.4
<body> = as per R7RS section 4.1.4

Which brings me to another set of questions:

• Are R7RS lambdas the only type of lambdas / arbitrary code allowed as
  define-typed checks? Is everything else supposed to be a symbol? Any
  support for user-provided lambda syntaxes?
• (I kind of repeat myself here, but I really don’t understand it:) how
  does one distinguish between a single-expression return check like
  (cut = 1 <>) and a list of return checks?

Thanks,
--
Artyom Bologov
https://aartaka.me