开发者

Return an expression that is a mutable object in Scheme?

开发者 https://www.devze.com 2023-02-12 02:33 出处:网络
Hi I am trying to write a function that will return an expression that is mutable and can be used as a procedure.

Hi I am trying to write a function that will return an expression that is mutable and can be used as a procedure.

For example:

(fooeq 1 2) would return (eq? 1 2)

and

((fooeq 1 2)) would return #f

Is there a way to write an expression that is a symbol that can be converted into a procedure?

EDIT: I got it, thanks for the responses. 开发者_如何学C In case anyone else was wondering it's the (eval p).


I guess you want fooeq to evaluate to a function:

> (define (fooeq a b)
    (lambda () (eq? a b)))

> ((fooeq 1 2))
#f
> ((fooeq 1 1))
#t
> 

A function that takes one or more functions as input or outputs a function is known as a higher-order function.

0

精彩评论

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

关注公众号