Skip to content

Commit

Permalink
Add: (-let) Bind vars to EIEIO object slots with &obj
Browse files Browse the repository at this point in the history
Fixes #250.
  • Loading branch information
alphapapa committed Nov 13, 2017
1 parent 91d8cb0 commit df0069c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
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
10 changes: 8 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,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
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
9 changes: 8 additions & 1 deletion 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 @@ -1109,7 +1110,13 @@ new list."
(-let [(list &as _ _ _ a _ _ _ b _ _ _ c) (list 1 2 3 4 5 6 7 8 9 10 11 12)] (list a b c list)) => '(4 8 12 (1 2 3 4 5 6 7 8 9 10 11 12))
(-let (((x &as a b) (list 1 2))
((y &as c d) (list 3 4)))
(list a b c d x y)) => '(1 2 3 4 (1 2) (3 4)))
(list a b c d x y)) => '(1 2 3 4 (1 2) (3 4))
(-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))
Expand Down

0 comments on commit df0069c

Please sign in to comment.