Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: (-let) Bind vars to EIEIO object slots with &obj #251

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -2321,6 +2321,10 @@ Key/value stores:
`source` hash table to aK. If the
value is not found, aK is nil.

(&obj key0 a0 ... keyN aN) - bind value mapped by keyK in the
`source` `eieio` object to aK. If the
value is not found, aK is nil.

Further, special keyword &keys supports "inline" matching of
plist-like key-value pairs, similarly to &keys keyword of
`cl-defun`.
Expand Down
11 changes: 9 additions & 2 deletions dash.el
Expand Up @@ -1738,7 +1738,9 @@ Valid values are &plist, &alist and &hash."
((eq type '&alist)
`(cdr (assoc ,k ,source)))
((eq type '&hash)
`(gethash ,k ,source)))))
`(gethash ,k ,source))
((eq type '&obj)
`(oref ,source ,k)))))
(cond
((symbolp v)
(list (list v getter)))
Expand Down Expand Up @@ -1771,7 +1773,7 @@ Key-value stores are disambiguated by placing a token &plist,
(let ((s (car match-form)))
(cons (list s source)
(dash--match (cddr match-form) s))))
((memq (car match-form) '(&keys &plist &alist &hash))
((memq (car match-form) '(&keys &plist &alist &hash &obj))
(dash--match-kv match-form source))
(t (dash--match-cons match-form source))))
((vectorp match-form)
Expand Down Expand Up @@ -1883,6 +1885,11 @@ Key/value stores:
SOURCE hash table to aK. If the
value is not found, aK is nil.

(&obj key0 a0 ... keyN aN) - bind value mapped by keyK in the
SOURCE EIEIO object to aK. If the
value is not found, aK is nil.
Only works on Emacs 24 and later.

Further, special keyword &keys supports \"inline\" matching of
plist-like key-value pairs, similarly to &keys keyword of
`cl-defun'.
Expand Down
3 changes: 3 additions & 0 deletions dash.info
Expand Up @@ -2135,6 +2135,9 @@ control.
(&hash key0 a0 ... keyN aN) - bind value mapped by keyK in the
SOURCE hash table to aK. If the value is not found, aK is nil.

(&obj key0 a0 ... keyN aN) - bind value mapped by keyK in the
SOURCE EIEIO object to aK. If the value is not found, aK is nil.

Further, special keyword &keys supports "inline" matching of
plist-like key-value pairs, similarly to &keys keyword of
‘cl-defun’.
Expand Down
4 changes: 4 additions & 0 deletions dash.texi
Expand Up @@ -3553,6 +3553,10 @@ Key/value stores:
@var{source} hash table to aK. If the
value is not found, aK is nil.

(&obj key0 a0 ... keyN aN) - bind value mapped by keyK in the
@var{source} @var{eieio} object to aK. If the
value is not found, aK is nil.

Further, special keyword &keys supports "inline" matching of
plist-like key-value pairs, similarly to &keys keyword of
@code{cl-defun}.
Expand Down
11 changes: 11 additions & 0 deletions dev/examples.el
Expand Up @@ -23,6 +23,7 @@
;;; Code:

(require 'dash)
(require 'eieio)

(defun even? (num) (= 0 (% num 2)))
(defun square (num) (* num num))
Expand Down Expand Up @@ -1111,6 +1112,16 @@ new list."
((y &as c d) (list 3 4)))
(list a b c d x y)) => '(1 2 3 4 (1 2) (3 4)))

(unless (version< emacs-version "24")
;; This fails on Emacs 23 with "Lisp nesting exceeds `max-lisp-eval-depth'".
(defexamples -let-eieio
(-let (((&obj :slot1 one :slot2 two) (progn
(defclass -let-test-class ()
((slot1 :initarg :slot1)
(slot2 :initarg :slot2)))
(make-instance '-let-test-class :slot1 1 :slot2 2))))
(list one two)) => '(1 2)))

(defexamples -let*
(-let* (((a . b) (cons 1 2))
((c . d) (cons 3 4)))
Expand Down