> On Aug 9, 2016, at 1:51 PM, Ben Greenman <[email protected]> wrote: > > Does anyone have code for statically approximating the arity (and keywords) > of a function? > > Examples of my dream function static-procedure-arity: > > > (static-procedure-arity #'(lambda (x) x)) > 1 > > (static-procedure-arity #'(lambda (x #:y y . z) x)) > (arity-at-least 1) > > (static-procedure-arity #'(define (f x y) x)) > 2
I've just added something similar to my kw-utils package here: https://github.com/AlexKnauth/kw-utils I've added four functions, and all four of them take the `args` in `(lambda args body)`, like this: > (require kw-utils/arity+keywords/syntax) > (kw-formals->arity+keywords #'(x)) (arity+keywords 1 '() '()) > (kw-formals->arity+keywords #'(x y)) (arity+keywords 2 '() '()) > (kw-formals->arity+keywords #'(x #:y y . z)) (arity+keywords (arity-at-least 1) '(#:y) '(#:y)) > (kw-formals->arity+keywords #'(x #:y [y 5] . z)) (arity+keywords (arity-at-least 1) '() '(#:y)) There's also kw-formals->arity to return just the arity part, and kw-formals->required-kws and kw-formals->allowed-kws for the keywords > (kw-formals->arity #'(x)) 1 > (kw-formals->required-kws #'(x #:y y)) '(#:y) > (kw-formals->allowed-kws #'(x #:y y)) '(#:y) > (kw-formals->required-kws #'(x #:y [y 5])) '() > (kw-formals->allowed-kws #'(x #:y [y 5])) '(#:y) Alex Knauth -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.

