about summary refs log tree commit diff
path: root/users/wpcarro/emacs/pkgs/struct
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2022-08-02T20·21-0700
committerclbot <clbot@tvl.fyi>2022-08-02T20·31+0000
commit63683b08034f1ea8dfb19add6a3d6b4b63dfb9d9 (patch)
tree559d12f582951470a476d23fd8acbe6ed66c8dc6 /users/wpcarro/emacs/pkgs/struct
parent44f520ccd176ef70f69a4e3bf9656d0198cfc5e8 (diff)
refactor(wpcarro/emacs): Remove struct.el dep on dash.el r/4371
Simplifying the dependency graph of struct.el :)

Change-Id: I23f990d9f02f76d7f8b69c65f5d5090b1c572eed
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6028
Reviewed-by: wpcarro <wpcarro@gmail.com>
Autosubmit: wpcarro <wpcarro@gmail.com>
Tested-by: BuildkiteCI
Diffstat (limited to 'users/wpcarro/emacs/pkgs/struct')
-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