Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有办法在运行时找出一个函数有多少输入(参数、参数)?
说,我想:
(define (my-function unknown-function) ... (number-of-necessary-arguments unknown-function) ...)
您可以使用procedure-arity.
procedure-arity
(procedure-arity expt) ; => 2
请注意,当procedure-arity与可变参数函数case-lambda等一起使用时,结果会更复杂:
case-lambda
(procedure-arity apply) ; => (arity-at-least 2) (procedure-arity (case-lambda ((x) x) ((x y z) z) ((a b c d e f . g) g))) ; => `(1 3 ,(arity-at-least 6))