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

customize when to prefer built-ins over clauses and vice versa #63

Closed
Luis-Henriquez-Perez opened this issue Apr 12, 2021 · 3 comments
Closed
Labels
enhancement New feature or request

Comments

@Luis-Henriquez-Perez
Copy link
Contributor

It is worth noting that the "while" clause does not work in iter (assuming the lax-naming flag is enabled) because iter uses the built-in while. Might be useful to have a custom variable for specifying for which commands iter should prefer built-ins and which it should prefer clauses.

Right now there's loopy-iter-ignored-commands which stops loopy iter from prioritizing some clauses over built-ins. But you should be able to go the other way around too. So I can say if you see a while assume it is a clause and not the built-in.

@okamsn okamsn added the enhancement New feature or request label May 8, 2021
@okamsn
Copy link
Owner

okamsn commented Jun 13, 2021

My thinking was that in loopy-iter, one wouldn't want to use the commands named after the built-in Emacs Lisp forms, as they are normally just wrappers around those forms.

That is, I don't know the benefit to using the whilecommand instead of the normal while special form in loopy-iter, since the command would just expand in place to a usage of the form.

What is your use case that you would prefer the command to form? Do you have other examples of this for other commands?

@Luis-Henriquez-Perez
Copy link
Contributor Author

Sorry for the very late response.

What is your use case that you would prefer the command to form?

At the time my use case were the examples I presented in #109 (one of which I show below). To try to describe the situation: I want to have multiple separate loops in the same body that share the same "environment". Below both loops collect to the same let-bind. In this example I feel that I'm kind of "misusing" iter--or at least I'm not using it as intended because it is intended to be a loop have some sort of iteration clause or at least iterate more than once. Rather, I'm using it for it's convenient accumulation commands and inefficiently returning a value. Therefore, I think there should be a specific macro for this situation.

(defmacro with-map! (map &rest body)
  "Let-bind dotted symbols to their values in BODY.
This is similar to `let-alist' but map can be any key value structure."
  (declare (indent 1))
  (iter (dolist (dot-sym (oo-dot-symbols body))
	  (expr name (macroexp-quote (oo-dot-symbol-name dot-sym)))
	  (collect let-binds (list name dot-sym)))
	(dolist (asterix-sym (oo-asterix-symbols body))
	  (expr name (oo-keyword-intern (oo-asterix-symbol-name asterix-sym)))
	  (collect let-binds (list name asterix-sym)))
	(return `(map-let ,let-binds ,map ,@body))))

Do you have other examples of this for other commands?

I don't have examples for other commands. Maybe loopy-block is good enough solution for this.

@okamsn
Copy link
Owner

okamsn commented Aug 12, 2023

After a series of changes to loopy-iter, one should now be able to use any loopy command after one of the special words listed in loopy-iter-keywords. For example,

;; => (1 2 2 4)
(loopy-iter (listing i '(1 2 3))
            (for while (< i 3))
            (collecting i)
            (accum collect (* 2 i)))

Since the idea for loopy clauses without a built-in while loop is discussed in other issues, I'm closing this one as complete.

@okamsn okamsn closed this as completed Aug 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants