Commit graph

45 commits

Author SHA1 Message Date
Linus
a38170a25b Added stop-after and stop-before
These are equivalent to their racket for loop counterparts, and creates
an iterator that signals exhaustion befor or after yielding a value
where a predicate returns true. Not useful in non-nested loops, but
could be useful in inner loops where you want to exit to an outerloop
instead of :break-ing.

Also fixed some bugs in other generator clauses.
2021-05-11 09:48:21 +02:00
Linus
3908019bbc Added some tests.
Fixed some things I noticed when testing the tests.
2021-03-22 19:30:09 +01:00
Linus
524933d29f Same as previous commit.
I forgot to edit the documentation for down-to.
2021-03-18 12:46:07 +01:00
Linus
78aed79463 Updated documentation to reflect previous change. 2021-03-18 12:43:56 +01:00
Linus
5847bd21d4 Fixed :final and make to, by => :to :by
I had a bug. I had an inconsistency. Don't worry. All is fixed.
2021-03-18 12:41:39 +01:00
Linus
f6d7b01793 Refactored for-clauses to take :for for better error reporting
At least in the future
2021-03-16 19:30:08 +01:00
Linus
172d0aa180 Changed the loop protocol for :acc clauses
The third clause (the "check" clause) now breaks the entire
iteration for :acc clauses instead of just exiting the current subloop.

This is much saner, and was immediately usable in vectoring.
2021-03-11 22:18:29 +01:00
Linus
90c2c6bfdf New documentation
Added a "Porting" section.

Some clarifications.
2021-03-11 14:42:52 +01:00
Linus
f0900a0497 Added some generator clauses to the iterators
in-vector, in-string and all other indexed for clauses
now have generator clauses.

in-hash now has a generator clause.
2021-03-11 14:38:26 +01:00
Linus
79b7c4eedd Clarified expansion
The expansion of (loop ...) without subloops is now the same as loop
with subloops.
2021-03-11 14:35:07 +01:00
Linus
f90d83b6a0 Mention documentation in the readme
The readme is awful, but now it at least points to the documentation.
2021-03-07 22:26:15 +01:00
Linus
74514bb4d1 Fixed the documentation a bit
Added some more info. It still looks awful.
2021-03-07 22:19:13 +01:00
Linus
bb0de3e949 Added some generator clauses
Now in-file, in-port, in-lists and in-generator have generator clauses
2021-02-18 22:08:34 +01:00
Linus
7b3814c430 More parentheses
I have changed my mind about the clause forms. They should, with the
exception of :subloop, be parethesised: :when test => (:when test).
2021-02-18 21:19:12 +01:00
Linus
a545c1cbd7 Fix a bug where simple loops did not bind let bindings correctly
add check whether a loop clause exists to avoid the ultra-shit errors that happen if you
accidentally write (up-form ...)
2021-02-09 22:02:40 +01:00
Linus
d48ed19e43 Fix the previous commit. Now also the simple loops are ensured to execute once if no for-clauses are given.
Instead of throwing a syntax-error...
2021-01-28 20:37:05 +01:00
Linus
685fe86f36 Loops without any clauses now run the body at least once.
Small updates to readme.
2021-01-28 20:18:15 +01:00
Linus
06a11fc892 Modularized the code
Everything in goof-impl.scm is portable (r7rs) syntax-rules. The non-portable parts
, most notably the let-kw-form macro is in the module definition goof.scm.
2021-01-28 20:01:24 +01:00
Linus
969b9a029a Added basic documentation
WIP.
2021-01-28 13:30:32 +01:00
Linus
93aa5aa439 Simplified the iterator protocol.
There is no need for :acc clauses to intoduce loop variables, or for :for clauses to introduce acc clauses.
They are now changed.

 * goof.scm (cl-next/acc cl-next/for): removed the unused matchings for loop-vars and acc-vars respectively.
 * goof/iterators.scm (all iterators): simplified it.
