gpt4 book ai didi

方案:与集合混淆!

转载 作者:行者123 更新时间:2023-12-02 06:44:09 26 4
gpt4 key购买 nike

我对这段代码的工作方式感到困惑:

(define m (list 1 2 3 '(5 8)))
(let ((l (cdr m)))
(set! l '(28 88))) ==>(1 2 3 (5 8))

(define o (list 1 2 3 '(5 8)))
(let ((l (cdr o)))
(set-car! l '(28 88))) ==> (1 (28 88) 3 (5 8))

为什么 (set!l '(28 88))) 不更新 m

最佳答案

设置!不能改变列表(或任何其他结构,不像 set-car/cdr!),但只能改变一个(在你的情况下,本地 l)变量的绑定(bind)。

(define x 3)
(define f (lambda (x) (set! x 4)))
(define g (lambda (y) (set! x y)))
(f x)
x
-> 3
(g 5)
x
-> 5

关于方案:与集合混淆!,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2985093/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com