Skip to content

Commit

Permalink
Remove the deprecated :result-type keyword argument.
Browse files Browse the repository at this point in the history
This argument was deprecated in PR #162.
See also issue #154.

- Remove tests of `:result-type`.
- Remove the relevant code.
- Update test `acccumulation-conflicting-final-updates` to use custom commands
  instead of checking using `:result-type`.
- Make sure the accumulation category actually gets set when
  the `:category` argument is passed to `loopy--defaccumulation`.
  • Loading branch information
okamsn committed Mar 9, 2024
1 parent 14aade8 commit d309cd3
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 199 deletions.
114 changes: 30 additions & 84 deletions loopy-commands.el
Original file line number Diff line number Diff line change
Expand Up @@ -1378,9 +1378,8 @@ VARIABLE is the accumulation variable. CATEGORY is one of
`list', `reverse-list', `string', `reverse-string', `vector',
`reverse-vector', `boolean-thereis', `boolean-always-never',
`number', and `generic'. It describes how the accumulation is
being built and its return type, ignoring special circumstances
like the `:result-type' keyword argument of commands like
`collect'. COMMAND is the accumulation command.
being built and its return type. COMMAND is the accumulation
command.
- Strings are only made by `concat'.
- Vectors are only made by `vconcat'.
Expand Down Expand Up @@ -1698,7 +1697,9 @@ you can use in the instructions:
(setq explicit-category category
implicit-category category)
(setq explicit-category (plist-get category :explicit)
implicit-category (plist-get category :implicit))))
implicit-category (plist-get category :implicit)))
(unless (and explicit-category implicit-category)
(error "Explicit or implicit accumulation category is nil.")))
`(let ((args)
(opts))
;; Compare with `loopy' for the equivalent code:
Expand All @@ -1723,15 +1724,6 @@ you can use in the instructions:

(ignore args opts)

