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

idea: making arguments more consistent #65

Closed
Luis-Henriquez-Perez opened this issue Apr 13, 2021 · 3 comments
Closed

idea: making arguments more consistent #65

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

Comments

@Luis-Henriquez-Perez
Copy link
Contributor

Luis-Henriquez-Perez commented Apr 13, 2021

Now that we seem to be introducing keywords as a way to specify additional arguments for clauses, it may be worth doing the same for things like list which can optionally take FUNC.

This would increase consistency.

Furthermore doing so would allow easy incorporation of #27. The signature for list could be (list elt list &rest lists &key func). If where if multiple lists are specified, it would perform a nested loop. So if (list var '(1 2 3) '(3 4 5)), then var would get the value (1 3) for the first iteration, (1 4) for the second and so on.

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

okamsn commented May 11, 2021

If we went the route of passing multiple lists to list, then I think it would be good to also allow multiple sequences for the array and seq commands, too. However, that raises questions about the order of the nesting in something like the example below.

(loopy (list i '(1 2 3 4) '(5 6 7 8))
       (array j [9 10 11 12] [13 14 15 16]))

I think that it could be interpreted like either of the following.

(seq-doseq (a '(1 2 3 4))
  (seq-doseq (b '(5 6 7 8))
    (seq-doseq (c [9 10 11 12])
      (seq-doseq (d [13 14 15 16])
        loopy--main-body))))

(seq-doseq (a '(1 2 3 4))
  (seq-doseq (b [9 10 11 12])
    (seq-doseq (c '(5 6 7 8))
      (seq-doseq (d [13 14 15 16])
        loopy--main-body))))

For that reason, I think it is better to have nested loops come from a special macro argument, instead. For example, there could be a generic nest which operates on all sequences, and more specific forms like nest-list or nest-array for efficiency.

In this case, using a special macro argument would remove any ambiguity caused by multiple loop commands, as there would only be one occurrence allowed.

Another interpretation is to "distribute" the elements of the list, in effect iterating through '((1 4) (2 4) (3 4) (1 5) (2 5) (3 5) (1 6) (2 6) (3 6)) while still only having 1 actual loop. This approach also avoids ambiguity caused by multiple loop commands.

A third possibility is to treat multiple arguments as iterated through in parallel, similar to Python's zip function. In you example, this would bind var to (1 3), (2 4), etc. However, I don't know if there's much to be gained over using two loop commands in this case, or just adding a separate zip loop command.

@Luis-Henriquez-Perez
Copy link
Contributor Author

Based on what you mentioned I like the "distribute" option best. I am biased though, because I think that the distinction in syntax between single nesting and multiple nesting caused by using a separate macro argument is more of a distraction. I like the idea of abstracting "looping" in general by which I mean, transitioning between a single-nested and multi-nested loop in a fluid way (without extra keywords). I can see perhaps a flag for this option for those who prefer using an extra macro argument.

This was referenced May 29, 2021
@okamsn
Copy link
Owner

okamsn commented Jun 9, 2021

Based on what you mentioned I like the "distribute" option best. I am biased though, because I think that the distinction in syntax between single nesting and multiple nesting caused by using a separate macro argument is more of a distraction. I like the idea of abstracting "looping" in general by which I mean, transitioning between a single-nested and multi-nested loop in a fluid way (without extra keywords).

There's only a practical difference if using multiple sequences in multiple iteration commands. For only iterating via 1 iteration commands, the behavior is the same except that the distribution is done before the loop begins.

I can see perhaps a flag for this option for those who prefer using an extra macro argument.

Since multiple sequences was also added to the seq iteration command, I no longer think that a new special macro argument is needed, which is nice.

The behavior of

((seq-doseq (a '(1 2 3 4))
  (seq-doseq (b '(5 6 7 8))
    (seq-doseq (c [9 10 11 12])
      (seq-doseq (d [13 14 15 16])
        loopy--main-body))))

can just be achieved using

(loopy (seq (a b c d) 
            '(1 2 3 4) '(5 6 7 8) 
            [9 10 11 12] [13 14 15 16])
       stuff)

It took a while, but #73 has been merged. Please try these new features out at your convenience.

@okamsn okamsn closed this as completed Jun 9, 2021
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