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

Implement -dolist #272

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Implement -dolist #272

wants to merge 1 commit into from

Conversation

Fuco1
Copy link
Collaborator

@Fuco1 Fuco1 commented Jul 26, 2018

Fixes #136

The syntax is as follows

(-dolist ((first . second) '((a . b) (c . d)))
  (message "first %s second %s" first second))

;; also works as usual `dolist'
(-dolist (var '((a . b) (c . d)))
  (message "first %s" var))

@Fuco1
Copy link
Collaborator Author

Fuco1 commented Jul 26, 2018

I like the syntax but in all honesty I think I never in my life used dolist so I'm not sure if it's worth adding this.

@Wilfred
Copy link
Contributor

Wilfred commented Jul 26, 2018

How about the name -each-let? That fits quite nicely with -when-let etc.

@Wilfred
Copy link
Contributor

Wilfred commented Jul 26, 2018

As an aside, dolist is awesome when you want nested loops.

(dolist (team world-cup)
  (dolist (player team)
    (foo player)))

Compare this with:

(--each world-cup
  (--each it
    (foo it)))

This is confusing because it means different things on line 2 vs line 3. There's also no way to refer back to the outer it (which I've named team in the first example).

I don't like that cl advises dolist, and I think dolist's optional result argument is less readable, but the basic use case is really handy.

@Fuco1
Copy link
Collaborator Author

Fuco1 commented Jul 27, 2018

Yea, so we can view dolist is like an --each with named it. Which I think -each-let represents nicely. I think I'll go with that, thanks!

@wbolster
Copy link
Contributor

--each-as anyone? (cf. -as->)

(just thinking out loud)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FR: Add variant of -each with -let binding
3 participants