Re: SRFI 284: define-typed Artyom Bologov 27 Sep 2026 00:30 UTC

Arne,

>> <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
>
> sph-sc style is supported by the implementation, but not part of the
> SRFI. While I like it, and while it might enable rest arguments (though
> my experiment with implementing them failed today), it is also more
> error-prone.

I see. Is there an extension space in the SRFI that’d accommodate that
syntax?

>> • 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?
>
> It should support everything that evaluates to a predicate.

Oh, okay, good!

>> • (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?
>
> For the sph-sc style you can’t.
>
> With the new release of this SRFI, the distinction is:
>
> 1. <argtypes> -> <form>: a single return type, checked by whatever the form evaluates to.
> 2. <argtypes> (-> <form>): a list of return types, checked by whatever the form evaluates to.
> 3. <argtypes> (-> <form> <form> <form> ...):  multiple return types, checked by whatever the forms evaluate to.

That sounds perfect! I like how -> becomes a reliable anchor for things,
it’s quite elegant!

> <define-typed> = (define-typed (<name> <arg> ...) <types> <body>)
> <arg> = symbol
> <name> = symbol
> <types> = (<argtype> ... -> <rettype>)       ; 1: args with a single return type
>         | (<argtype> ... (-> <retlisttype>)) ; 2: args with multiple returns,
>                                              ;    checked with a single
>                                              ;    procedure that receives the
>                                              ;    return values as list
>         | (<argtype> ... (-> <rettype> <rettype> <rettype> ...)) ; 3: args with multiple returns
>         | (<argtype> ...)                    ; 4: args only
> <artype> = #f | symbol | <predicate-form>
> <rettype> = #f | symbol | <predicate-form>
> <retlisttype> = procedure that receives a list with all return values and returns a true value or #f
> <predicate-form> = procedure with one argument that returns a true value or #f

<predicate-form> might be better explained as “_a form returning_ a
procedure with one argument that…” but that’s really minor. Also, I
think that “predicate” is clear enough to not really need an explanation
about return values and number of args.

> <formals> = as per R7RS section 4.1.4 https://standards.scheme.org/r7rs-html5/index.html#4.1.4

These are unused now, I believe.

> <body> = as per R7RS section 4.1.4
>
> Is it clear this way?

It is!

This would make a nice addition to the document, thank you!

Best of luck,
--
Artyom Bologov
https://aartaka.me