Skip to content

Instantly share code, notes, and snippets.

@mpontus
Created March 17, 2015 04:26
Show Gist options
  • Save mpontus/c0885127b424d2f7f1d0 to your computer and use it in GitHub Desktop.
Save mpontus/c0885127b424d2f7f1d0 to your computer and use it in GitHub Desktop.
(cl-defun test (&key bar)
(message "bar: %s" bar))
(test :bar 'qwe)
;; "bar: qwe"
(cl-defun test (&rest foo &key bar)
(message "foo: %s bar: %s" foo bar))
(test 'qwe :bar 'asd)
;; (error "Keyword argument qwe not one of (:bar)")
(cl-defun test (&rest foo &key bar &allow-other-keys)
(message "foo: %s bar: %s" foo bar))
(test 'qwe :bar 'asd)
;; "foo: (qwe :bar asd) bar: nil"
(cl-defun test (&rest foo &key bar baz)
(message "foo: %s bar: %s baz: %s" foo bar baz))
(test 'qwe :bar 'asd :baz 'zxc)
;; (error "Keyword argument qwe not one of (:bar :baz)")
(cl-defun test (&rest foo &key bar baz &allow-other-keys)
(message "foo: %s bar: %s baz: %s" foo bar baz))
(test 'qwe :bar 'asd :baz 'zxc)
;; "foo: (qwe :bar asd :baz zxc) bar: nil baz: nil"
(test 'asd :bar 'qwe :baz 'zxc)
(cl-defun test (arg &rest foo &key bar baz &allow-other-keys)
(message "arg: %s foo: %s bar: %s baz: %s" arg foo bar baz))
(test 123 'asd :bar 'qwe :baz 'zxc)
;; "arg: 123 foo: (asd :bar qwe :baz zxc) bar: nil baz: nil"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment