unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Announcement: goof-loop 0.1
@ 2021-05-11 12:26 Linus Björnstam
  2021-05-11 14:15 ` Dr. Arne Babenhauserheide
  0 siblings, 1 reply; 2+ messages in thread
From: Linus Björnstam @ 2021-05-11 12:26 UTC (permalink / raw)
  To: guile-user

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



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-05-11 14:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-11 12:26 Announcement: goof-loop 0.1 Linus Björnstam
2021-05-11 14:15 ` Dr. Arne Babenhauserheide

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