with-slots 这个宏能解释一下是用来干什么吗?

with-slots 这个宏能解释是用来干什么吗? 看文档还是有些不懂, 希望能举一些例子

在 EIEIO 对象中,访问 slot 要用 oref 或者 slot-value,当你要同时访问多个 slot 时,反复写有点麻烦,那么就可以用 with-slots

(require 'eieio)

(defclass test ()
  ((foo) (bar) (baz)))

(let ((test (make-instance 'test)))
  (with-slots (foo bar) test
    (setq foo 1)
    (setq bar 2))
  (list (oref test foo)
        (oref test bar)))
2 个赞