I rather think that the point of the arity query procedure
is for some kind of crude optimization, rather than strict
error checking, given the nature of the ambiguity Thomas mentioned.
For example, higher order procedure can branch out the typical
cases to avoid folding arguments (it can be abstracted to a macro).
(define (complement fn)
(case (arity fn) ;; some optimization
((0) (lambda () (not (fn))))
((1) (lambda (x) (not (fn x))))
((2) (lambda (x y) (not (fn x y))))
(else (lambda args (not (apply fn args))))))
If an implementation doesn't care about such kludge, it can
just have procedure-arity return "arbitrary number of arguments"
to all the procedures. Third-party library written in the above
way can still work without any disadvantages.
--shiro
>From: Thomas Bushnell BSG <xxxxxx@becket.net>
Subject: arity failures
Date: Fri, 13 Nov 2009 10:54:40 -0800
> So "passing" an arity check doesn't mean that the number of arguments
> you pass is correct, as Dybvig's already noted.
>
> Also, "failing" an arity check doesn't mean that you will get any kind
> of error or exception as a result.
>
> For example, in response to the question, "what is the arity of read", I
> said that under my proposal,
> (procedure-arity read) => 0, #t
> and then I gave code which throws an error if more than one argument is
> passed. But no error is required by Scheme, both because an
> implementation is free to assign a meaning to (read a b c), and further,
> because an implementation is free to assign a meaning in general to
> "extra arguments" passed to procedures.
>
> I can understand then "arity" to mean something which matches the syntax
> specification for lambda formals lists, in which there is a minimum and
> permission for more arguments.
>
> People seem to want some *other* meaning than that. Something like "the
> number of arguments that can be passed without signaling an error",
> though that's not a very clear concept without specifying which errors
> are involved. Moreover, for the reasons Dybvig has indicated
> previously, this is not something most systems could successfully
> implement, what with passing argument lists around via apply and such.
>
> So, to recap:
>
> Being told that a procedure takes, say, exactly three arguments, does
> not mean that
> 1) You won't get an error for passing three arguments;
> 2) You will get an error for passing other than three arguments.
>
> However, I believe it could mean that:
> * The procedure was created with a proper lambda formals list
> containing exactly three identifiers.
>
> Thomas
>
>
>
>
>
>