[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Announcement: goof-loop 0.1
From: |
Linus Björnstam |
Subject: |
Announcement: goof-loop 0.1 |
Date: |
Tue, 11 May 2021 14:26:16 +0200 |
User-agent: |
Cyrus-JMAP/3.5.0-alpha0-448-gae190416c7-fm-20210505.004-gae190416 |
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
- Announcement: goof-loop 0.1,
Linus Björnstam <=