Skip to content

Commit

Permalink
(GitHub Action) Remove the deprecated :result-type keyword argument. (
Browse files Browse the repository at this point in the history
#196)

This commit was copied from the master branch.

Commit: 395885b
Author: okamsn <28612288+okamsn@users.noreply.github.com>
Date: 2024-03-09 15:51:21 +0000

Remove the deprecated `:result-type` keyword argument. (#196)

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`.
- Remove the keyword from the mostly unused
  `loopy--accum-common-keywords-edebug-spec` debug specification.
  • Loading branch information
github-actions[bot] committed Mar 9, 2024
1 parent 2f4b1d2 commit 876d245
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 200 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ This document describes the user-facing changes to Loopy.
- The deprecated `:init` keyword argument has been removed ([#195], [#146]).
Use the `with` special macro argument instead.

- The deprecated `:result-type` keyword argument has been removed ([#196],
[#154]). Use the `finally-return` special macro argument instead in
combination with `cl-coerce`, `seq-into`, or a similar function.

[#195]: https://github.com/okamsn/loopy/pull/195
[#196]: https://github.com/okamsn/loopy/pull/196

## 0.12.2

Expand Down
3 changes: 3 additions & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ please let me know.
- Unreleased:
- The deprecated =:init= keyword argument has been removed. Use the =with=
special macro argument instead.
- The deprecated =:result-type= keyword argument has been removed. Use the
=finally-return= special macro argument instead in combination with
~cl-coerce~, ~seq-into~, or a similar function.
- Version 0.12.0:
- The boolean commands =always=, =never=, and =thereis= now behave more like
accumulation commands and use ~loopy-result~ by default.
Expand Down
113 changes: 30 additions & 83 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 @@ -1845,34 +1836,24 @@ Warning trigger: %s"
`(,@(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))))))))
(loopy--vars-final-updates (,var . nil))))

;; 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 +1864,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 +1882,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 +1976,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 +1990,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 +2015,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 +2026,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
3 changes: 1 addition & 2 deletions loopy.el
Original file line number Diff line number Diff line change
Expand Up @@ -778,8 +778,7 @@ In `loopy', processing instructions is stateful."
[":into" loopy--destr-var-name-edebug-spec]
[":test" form]
[":key" form]
[":init" form]
[":result-type" symbolp]])
[":init" form]])

(def-edebug-spec loopy--command-edebug-specs
[&or
Expand Down
Loading

0 comments on commit 876d245

Please sign in to comment.