Scheme n-ary functions
I'm looking to make my own custom < function that can take any number of arguments in scheme. How would I go about doing this?
I'm thinking I have to do something like (and (b< x开发者_Python百科 y) (b< y z)) but I'm not sure.
Here's an implementation of <
that works like the one in Scheme, using b<
as the binary less-than operation:
(define (< . args)
(cond
[(null? args) #t]
[(null? (cdr args)) #t]
[(b< (car args) (car (cdr args)))
(apply < (cdr args))]))
well, to start off, you define a variadic function with something like
(define (my-< . numbers)
<body>
)
then numbers will be a list which contains the arguments. From there you'll need some sort of loop or recursion so that it works for an arbitrary number of arguments.
精彩评论