diff options
author | Leah Neukirchen <leah@vuxu.org> | 2022-10-13 14:56:06 +0200 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2022-10-13 14:56:17 +0200 |
commit | 653a7f849e3320d7c3ce148ed30485d4c111d195 (patch) | |
tree | c572c422c4b83cc7f52934e98a47b32e681433b2 | |
parent | 2da633a42184b5a60c01163f6d5a07236a31902e (diff) | |
download | mew-653a7f849e3320d7c3ce148ed30485d4c111d195.tar.gz mew-653a7f849e3320d7c3ce148ed30485d4c111d195.tar.xz mew-653a7f849e3320d7c3ce148ed30485d4c111d195.zip |
use generators, add giterate
-rw-r--r-- | mew.egg | 3 | ||||
-rw-r--r-- | mew.scm | 14 | ||||
-rw-r--r-- | mew.svnwiki | 25 |
3 files changed, 38 insertions, 4 deletions
diff --git a/mew.egg b/mew.egg index 250872b..f18c442 100644 --- a/mew.egg +++ b/mew.egg @@ -7,4 +7,5 @@ (synopsis "Convenience library for compact code") (dependencies (matchable 1.1) - (srfi-69 0.4.3))) + (srfi-69 0.4.3) + (srfi-158 0.1))) diff --git a/mew.scm b/mew.scm index 249d6b6..815ea51 100644 --- a/mew.scm +++ b/mew.scm @@ -1,4 +1,4 @@ -(module mew (at dec def div empty? esc fin for generic-for-each get inc keys keyvals loc mod nth op prn puts rep str tbl while until vals) +(module mew (at dec def div empty? esc fin for generic-for-each get giterate inc keys keyvals loc mod nth op prn puts rep str tbl while until vals) (import scheme (rename (chicken base) (print puts)) @@ -9,8 +9,16 @@ (rename (srfi-69) (hash-table-keys keys) (hash-table-values vals)) + srfi-158 matchable) + (reexport srfi-69) + (reexport srfi-158) + (reexport + (rename (srfi-158) + (make-range-generator range) + (circular-generator cycle))) + (reexport (only (chicken base) unless @@ -172,6 +180,7 @@ (cond ((list? obj) for-each) ((vector? obj) vector-for-each) ((hash-table? obj) (lambda (f h) (hash-table-for-each h f))) + ((procedure? obj) generator-for-each) (#t (error "no generic-for-each defined")))) (define-syntax for @@ -182,4 +191,7 @@ ((_ (i obj) body ...) (let ((o obj)) ((generic-for-each o) (lambda (i) body ...) o))))) + + (define (giterate f x) + (make-unfold-generator (op #f) (op) f x)) ) diff --git a/mew.svnwiki b/mew.svnwiki index ac40d03..0a81bee 100644 --- a/mew.svnwiki +++ b/mew.svnwiki @@ -2,6 +2,10 @@ Mew is a library targetting R5RS/R7RS scheme, which provides some conveniences inspired from Goo, Clojure and Arc to allow writing more compact code. +== Re-Exports + +Mew re-exports SRFI-69 (Basic hash tables) +and SRFI-158 (Generators and Accumulators). == Definitions, bindings and assignments @@ -152,5 +156,22 @@ Test if {{<obj>}} is an empty list/string/vector/hash-table. <syntax>(for (<var> <obj>) <body>...)</syntax> <syntax>(for ((<key> <val>) <tbl>) <body>...)</syntax> -Iterate over the items of the list or vector <obj> -or the keys and values of the hash-table <tbl>. +If {{<obj>}} is a list or a vector, iterate over its elements. +If {{<obj>}} is a procedure, consider it a SRFI-158 generator +and iterate over its values. +If {{<obj>}} is a hash-table, iterate over its keys and values. + + +== Generators + +<procedure>(cycle <val>...)</procedure> + +Alias for {{circular-generator}}. + +<procedure>(range <val>...)</procedure> + +Alias for {{make-range-generator}}. + +<procedure>(giterate <fun> <val>)<procedure> + +Generator returning {{<val>}}, {{(<fun> <val>)}}, {{(<fun> (<fun (<val>)))}}... |