Dynamically find out how many inputs a function has, Racket

Is there a way to find out at runtime how many inputs (arguments, parameters) a function has?

Say I want:

(define (my-function unknown-function) ... (number-of-necessary-arguments unknown-function) ...) 
+6
source share
1 answer

You can use procedure-arity .

 (procedure-arity expt) ; => 2 

Note that when using procedure-arity with variational functions or case-lambda or the like, the results are more complex:

 (procedure-arity apply) ; => (arity-at-least 2) (procedure-arity (case-lambda ((x) x) ((xyz) z) ((abcdef . g) g))) ; => `(1 3 ,(arity-at-least 6)) 
+11
source

Source: https://habr.com/ru/post/896838/


All Articles