aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlenn Morris2015-06-05 16:30:39 -0400
committerGlenn Morris2015-06-05 16:30:39 -0400
commitb0eb66823f12c85d04e36ddd0e58e20c0a0694db (patch)
treeb1ebeac702c61e9c593eeccadfffbafc51cdeff3
parent45fbcfe37da8e0caa941311626db77e94889fddb (diff)
downloademacs-b0eb66823f12c85d04e36ddd0e58e20c0a0694db.tar.gz
emacs-b0eb66823f12c85d04e36ddd0e58e20c0a0694db.zip
* lisp/emacs-lisp/map.el (map--dispatch): Move before use.
(map--delete-array): Fix typo.
-rw-r--r--lisp/emacs-lisp/map.el64
1 files changed, 32 insertions, 32 deletions
diff --git a/lisp/emacs-lisp/map.el b/lisp/emacs-lisp/map.el
index 46c795840b0..b10be44c218 100644
--- a/lisp/emacs-lisp/map.el
+++ b/lisp/emacs-lisp/map.el
@@ -63,6 +63,37 @@ can be a list, hash-table or array."
63 `(pcase-let ((,(map--make-pcase-patterns args) ,map)) 63 `(pcase-let ((,(map--make-pcase-patterns args) ,map))
64 ,@body)) 64 ,@body))
65 65
66(defmacro map--dispatch (spec &rest args)
67 "Evaluate one of the provided forms depending on the type of MAP.
68
69SPEC can be a map or a list of the form (VAR MAP [RESULT]).
70ARGS should have the form [TYPE FORM]...
71
72The following keyword types are meaningful: `:list',
73`:hash-table' and `array'.
74
75An error is thrown if MAP is neither a list, hash-table nor array.
76
77Return RESULT if non-nil or the result of evaluation of the
78form.
79
80\(fn (VAR MAP [RESULT]) &rest ARGS)"
81 (declare (debug t) (indent 1))
82 (unless (listp spec)
83 (setq spec `(,spec ,spec)))
84 (let ((map-var (car spec))
85 (result-var (make-symbol "result")))
86 `(let ((,map-var ,(cadr spec))
87 ,result-var)
88 (setq ,result-var
89 (cond ((listp ,map-var) ,(plist-get args :list))
90 ((hash-table-p ,map-var) ,(plist-get args :hash-table))
91 ((arrayp ,map-var) ,(plist-get args :array))
92 (t (error "Unsupported map: %s" ,map-var))))
93 ,@(when (cddr spec)
94 `((setq ,result-var ,@(cddr spec))))
95 ,result-var)))
96
66(defun map-elt (map key &optional default) 97(defun map-elt (map key &optional default)
67 "Perform a lookup in MAP of KEY and return its associated value. 98 "Perform a lookup in MAP of KEY and return its associated value.
68If KEY is not found, return DEFAULT which defaults to nil. 99If KEY is not found, return DEFAULT which defaults to nil.
@@ -254,37 +285,6 @@ MAP can be a list, hash-table or array."
254 (`hash-table (map--into-hash-table map)) 285 (`hash-table (map--into-hash-table map))
255 (t (error "Not a map type name: %S" type)))) 286 (t (error "Not a map type name: %S" type))))
256 287
257(defmacro map--dispatch (spec &rest args)
258 "Evaluate one of the provided forms depending on the type of MAP.
259
260SPEC can be a map or a list of the form (VAR MAP [RESULT]).
261ARGS should have the form [TYPE FORM]...
262
263The following keyword types are meaningful: `:list',
264`:hash-table' and `array'.
265
266An error is thrown if MAP is neither a list, hash-table nor array.
267
268Return RESULT if non-nil or the result of evaluation of the
269form.
270
271\(fn (VAR MAP [RESULT]) &rest ARGS)"
272 (declare (debug t) (indent 1))
273 (unless (listp spec)
274 (setq spec `(,spec ,spec)))
275 (let ((map-var (car spec))
276 (result-var (make-symbol "result")))
277 `(let ((,map-var ,(cadr spec))
278 ,result-var)
279 (setq ,result-var
280 (cond ((listp ,map-var) ,(plist-get args :list))
281 ((hash-table-p ,map-var) ,(plist-get args :hash-table))
282 ((arrayp ,map-var) ,(plist-get args :array))
283 (t (error "Unsupported map: %s" ,map-var))))
284 ,@(when (cddr spec)
285 `((setq ,result-var ,@(cddr spec))))
286 ,result-var)))
287
288(defun map--apply-alist (function map) 288(defun map--apply-alist (function map)
289 "Private function used to apply FUNCTION over MAP, MAP being an alist." 289 "Private function used to apply FUNCTION over MAP, MAP being an alist."
290 (seq-map (lambda (pair) 290 (seq-map (lambda (pair)
@@ -338,7 +338,7 @@ If KEY is not found, return DEFAULT which defaults to nil."
338 (let ((len (seq-length map))) 338 (let ((len (seq-length map)))
339 (and (>= key 0) 339 (and (>= key 0)
340 (<= key len) 340 (<= key len)
341 (aset m key nil))) 341 (aset map key nil)))
342 map) 342 map)
343 343
344(defun map--into-hash-table (map) 344(defun map--into-hash-table (map)