求助:let bind url-mime-accept-string的问题

调用下面这个函数

(defun f1 ()
  (let ((url-request-method "GET")
        (url-mime-accept-string "application/json"))
    (with-temp-buffer
      (list url-request-method url-mime-accept-string)
      )
    ))

应该得到

("GET" "application/json")

但是下面这段

(with-current-buffer
    (url-retrieve-synchronously "http://example.com" t)
  (f1))

给出

("GET" nil)

为何?请道友解惑,多谢!

我先给个最小化后的例子

(save-current-buffer
  (set-buffer (url-retrieve-synchronously "http://example.com" t))
  (let ((url-request-method "GET") (url-mime-accept-string "application/json"))
    (set-buffer (generate-new-buffer " *temp*" t))
    (list url-request-method url-mime-accept-string)))

显然原因是 url-mime-accept-string 在这里被设成 local variable 并清空了

1 个赞

感谢! 所以是因为变成了local variable,所以let bind在新的temp buffer里面不起作用。