开发者

What does this function mean?

开发者 https://www.devze.com 2023-02-13 15:53 出处:网络
for the following function: (define (update f x v) (λ ($x) (display $x) (newline) (if (e开发者_如何学JAVAqual? $x x)

for the following function:

(define (update f x v)
  (λ ($x)
    (display $x)
    (newline)
    (if (e开发者_如何学JAVAqual? $x x)
        v
        (f $x))))
  1. what does $ mean here?

  2. where does the $x come from?


$ has no particular meaning in Scheme -- it's just a character like any other.

As for part 2: the code

(define (update f x v)
  (λ ($x)
    (display $x)
    (newline)
    (if (equal? $x x)
        v
        (f $x))))

is equivalent to:

(define (update f x v)
  (define (DUMMY $x)
    (display $x)
    (newline)
    (if (equal? $x x)
        v
        (f $x)))
  DUMMY)    ;; Return the lambda

So $x is just a parameter to the inner function, nothing special.


From what I can tell, the $ has no syntactic meaning, it's merely part of the parameter's identifier (like a variable name). This appears to create an anonymous function with $x as its only parameter.

0

精彩评论

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