如何测试scheme中的对象是否为lambda表达式?看起来像这样:
(define call-if-can (lambda (x)
(if (function? x)
(x)
x)))
谢谢!
答案 0 :(得分:3)
尝试使用procedure?
谓词,这是标准的Scheme:
(define (call-if-can x)
(if (procedure? x)
(x)
x))
按预期工作:
(define (test) (+ 1 1))
(call-if-can 1)
=> 1
(call-if-can test)
=> 2