(when (plist-member opts :result-type)
(warn "Loopy: `%s': Use of `:result-type' is deprecated.
Instead, use a coercing function like `seq-into' in a special
macro argument, such as `finally-return'. See also `accum-opt' at the Info node
`(loopy)Optimizing Accumulations'.
Warning trigger: %s"
name
cmd))

(let ((arg-length (length args)))
(cond
((= arg-length ,implicit-num-args)
Expand Down Expand Up @@ -1820,8 +1812,7 @@ Warning trigger: %s"
(defun loopy--construct-accum-adjoin (plist)
"Construct optimized accumulation for `adjoin' from PLIST."
(loopy--plist-bind ( :cmd cmd :loop loop :var var :val val
:test test :key key :at pos
:result-type (result-type 'list))
:test test :key key :at pos)
plist
(map-let (('start start)
('end end))
Expand All @@ -1844,35 +1835,24 @@ Warning trigger: %s"
(loopy--check-accumulation-compatibility loop var 'list cmd)
`(,@(if (eq pos 'start)
at-start-instrs
at-end-instrs)
(loopy--vars-final-updates
(,var . ,(if (eq 'list result-type)
nil
`(setq ,var (cl-coerce ,var (quote ,result-type))))))))
at-end-instrs)))

;; Create list in reverse order.
(loopy--check-accumulation-compatibility loop var 'reverse-list cmd)
`(,@(if (eq pos 'start)
at-end-instrs
at-start-instrs)
(loopy--vars-final-updates
(,var . (setq ,var ,(if (eq 'list result-type)
`(nreverse ,var)
`(cl-coerce (nreverse ,var)
(quote ,result-type)))))))))))))
(,var . (setq ,var (nreverse ,var)))))))))))

(loopy--defaccumulation adjoin
"Parse the `adjoin' command as (adjoin VAR VAL &key test key result-type at)
RESULT-TYPE can be used to `cl-coerce' the return value."
:keywords (test key result-type at)
"Parse the `adjoin' command as (adjoin VAR VAL &key test key at)."
:keywords (test key at)
;; This is same as implicit behavior, so we only need to specify the explicit.
:explicit
(loopy--plist-bind ( :test (test (quote #'equal)) :key key :at (pos 'end)
:result-type (result-type 'list))
(loopy--plist-bind ( :test (test (quote #'equal)) :key key :at (pos 'end))
opts
(setq pos (loopy--normalize-symbol pos)
result-type (loopy--normalize-symbol result-type))
(setq pos (loopy--normalize-symbol pos))
(when (eq pos 'beginning) (setq pos 'start))
(unless (memq pos '(start beginning end))
(signal 'loopy-bad-position-command-argument (list pos cmd)))
Expand All @@ -1883,8 +1863,7 @@ RESULT-TYPE can be used to `cl-coerce' the return value."
`((loopy--main-body
(loopy--optimized-accum '( :cmd ,cmd :name ,name
:var ,var :val ,val
:test ,test :key ,key :at ,pos
:result-type ,result-type)))))
:test ,test :key ,key :at ,pos)))))

(loopy--check-accumulation-compatibility loopy--loop-name var 'list cmd)
`((loopy--accumulation-vars (,var nil))
Expand All @@ -1902,27 +1881,19 @@ RESULT-TYPE can be used to `cl-coerce' the return value."
(loopy--produce-adjoin-end-tracking var val :test test :key key))
(t
(signal 'loopy-bad-position-command-argument (list pos cmd))))
(loopy--vars-final-updates
(,var . ,(if (eq result-type 'list)
nil
`(setq ,var (cl-coerce ,var
(quote ,(loopy--get-quoted-symbol
result-type))))))))))
(loopy--vars-final-updates (,var . nil)))))
:implicit
(loopy--plist-bind ( :test (test (quote #'equal)) :key key :at (pos 'end)
:result-type (result-type 'list))
(loopy--plist-bind ( :test (test (quote #'equal)) :key key :at (pos 'end))
opts
(setq pos (loopy--normalize-symbol pos)
result-type (loopy--normalize-symbol result-type))
(setq pos (loopy--normalize-symbol pos))
(when (eq pos 'beginning) (setq pos 'start))
(unless (memq pos '(start beginning end))
(signal 'loopy-bad-position-command-argument (list pos cmd)))
(loopy--update-accum-place-count loopy--loop-name var pos)
`((loopy--main-body
(loopy--optimized-accum '( :cmd ,cmd :name ,name
:var ,var :val ,val
:test ,test :key ,key :at ,pos
:result-type ,result-type)))
:test ,test :key ,key :at ,pos)))
(loopy--implicit-return ,var))))

;;;;;;; Append
Expand Down Expand Up @@ -2004,9 +1975,7 @@ RESULT-TYPE can be used to `cl-coerce' the return value."
;;;;;;; Collect
(defun loopy--construct-accum-collect (plist)
"Construct an optimized `collect' accumulation from PLIST."
(loopy--plist-bind ( :cmd cmd :loop loop :var var :val val
:at (pos 'end)
:result-type (result-type 'list))
(loopy--plist-bind ( :cmd cmd :loop loop :var var :val val :at (pos 'end))
plist
(setq pos (loopy--get-quoted-symbol pos))
`((loopy--accumulation-vars (,var nil))
Expand All @@ -2020,35 +1989,22 @@ RESULT-TYPE can be used to `cl-coerce' the return value."
`(,@(if (eq pos 'start)
`((loopy--main-body (setq ,var (cons ,val ,var))))
(loopy--produce-collect-end-tracking var val))
(loopy--vars-final-updates
(,var . ,(if (eq result-type 'list)
nil
`(setq ,var
(cl-coerce ,var
(quote ,(loopy--get-quoted-symbol
result-type)))))))))
(loopy--vars-final-updates (,var . nil))))

;; Create list in reverse order.
(loopy--check-accumulation-compatibility loop var 'reverse-list cmd)
`(,@(if (eq pos 'end)
`((loopy--main-body (setq ,var (cons ,val ,var))))
(loopy--produce-collect-end-tracking var val))
(loopy--vars-final-updates
(,var . (setq ,var
,(if (eq result-type 'list)
`(nreverse ,var)
`(cl-coerce
(nreverse ,var)
(quote ,(loopy--get-quoted-symbol result-type)))))))))))))
(,var . (setq ,var (nreverse ,var))))))))))

(loopy--defaccumulation collect
"Parse the `collect' command as (collect VAR VAL &key result-type at)."
:keywords (result-type at)
:explicit (loopy--plist-bind ( :at (pos (quote 'end))
:result-type (result-type 'list))
"Parse the `collect' command as (collect VAR VAL &key at)."
:keywords (at)
:explicit (loopy--plist-bind ( :at (pos (quote 'end)))
opts
(setq pos (loopy--normalize-symbol pos)
result-type (loopy--normalize-symbol result-type))
(setq pos (loopy--normalize-symbol pos))
(when (eq pos 'beginning) (setq pos 'start))
(unless (memq pos '(start beginning end))
(signal 'loopy-bad-position-command-argument (list pos cmd)))
Expand All @@ -2058,8 +2014,7 @@ RESULT-TYPE can be used to `cl-coerce' the return value."
`((loopy--main-body
(loopy--optimized-accum
'( :loop ,loopy--loop-name :var ,var :val ,val
:cmd ,cmd :name ,name :at ,pos
:result-type ,result-type)))))
:cmd ,cmd :name ,name :at ,pos)))))
(loopy--check-accumulation-compatibility
loopy--loop-name var 'list cmd)
`((loopy--accumulation-vars (,var nil))
Expand All @@ -2070,28 +2025,19 @@ RESULT-TYPE can be used to `cl-coerce' the return value."
(loopy--produce-collect-end-tracking var val))
(t
(signal 'loopy-bad-position-command-argument (list pos cmd))))
(loopy--vars-final-updates
(,var . ,(if (eq result-type 'list)
nil
`(setq ,var
(cl-coerce ,var (quote
,(loopy--get-quoted-symbol
result-type))))))))))

:implicit (loopy--plist-bind ( :at (pos 'end)
:result-type (result-type 'list))
(loopy--vars-final-updates (,var . ,nil)))))

:implicit (loopy--plist-bind ( :at (pos 'end))
opts
(setq pos (loopy--normalize-symbol pos)
result-type (loopy--normalize-symbol result-type))
(setq pos (loopy--normalize-symbol pos))
(when (eq pos 'beginning) (setq pos 'start))
(unless (memq pos '(start beginning end))
(signal 'loopy-bad-position-command-argument (list pos cmd)))
(loopy--update-accum-place-count loopy--loop-name var pos)
`((loopy--main-body
(loopy--optimized-accum
'( :loop ,loopy--loop-name :var ,var :val ,val
:cmd ,cmd :name ,name :at ,pos
:result-type ,result-type)))
:cmd ,cmd :name ,name :at ,pos)))
(loopy--implicit-return ,var))))

;;;;;;; Concat
Expand Down
Loading

0 comments on commit d309cd3

Please sign in to comment.