2021-01-06 21:24:15 +01:00
Linus
7311da2ec2 Add the vectoring accumulator.
Currently undocumented and untested.
2021-01-02 21:43:10 +01:00
Linus
f492a5278b Added hashing, hashqing hashving och in-hash. 2021-01-02 12:03:03 +01:00
Linus
5f96ef4fb0 Promote accumulator lets to the outermost let
This is a bug I never hit, due to me only having accumulators that gets passed along. However,
something like vectoring or hashing should behave like (in-vector ...), which means the let binding
needs to be propagated upwards.
* goof.scm change cl-next/acc to promote let bindings for accumulators to the outermost let.
2021-01-01 22:00:39 +01:00
Linus
02fd0199ec Added a docfile without any tools to generate the proper docs.
I can't seem to find my old xslt files.
2020-12-29 22:01:44 +01:00
Linus
bd2a69a16c Readme change. Beta quality! 2020-12-16 20:19:43 +01:00
Linus
7ddb707bb7 Made it a module.
Put it in any directory, run guile -L . and then import (goof) in that directory.
2020-12-16 20:17:13 +01:00
Linus
317b3e732b Fix markdown in README.md to not show like HTML. 2020-12-16 19:59:03 +01:00
Linus
2d35c9d6cf Polishing the README and iterator protocol.
* README.md: added some small documentation and loop expansion.
 * goof.scm: Changed the iterator protocol to not use unnecessary :acc and :fors.
 * iterators.scm: see above.
 * ref-let.scm: a new macro to allow multiple values and pattern matching to co-exist for body-bindings.
2020-12-16 19:54:55 +01:00
Linus
aab9fcabb0 Extracted the innermost recuring form into a separate form to facilitate inlining
Guile wasn't properly doing DCE when there are no :final guards, so I did it as a macro.
2020-12-02 21:39:47 +01:00
Linus
2dc4a72790 Added pattern matching
ref variables now do pattern matching. This means that, say, the
variable binding the (car cursor) in (in-list ...) can be a (ice-9 match) pattern:

(loop/list (((a . b) (in-list '((1 ignore) (2 ignore) (3 ignore))))
  a)
;; => (1 2 3)
2020-12-02 21:17:42 +01:00
Linus
093d1319d9 Fixed a bug with a forgotten :acc.
Inlined the in-file bindings, with the risk of exposing it to a misguided set!.
2020-12-01 20:54:42 +01:00
Linus
c53a08c769 Made simple loops better. Now with correct syntax proliferation.w 2020-12-01 20:53:25 +01:00
Linus
0c110dd080 Big, buggy commit
:for clauses now have finalizers! This means (in-file "path") now works. This meant I had to do some restructuring of many nasty pieces of code, but I believe it works. cl-next was broken up into cl-next/acc and cl-next/for. Accumulators have to pass :acc to (cl-next/acc ...). I plan for :for clauses to do the same.

I fixed tests.scm and README.md to reflect the de-racketification of the for loops.
2020-11-25 20:40:48 +01:00
Linus
1a826f86e2 Undid racketification, because not diffrentiating between :for and :acc means that errors become very strange and unhelpful.
Added simple forms, like loop/list that accumulates bodies into a list.

Add :final that works like in racket:
(loop/list ((:for a (in-list '(1 2 3))) :final (= a 2)) (display a))
=> (1 2)
2020-11-22 21:47:48 +01:00
Linus
80464ebe48 Added some simple versions of loop
loop/first loop/last loop/sum loop/product now added.
2020-11-09 23:18:58 +01:00
Linus
17d72f2cea Added generator sequences
Basic hack of in-cycle and in-indexed
2020-11-09 22:57:18 +01:00
Linus
30b73286b3 Forgot some updates in the readme to accompany previous commit. 2020-11-09 13:44:55 +01:00
Linus
a3244a065a Update readme to reflect recent changes.wq 2020-11-09 13:35:43 +01:00
Linus
2c182da570 Racketifying goof-loop
I have racketified goof loops. No :for or :acc needed, and :when, :unless, and :break are no longer parethesised.
:acc blah (in ...) and :for blah (in ...) has been changed to
(blah (folding ...)) and (blah (in ...))
2020-11-09 13:30:02 +01:00
Linus
716c26c7ce Removed unused, undefined exports.
Shedded some garbage from helpers.scm
2020-11-04 23:20:19 +01:00
Linus
be9ac1a55d Intermediate loops
goof.scm
  * Changed cl-next to properly push all intermediate loops
  * Changed emit-many/rest to emit intermediate loops
  * Added loop/list as a shorthand for just accumulating lists.

tests.scm
  * Collected some things I wanted ta have to track regressions.

README.md
  * Reflect above changes
2020-11-04 23:15:32 +01:00
Linus
f2496604d5 Fixed named update and a bug in accumulating
* goof.scm: Removed positional updates and fixed named updates
 * iterators.scm: Fixed bug in accumulating where only lists were supported.
2020-11-04 11:58:58 +01:00
Linus
b3efccb4aa Clarified readme regarding named update. 2020-11-02 22:20:52 +01:00
Linus
dd86fc8a0b Added a LICENCE file and fixed a small readme error. 2020-11-02 22:17:48 +01:00
Linus
ef96da9658 First commit 2020-11-02 22:11:45 +01:00