From: "Linus Björnstam" <linus.internet@fastmail.se>
To: guile-user@gnu.org
Subject: Naming help for a looping facility
Date: Fri, 05 Mar 2021 21:58:28 +0100 [thread overview]
Message-ID: <4d26504a-cab5-4112-92a1-745aed06671e@www.fastmail.com> (raw)
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
next reply other threads:[~2021-03-05 20:58 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-05 20:58 Linus Björnstam [this message]
2021-03-06 16:58 ` Naming help for a looping facility Zelphir Kaltstahl
2021-03-06 19:27 ` Linus Björnstam
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=4d26504a-cab5-4112-92a1-745aed06671e@www.fastmail.com \
--to=linus.internet@fastmail.se \
--cc=guile-user@gnu.org \
/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).