Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate reduce and accumulate? #153

Open
okamsn opened this issue Feb 2, 2023 · 2 comments
Open

Deprecate reduce and accumulate? #153

okamsn opened this issue Feb 2, 2023 · 2 comments
Labels
breaking changes deprecation/obsoletion Marking things for eventual removal simplification Making things simpler

Comments

@okamsn
Copy link
Owner

okamsn commented Feb 2, 2023

set-accum is the more general version of both. The reduce command has a sligtly different argument order compared to the function anyway.

(accumulate n #'-)
(set-accum (- n loopy-result))

(reduce n #'-)
(set-accum (- loopy-result n))
@okamsn okamsn added simplification Making things simpler deprecation/obsoletion Marking things for eventual removal breaking changes labels Feb 2, 2023
@okamsn
Copy link
Owner Author

okamsn commented Aug 12, 2023

To replace reduce, which has a different behavior depending on whether an
initial value is provided, we should add multiple values to set-accum so that
it works more like set.

Currently, we need to do something like this:

;; => 24
;; Note that this example `reduce` doesn't currently work because `loopy-result'
;; is initialized to `nil'.
(loopy (list i '(1 2 3 4))
       (reduce i #'*))

(loopy (list i '(1 2 3 4))
       (set first-time t nil)
       (set-accum (if first-time
                      i
                    (* i loopy-result))))

It would be better if we did something like this:

(loopy (list i '(1 2 3 4))
       (set-accum i (* i loopy-result)))

;; Same as above:
(loopy (list i '(1 2 3 4))
       (set loopy-result i (* i loopy-result))
       (finally-return loopy-result))

@okamsn
Copy link
Owner Author

okamsn commented Aug 13, 2023

It would be better if we did something like this:

(loopy (list i '(1 2 3 4))
       (set-accum i (* i loopy-result)))

;; Same as above:
(loopy (list i '(1 2 3 4))
       (set loopy-result i (* i loopy-result))
       (finally-return loopy-result))

However, we can't, because it's impossible to distinguish between
(cmd VAR VAL1) and (cmd VAL1 VAL2).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking changes deprecation/obsoletion Marking things for eventual removal simplification Making things simpler
Projects
None yet
Development

No branches or pull requests

1 participant