diff options
| author | Earl Hyatt | 2025-03-12 23:01:49 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2025-03-31 14:29:48 -0400 |
| commit | e04d1dafc700813c835ae4e45af4e104c49e8875 (patch) | |
| tree | 405296248ee9da13e065213d8f88cfe317a7bc81 /test | |
| parent | a97a61b630624f5a6ec917db92e2985c56b20aa0 (diff) | |
| download | emacs-e04d1dafc700813c835ae4e45af4e104c49e8875.tar.gz emacs-e04d1dafc700813c835ae4e45af4e104c49e8875.zip | |
Add cl-with-accessors
* lisp/emacs-lisp/cl-macs.el (cl-with-accessors): New macro.
* doc/misc/cl.texi (Structures): Mention the new macro.
* test/lisp/emacs-lisp/cl-macs-tests.el (cl-lib-struct-with-accessors):
New Test.
* etc/NEWS (New macro 'cl-with-accessors'.): Mention the macro.
This macro is useful when making repeated use of a structures accessor
functions, such as reading from a slot and then writing to a slot. It
is similar to 'with-slots' from EIEIO, but uses accessor functions
instead of slot names.
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/emacs-lisp/cl-macs-tests.el | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/test/lisp/emacs-lisp/cl-macs-tests.el b/test/lisp/emacs-lisp/cl-macs-tests.el index b4b939d3d31..ed6b1c2e4d4 100644 --- a/test/lisp/emacs-lisp/cl-macs-tests.el +++ b/test/lisp/emacs-lisp/cl-macs-tests.el | |||
| @@ -541,6 +541,21 @@ collection clause." | |||
| 541 | (should (mystruct-p (cl-lib--con-1))) | 541 | (should (mystruct-p (cl-lib--con-1))) |
| 542 | (should (mystruct-p (cl-lib--con-2)))) | 542 | (should (mystruct-p (cl-lib--con-2)))) |
| 543 | 543 | ||
| 544 | (ert-deftest cl-lib-struct-with-accessors () | ||
| 545 | (let ((x (make-mystruct :abc 1 :def 2))) | ||
| 546 | (cl-with-accessors ((abc mystruct-abc) | ||
| 547 | (def mystruct-def)) | ||
| 548 | x | ||
| 549 | (should (= abc 1)) | ||
| 550 | (should-error (setf abc 99)) | ||
| 551 | (should (= def 2)) | ||
| 552 | (setf def 3) | ||
| 553 | (should (= def 3)) | ||
| 554 | (setq def 4) | ||
| 555 | (should (= def 4))) | ||
| 556 | (should (= 4 (mystruct-def x))) | ||
| 557 | (should (= 1 (mystruct-abc x))))) | ||
| 558 | |||
| 544 | (ert-deftest cl-lib-arglist-performance () | 559 | (ert-deftest cl-lib-arglist-performance () |
| 545 | ;; An `&aux' should not cause lambda's arglist to be turned into an &rest | 560 | ;; An `&aux' should not cause lambda's arglist to be turned into an &rest |
| 546 | ;; that's parsed by hand. | 561 | ;; that's parsed by hand. |