From 63683b08034f1ea8dfb19add6a3d6b4b63dfb9d9 Mon Sep 17 00:00:00 2001 From: William Carroll Date: Tue, 2 Aug 2022 13:21:06 -0700 Subject: refactor(wpcarro/emacs): Remove struct.el dep on dash.el Simplifying the dependency graph of struct.el :) Change-Id: I23f990d9f02f76d7f8b69c65f5d5090b1c572eed Reviewed-on: https://cl.tvl.fyi/c/depot/+/6028 Reviewed-by: wpcarro Autosubmit: wpcarro Tested-by: BuildkiteCI --- users/wpcarro/emacs/pkgs/struct/default.nix | 1 - users/wpcarro/emacs/pkgs/struct/struct.el | 42 ++++++++++++----------------- 2 files changed, 17 insertions(+), 26 deletions(-) (limited to 'users/wpcarro/emacs') 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 -- cgit 1.4.1