Skip to content

Implement -dolist#272

Open
Fuco1 wants to merge 1 commit intomasterfrom
feature/-dolist
Open

Implement -dolist#272
Fuco1 wants to merge 1 commit intomasterfrom
feature/-dolist

Conversation

@Fuco1
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

Wilfred commented Jul 26, 2018

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

@Wilfred
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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