How do you return the description of a procedure in Scheme?

前端 未结 2 1357
时光取名叫无心
时光取名叫无心 2020-12-11 06:28

Suppose I have something like this:

(define pair (cons 1 (lambda (x) (* x x))

If I want to return the front object of the pair I do this:

2条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-11 07:03

    The procedure cons evaluates its arguments: 1 is self-evaluating to 1; (lambda ...) evaluates to an anonymous procedure. If you want to 'prevent' evaluation, you need to quote the argument, as such:

    > (define pair (cons 1 '(lambda (x) (* x x))
    > (cdr pair)
    (lambda (x) (* x x))
    

提交回复
热议问题