Using AND with the apply function in Scheme

前端 未结 9 908
被撕碎了的回忆
被撕碎了的回忆 2020-12-03 05:26

Why doesn\'t the following work?

(apply and (list #t #t #f))

While the following works just fine.

(apply + (list 1 3 2))
         


        
9条回答
  •  有刺的猬
    2020-12-03 06:11

    If you REALLY wanted to have a function pointer to a function that does and, and you don't mind behavior different than the "real" and, then this would work:

    (define and-l (lambda (a b) (and a b)))
    

    Which you can apply like this:

    (apply and-l (list #t #f))
    

    The two caveats are:

    1. All of the args get evaluated, in violation of the definition of and, which should have shortcutting behavior.
    2. Only two arguments are allowed.

提交回复
热议问题