lisp-tips / lisp-tips

Common Lisp tips. Share !
119 stars 2 forks source link

Duplicated keyword arguments #15

Open svetlyak40wt opened 5 years ago

svetlyak40wt commented 5 years ago

If a function call has two pairs of keyword arguments with the same keyword, the leftmost argument pair is used. This can be helpful if a list of keyword arguments is received and you want to selectively override some value in that argument list in application. There’s no need to use mutation or produce a fresh variation of the list.

For example:

(defun write-escaped (object &rest args &key &allow-other-keys)
  (apply 'write object :escape t args))

* (write "hello" :escape nil)
hello

* (write-escaped "hello" :escape nil)
"hello"

See section 3.4.1.4 for details.

(source: https://lisptips.com/post/37350128056/duplicated-keyword-arguments)