* Naming help for a looping facility @ 2021-03-05 20:58 Linus Björnstam 2021-03-06 16:58 ` Zelphir Kaltstahl 0 siblings, 1 reply; 3+ messages in thread From: Linus Björnstam @ 2021-03-05 20:58 UTC (permalink / raw) To: guile-user Hello fellow guilers! I have been writing the bastard child of foof-loop/chibi loop (https://mumble.net/~campbell/darcs/hack-foof-loop/foof-loop.txt) and racket's for loops. The current pre-beta can be found here: https://git.sr.ht/~bjoli/goof-loop/ I want to, just like the racket loops, provide simple forms, so that I instead of (loop ((:for a (up-from 0 10)) (:acc acc (listing (* a a)))) => acc) can write (NAME ((:for a (up-from 0 10))) (* a a)). My struggle is what I should name this. In racket it is for/list. I could of course call it loop/list, but that is inconsistent with the naming inherited from (chibi loop): listing. loop/listing becomes verbose (it's scheme after all) and is very clear what it does. But, as I already have a listing macro to be used within the loop facility, wouldn't (listing ((:for a (up-from 0 10)) ...) be a good name? Is it too magical? I happen to think that it is elegant, but I don't know. It doesn't feel like the scheme way. I am pretty sure I want a special form for these things, as it allows for some optimization work. listing, as we all understand, has to reverse it's arguments, whereas a special form easily can rewrite itself to be a non-tail-recursive loop (which is faster than a reverse, yet without all the nasty sides of reverse!) The options as of right now: (loop/list ...) Upsides: - pretty short - loop/list works differently from listing, even tthough the end result is the same. This signals that to some extent. - If I am stealing from racket anyway... Downsides: - not as clear as (loop/listing ...). To be honest, this is a pretty big one. If I _could_ I would make (loop (... ( ...(listing ...))) ...) work like the simple form, but that is not possible if we have other accumulating clauses. (loop/listing ...) Upsides: - The most clear Downsides: - Verbose, which is what we want to avoid. (listing ...) Upsides: - We export fewer identifiers - Is already used as an accumulating clause - shortest Downsides: - Too much magic? - One exported form does two related, but different things in different contexts? - (anding ...) makes sense, whereas (loop (... (:acc a (anding ...))) ...) does almost not at all. I somewhat prefer the last one, but it feels icky. So, scheme sages of guile-user, what do you say? Liebe Grüße Linus Björnstam ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Naming help for a looping facility 2021-03-05 20:58 Naming help for a looping facility Linus Björnstam @ 2021-03-06 16:58 ` Zelphir Kaltstahl 2021-03-06 19:27 ` Linus Björnstam 0 siblings, 1 reply; 3+ messages in thread From: Zelphir Kaltstahl @ 2021-03-06 16:58 UTC (permalink / raw) To: guile-user Hello Linus! Not sure my idea for naming is any good: Perhaps you could use the word "iteration" or "iter" in combination with something else. I have a bit of difficulty understanding how these forms work. The readme could perhaps be better, if you showed the output as well as describing it, which you already do and show multiple examples per form, varying the arguments. For example: ~~~~ (define lst '((1 2) dud (3 4) (5 6))) (loop ((:for a (in-list lst)) (:when (pair? a)) (:for b (in-list a)) (:acc acc (summing b))) => acc) ~~~~ What happens, if one leaves the :when away? Is it strictly necessary, when we already use in-list, telling the machine, that we are processing a list? What changes, when we put :subloop in there? I am guessing, that it is the difference between nested looping and not nested. In the example with :subloop, you have shown the output. If comparing to Racket's for-loop variants, I could imagine, that it could improve understanding, if you put the Racket expression there and then show how to do the same with the forms you are showing. Would your implementation be portable between various Schemes? That would be great! One problem I had when migrating my decision tree implementation from Racket to GNU Guile was, that I had been using Racket's special for-loop forms and that I had to translate those back into named let or others, to get it running on GNU Guile. If one could simply load your library in any Scheme that fulfills some known and specified set of conditions, one would not need to worry about portability of the code as much. Best wishes, Zelphir On 3/5/21 9:58 PM, Linus Björnstam wrote: > Hello fellow guilers! > > I have been writing the bastard child of foof-loop/chibi loop (https://mumble.net/~campbell/darcs/hack-foof-loop/foof-loop.txt) and racket's for loops. The current pre-beta can be found here: https://git.sr.ht/~bjoli/goof-loop/ > > I want to, just like the racket loops, provide simple forms, so that I instead of > > (loop ((:for a (up-from 0 10)) (:acc acc (listing (* a a)))) => acc) > > can write > > (NAME ((:for a (up-from 0 10))) (* a a)). > > My struggle is what I should name this. In racket it is for/list. I could of course call it loop/list, but that is inconsistent with the naming inherited from (chibi loop): listing. loop/listing becomes verbose (it's scheme after all) and is very clear what it does. But, as I already have a listing macro to be used within the loop facility, wouldn't (listing ((:for a (up-from 0 10)) ...) be a good name? Is it too magical? > > I happen to think that it is elegant, but I don't know. It doesn't feel like the scheme way. I am pretty sure I want a special form for these things, as it allows for some optimization work. listing, as we all understand, has to reverse it's arguments, whereas a special form easily can rewrite itself to be a non-tail-recursive loop (which is faster than a reverse, yet without all the nasty sides of reverse!) > > The options as of right now: > > (loop/list ...) > Upsides: > - pretty short > - loop/list works differently from listing, even tthough the end result is the same. This signals that to some extent. > - If I am stealing from racket anyway... > Downsides: > - not as clear as (loop/listing ...). To be honest, this is a pretty big one. If I _could_ I would make (loop (... ( ...(listing ...))) ...) work like the simple form, but that is not possible if we have other accumulating clauses. > > (loop/listing ...) > Upsides: > - The most clear > Downsides: > - Verbose, which is what we want to avoid. > > (listing ...) > Upsides: > - We export fewer identifiers > - Is already used as an accumulating clause > - shortest > Downsides: > - Too much magic? > - One exported form does two related, but different things in different contexts? > - (anding ...) makes sense, whereas (loop (... (:acc a (anding ...))) ...) does almost not at all. > > I somewhat prefer the last one, but it feels icky. So, scheme sages of guile-user, what do you say? > > Liebe Grüße > Linus Björnstam > -- repositories: https://notabug.org/ZelphirKaltstahl ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Naming help for a looping facility 2021-03-06 16:58 ` Zelphir Kaltstahl @ 2021-03-06 19:27 ` Linus Björnstam 0 siblings, 0 replies; 3+ messages in thread From: Linus Björnstam @ 2021-03-06 19:27 UTC (permalink / raw) To: Zelphir Kaltstahl, guile-user On Sat, 6 Mar 2021, at 17:58, Zelphir Kaltstahl wrote: > Hello Linus! > > Not sure my idea for naming is any good: Perhaps you could use the word > "iteration" or "iter" in combination with something else. I don't think I will change the loop name. What I am interested in is the feedback for what to call the simpler forms. Should it be loop/list, loop/listing or simply (listing ...). I think the two latter are preferrable. > > I have a bit of difficulty understanding how these forms work. The > readme could > perhaps be better, if you showed the output as well as describing it, > which you > already do and show multiple examples per form, varying the arguments. > For example: > > ~~~~ > (define lst '((1 2) dud (3 4) (5 6))) > (loop ((:for a (in-list lst)) > (:when (pair? a)) > (:for b (in-list a)) > (:acc acc (summing b))) > => acc) > ~~~~ > > What happens, if one leaves the :when away? Is it strictly necessary, when we > already use in-list, telling the machine, that we are processing a list? What > changes, when we put :subloop in there? I am guessing, that it is the difference > between nested looping and not nested. > > In the example with :subloop, you have shown the output. > > If comparing to Racket's for-loop variants, I could imagine, that it could > improve understanding, if you put the Racket expression there and then show how > to do the same with the forms you are showing. The documentation (in documentation/doc.html) is probably what you want to look at. That one explains it. When that one is finished, I will revamp the readme to point to a hosted version of it. But alas, you are correct: the readme is awful. I need to rewrite it. Regarding your comment about :when: every non-binding clause (:when, :break, :unless, :final, and :subloop) breaks out a new subloop. I do write about the results in the text following the code blocks - which I should also change. > > Would your implementation be portable between various Schemes? That would be > great! One problem I had when migrating my decision tree implementation from > Racket to GNU Guile was, that I had been using Racket's special for-loop forms > and that I had to translate those back into named let or others, to get it > running on GNU Guile. If one could simply load your library in any Scheme that > fulfills some known and specified set of conditions, one would not need to worry > about portability of the code as much. This is indeed portable. The meat of the loop is written in syntax-rules with one 10-line syntax-case macro (and some auxiliary procedures). If you want racket's for loops I do have an implementation of them for guile somewhere online, however this macro can do more things and will be strictly more powerful than racket's for loops when it is completely done. It is already more powerful, except for some fancy things they can do with their sequence api. Anyway, if you want to port it to another scheme, you will have to rewrite about 70 lines in goof.scm. The files goof-impl.scm and goof/*.scm are all portable. What you DO need is a pattern matching macro (I use alex's match.scm). ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-03-06 19:27 UTC | newest] Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2021-03-05 20:58 Naming help for a looping facility Linus Björnstam 2021-03-06 16:58 ` Zelphir Kaltstahl 2021-03-06 19:27 ` Linus Björnstam
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).