emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] 148/255: improved the setf method for aget


From: Eric Schulte
Subject: [elpa] 148/255: improved the setf method for aget
Date: Sun, 16 Mar 2014 01:02:37 +0000

eschulte pushed a commit to branch go
in repository elpa.

commit de4ddf2419b9fc1b26814db6cbd3ddc9b0214232
Author: Eric Schulte <address@hidden>
Date:   Sun Jun 3 09:18:47 2012 -0600

    improved the setf method for aget
    
    Now works when the item being set is initially nil.
---
 go-util.el |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/go-util.el b/go-util.el
index 1533f7d..de1b178 100644
--- a/go-util.el
+++ b/go-util.el
@@ -50,10 +50,16 @@
 
 (defun take (num list) (subseq list 0 num))
 
-(defun set-aget (list key new)
-  (if (aget list key)
-      (setf (cdr (assoc key list)) new)
-    (setf (cdr (last list)) (list (cons key new)))))
+(defmacro set-aget (place key new)
+  "Set `aget' of KEY in the list stored in PLACE to NEW."
+  (let ((sym (gensym)))
+    (if (symbolp place)
+        (if (aget (eval place) (eval key))
+            `(setf (cdr (assoc ,key ,place)) ,new)
+          `(callf setq ,place (cons (cons ,key ,new) ,place)))
+      `(let ((,sym ,place))
+         (setf (aget ,sym ,key) ,new)
+         (setf ,place ,sym)))))
 
 (defsetf aget set-aget)
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]