方案:如何测试对象是否为 lambda 表达式
Scheme: How to test if an object is a lambda expression
如何测试 scheme 中的对象是否为 lambda 表达式?看起来像这样的东西:
(define call-if-can (lambda (x)
(if (function? x)
(x)
x)))
谢谢!
尝试使用 procedure?
谓词,这是标准方案:
(define (call-if-can x)
(if (procedure? x)
(x)
x))
它按预期工作:
(define (test) (+ 1 1))
(call-if-can 1)
=> 1
(call-if-can test)
=> 2
如何测试 scheme 中的对象是否为 lambda 表达式?看起来像这样的东西:
(define call-if-can (lambda (x)
(if (function? x)
(x)
x)))
谢谢!
尝试使用 procedure?
谓词,这是标准方案:
(define (call-if-can x)
(if (procedure? x)
(x)
x))
它按预期工作:
(define (test) (+ 1 1))
(call-if-can 1)
=> 1
(call-if-can test)
=> 2