about summary refs log tree commit diff
path: root/users
diff options
context:
space:
mode:
Diffstat (limited to 'users')
-rw-r--r--users/wpcarro/emacs/pkgs/struct/default.nix1
-rw-r--r--users/wpcarro/emacs/pkgs/struct/struct.el42
2 files changed, 17 insertions, 26 deletions
diff --git a/users/wpcarro/emacs/pkgs/struct/default.nix b/users/wpcarro/emacs/pkgs/struct/default.nix
index 3c836e74ac97..1b8b27457a66 100644
--- a/users/wpcarro/emacs/pkgs/struct/default.nix
+++ b/users/wpcarro/emacs/pkgs/struct/default.nix
@@ -9,7 +9,6 @@ let
         src = ./struct.el;
         packageRequires =
           (with emacsPackages; [
-            dash
             s
           ]);
       })
diff --git a/users/wpcarro/emacs/pkgs/struct/struct.el b/users/wpcarro/emacs/pkgs/struct/struct.el
index e5b25c3836af..177878c5e1c5 100644
--- a/users/wpcarro/emacs/pkgs/struct/struct.el
+++ b/users/wpcarro/emacs/pkgs/struct/struct.el
@@ -18,7 +18,6 @@
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 (require 's)
-(require 'dash)
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Library
@@ -27,38 +26,23 @@
 (defmacro struct-update (type field f xs)
   "Apply F to FIELD in XS, which is a struct of TYPE.
 This is immutable."
-  (let ((copier (->> type
-                     symbol-name
-                     (s-prepend "copy-")
-                     intern))
-        (accessor (->> field
-                       symbol-name
-                       (s-prepend (s-concat (symbol-name type) "-"))
-                       intern)))
+  (let ((copier (struct--copier-for type))
+        (accessor (struct--accessor-for type field)))
     `(let ((copy (,copier ,xs)))
        (setf (,accessor copy) (funcall ,f (,accessor copy)))
        copy)))
 
 (defmacro struct-update! (type field f xs)
   "Mutably apply F to FIELD in XS."
-  (let ((accessor (->> field
-                       symbol-name
-                       (s-prepend (s-concat (symbol-name type) "-"))
-                       intern)))
+  (let ((accessor (struct--accessor-for type field)))
     `(progn
        (setf (,accessor ,xs) (funcall ,f (,accessor ,xs)))
        ,xs)))
 
 (defmacro struct-set (type field x xs)
   "Immutably set FIELD in XS (struct TYPE) to X."
-  (let ((copier (->> type
-                     symbol-name
-                     (s-prepend "copy-")
-                     intern))
-        (accessor (->> field
-                       symbol-name
-                       (s-prepend (s-concat (symbol-name type) "-"))
-                       intern)))
+  (let ((copier (struct--copier-for type))
+        (accessor (struct--accessor-for type field)))
     `(let ((copy (,copier ,xs)))
        (setf (,accessor copy) ,x)
        copy)))
@@ -66,13 +50,21 @@ This is immutable."
 (defmacro struct-set! (type field x xs)
   "Set FIELD in XS (struct TYPE) to X mutably.
 This is an adapter interface to `setf'."
-  (let ((accessor (->> field
-                       symbol-name
-                       (s-prepend (s-concat (symbol-name type) "-"))
-                       intern)))
+  (let ((accessor (struct--accessor-for type field)))
     `(progn
        (setf (,accessor ,xs) ,x)
        ,xs)))
 
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Helper Functions
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+(defun struct--copier-for (type)
+  (intern (s-prepend "copy-" (symbol-name type))))
+
+(defun struct--accessor-for (type field)
+  (intern (s-prepend (s-concat (symbol-name type) "-")
+                     (symbol-name field))))
+
 (provide 'struct)
 ;;; struct.el ends here