unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: "Linus Björnstam" <linus.internet@fastmail.se>
To: "Zelphir Kaltstahl" <zelphirkaltstahl@posteo.de>, guile-user@gnu.org
Subject: Re: Naming help for a looping facility
Date: Sat, 06 Mar 2021 20:27:12 +0100	[thread overview]
Message-ID: <df0a056e-8942-4837-8a84-a3c07432aee2@www.fastmail.com> (raw)
In-Reply-To: <bfaca51e-3db4-bf11-c7f1-f6f317d1d88d@posteo.de>


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).





      reply	other threads:[~2021-03-06 19:27 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=df0a056e-8942-4837-8a84-a3c07432aee2@www.fastmail.com \
    --to=linus.internet@fastmail.se \
    --cc=guile-user@gnu.org \
    --cc=zelphirkaltstahl@posteo.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).