unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: "Linus Björnstam" <linus.internet@fastmail.se>
To: guile-user@gnu.org
Subject: Announcement: goof-loop 0.1
Date: Tue, 11 May 2021 14:26:16 +0200	[thread overview]
Message-ID: <8235e1cd-3fe1-4345-83db-a7c123801895@www.fastmail.com> (raw)

Hello Friends!

I am rather pleased to announce the first beta release of goof-loop, an extensible, powerful and fast looping facility for (guile) scheme. It is based on (chibi loop), but adds quite a bit of nice things - most notably subloops and a higher order loop protocol based on srfi-158-styled generators. 

The repo can be found here: https://git.sr.ht/~bjoli/goof-loop
Hosted documentation: https://bjoli.srht.site/doc.html

If you are familiar with racket's for loops, you will find these pretty similar, more verbose, and more powerful. Some examples to show highlights compared to racket's loops and foof-loop:

Subloops and accumulators in all loop stages:
(loop ((:for a (in-list '(1 2 3)))
       (:acc aa (summing a))
       :subloop
       (:for b (up-from a (to (+ a 2))))
       (:acc ab (listing b)))
  => (values aa ab))
;; => 6  (1 2 2 3 3 4)

Loop clauses that refer to eachother, here producing a list of fibonacci numbers:
(loop/list ((count (up-from 0 100))
            (a (in 1 b)) 
            (b (in 1 (+ a b))))
  a)

Named updates (shamelessly stolen from Taylor Campbells foof-loop documentation):
(define (partition list predicate)
  (loop continue ((:for element (in-list list))
                  (:acc satisfied (folding '()))
                  (:acc unsatisfied (folding '())))
     => (values (reverse satisfied) (reverse unsatisfied))
     (if (predicate element)
         (continue (=> satisfied (cons element satisfied)))
         (continue (=> unsatisfied (cons element unsatisfied))))))

Pattern matching, here extracting all keys in an alist
(loop/list (((key . val) (in-list '((a . 0) (b . 1) (c .2)))))
  key)

Higher order loop protocol (for the :for clause scheme-value)
(loop/list ((key (in-list '(true false sant falskt wahr falsch vrai faux)))
            (scheme-value (in-cycle (in-list '(#t #f)))))
  (cons key scheme-value))

The loop expansion is usually as fast as a named let.

You can find a lot more tofu in the readme and documentation.

best regards
  Linus Björnstam



             reply	other threads:[~2021-05-11 12:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-11 12:26 Linus Björnstam [this message]
2021-05-11 14:15 ` Announcement: goof-loop 0.1 Dr. Arne Babenhauserheide

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=8235e1cd-3fe1-4345-83db-a7c123801895@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).