开发者

Scheme n-ary functions

开发者 https://www.devze.com 2023-01-28 18:26 出处:网络
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 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消