Alex Shinn <xxxxxx@gmail.com> schrieb am Mi., 4. Jan. 2017 um 10:23 Uhr:
On Wed, Jan 4, 2017 at 6:05 PM, Marc Nieper-Wißkirchen <xxxxxx@nieper-wisskirchen.de> wrote:

While for most use cases (optional parameters), the syntax and semantics is definitely not optimal (you mentioned the quadratic code size, for example), I see one use case, for which it seems to fit:

(define f
  (case-lambda
    ((x y z) (* x y z))
    (args (error "f has to be invoked with exactly three arguments"))))

How would you code this without case-lambda so that optimal code is produced when f is well-known at a call-site?

(define f (lambda (x y z) (* x y z)))

This is not exactly doing what my example does. (In your version, you have no control about the error case - whether it is signaled or not, what the error message is, etc.) If you don't like this argument, consider the following instead:

(define f
  (case-lambda
    ((x y z) (* x y z))
    (args 
      (log "f has been invoked with a wrong number of arguments" args)
      (error "f has to be invoked with exactly three arguments"))))

NB: In my Rapid Scheme front-end, I am currently using case-lambda as a core form, but it does replace lambda, so the number of core forms do not change. And handling case-lambda-nodes is no more difficult than handling lambda-nodes in an AST (you just have one more loop, over the clauses).

I don't want the extra loop - in fact, I don't want
extra code at all, I just want to pattern match the
form.

Just two more instances of "..." (or ,@ or whatever, depending on your pattern matcher).

Marc