Eduardo Cavazos wrote:

Let's simulate 'procedure-arity' functionality for a few procedures:

(define (procedure-arity f)
  (cdr (assq f (list (cons vector-ref  2)
                     (cons vector-set! 3)
                     (cons eq?         2)))))

This is a simulation of what systems like Larceny offer. I.e. you call 'procedure-arity' on a procedure object.

I think there are other, but perhaps more "far out" approaches to this.

For example, consider a version of 'procedure-arity' which actually take the *name* of a procedure as a symbol:

(define (procedure-arity f)
  (cdr (assq f '((vector-ref  . 2)
                 (vector-set! . 3)
                 (eq?         . 2)))))

A macro (like smart-curry) would have no trouble at all with this. But of course, now you might not be getting the right information since there may be many procedures named 'vector-ref' from various libraries.

How would a table like 'procedure-arity' get populated? A define-like macro could annotate the table.

I know very little about the implementation of syntax, macros, etc. But occasionally I see discussion regarding "syntactic information" being attached to symbols. So I wonder if another route is as follows; when defining a procedure, attach information to that symbol which indicates that is *is* a procedure with certain properties; arity, how many values it produces, the body as an sexp, etc. This is information that *can* be used by macros.

Ed

Reply via email to