Detecting arity errors
Lassi Kortela
(15 Apr 2020 07:48 UTC)
|
Re: Detecting arity errors
Marc Nieper-Wißkirchen
(15 Apr 2020 08:49 UTC)
|
Re: Detecting arity errors Lassi Kortela (15 Apr 2020 09:19 UTC)
|
Re: Detecting arity errors
Marc Nieper-Wißkirchen
(15 Apr 2020 09:43 UTC)
|
Re: Detecting arity errors
Lassi Kortela
(15 Apr 2020 09:51 UTC)
|
Re: Detecting arity errors
Marc Nieper-Wißkirchen
(15 Apr 2020 10:34 UTC)
|
Re: Detecting arity errors
Lassi Kortela
(15 Apr 2020 10:54 UTC)
|
Re: Detecting arity errors
Lassi Kortela
(15 Apr 2020 10:57 UTC)
|
Re: Detecting arity errors
Marc Nieper-Wißkirchen
(15 Apr 2020 11:17 UTC)
|
Re: Detecting arity errors
Lassi Kortela
(15 Apr 2020 16:39 UTC)
|
> For unit testing, a portable `arity-error?` predicate would be really > useful. You could give it an exception object and it would return #t if > the exception was caused by passing the wrong number of arguments. > > A Scheme system does not have to signal an arity error. If a Scheme system has no arity exceptions, it can simply define: (define (arity-error? obj) #f) I read the following sections of R7RS: 4.1.3. Procedure calls 4.1.4. Procedures and indeed the report doesn't even say "it is an error" to call a procedure with the wrong number of arguments. It only says: "When the procedure is later called with some actual arguments, the environment in which the lambda expression was evaluated will be extended by binding the variables in the formal argument list to fresh locations, and the corresponding actual argument values will be stored in those locations." > Besides, can you give an example of how it would help in unit testing It would help check that procedures require the needed number of arguments and reject extra ones. Rejecting extra arguments may not be required by RnRS and SRFIs, but in practice it is quite confusing if a standard procedure or syntax silently succeeds with spurious arguments. More than one Scheme has silently accepted (if a b c spurious) for example. As a concrete example, Gambit comes with about a thousand tests using its own `wrong-number-of-arguments-exception?`.