Difference between `set`, `setq`, and `setf` in Common Lisp?

前端 未结 6 2092
Happy的楠姐
Happy的楠姐 2020-11-30 16:53

What is the difference between \"set\", \"setq\", and \"setf\" in Common Lisp?

6条回答
  •  伪装坚强ぢ
    2020-11-30 17:06

    setq is just like set with a quoted first arg -- (set 'foo '(bar baz)) is just like (setq foo '(bar baz)). setf, on the other hand, is subtle indeed -- it's like an "indirection". I suggest http://www.n-a-n-o.com/lisp/cmucl-tutorials/LISP-tutorial-16.html as a better way to get started understanding it than any answer here can give... in short, though, setf takes the first argument as a "reference", so that e.g. (aref myarray 3) will work (as the first arg to setf) to set an item inside an array.

提交回复
热议问题