Made it a module.
Put it in any directory, run guile -L . and then import (goof) in that directory.
This commit is contained in:
parent
317b3e732b
commit
7ddb707bb7
5 changed files with 59 additions and 14 deletions
9
example.scm
Normal file
9
example.scm
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
(load "goof.scm")
|
||||||
|
|
||||||
|
(define (erathostenes n)
|
||||||
|
(define vec (make-vector n #t))
|
||||||
|
(loop/list ((:for i (up-from 2 (to n)))
|
||||||
|
(:when (vector-ref vec i)))
|
||||||
|
(loop ((:for j (up-from (* 2 i) (to n) (by i))))
|
||||||
|
(vector-set! vec j #f))
|
||||||
|
i))
|
60
goof.scm
60
goof.scm
|
@ -32,14 +32,50 @@
|
||||||
;; name, and the fact that I goofed in the chibi issue tracker when
|
;; name, and the fact that I goofed in the chibi issue tracker when
|
||||||
;; trying to understand the iterator protocol.
|
;; trying to understand the iterator protocol.
|
||||||
|
|
||||||
;; TODO add :let and :let* to forify
|
(define-module (goof)
|
||||||
|
#:use-module (goof helpers)
|
||||||
|
#:use-module (goof ref-let)
|
||||||
|
#:use-module ((srfi srfi-1) #:select (circular-list))
|
||||||
|
#:use-module (srfi srfi-71)
|
||||||
|
#:use-module (rnrs io simple)
|
||||||
|
#:use-module (ice-9 futures)
|
||||||
|
#:export (loop
|
||||||
|
|
||||||
(use-modules (helpers)
|
loop/list
|
||||||
(ref-let)
|
loop/sum
|
||||||
((srfi srfi-1) #:select (circular-list))
|
loop/product
|
||||||
(srfi srfi-71)
|
loop/first
|
||||||
(rnrs io simple)
|
loop/last
|
||||||
(ice-9 futures))
|
loop/and
|
||||||
|
loop/or
|
||||||
|
loop/list/parallel
|
||||||
|
|
||||||
|
:when :unless :break :final :let :let* :subloop :for :acc
|
||||||
|
|
||||||
|
in
|
||||||
|
in-list
|
||||||
|
in-lists
|
||||||
|
|
||||||
|
in-vector in-reverse-vector
|
||||||
|
in-string in-reverse-string
|
||||||
|
|
||||||
|
in-port
|
||||||
|
in-file
|
||||||
|
in-generator
|
||||||
|
up-from
|
||||||
|
down-from
|
||||||
|
accumulating
|
||||||
|
folding
|
||||||
|
listing
|
||||||
|
listing-reverse
|
||||||
|
appending
|
||||||
|
appending-reverse
|
||||||
|
summing
|
||||||
|
multiplying
|
||||||
|
|
||||||
|
in-cycle
|
||||||
|
in-indexed
|
||||||
|
))
|
||||||
|
|
||||||
(define-aux-syntaxes
|
(define-aux-syntaxes
|
||||||
;; Auxiliary syntax for the loop clauses
|
;; Auxiliary syntax for the loop clauses
|
||||||
|
@ -53,20 +89,20 @@
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
(include "iterators.scm")
|
(include "goof/iterators.scm")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(define-syntax loop
|
(define-syntax loop
|
||||||
(syntax-rules (=>)
|
(syntax-rules (=>)
|
||||||
((loop () => expr body ...)
|
((loop () => expr body ...)
|
||||||
(let () expr))
|
(loop ((:for ensure-once (up-from 0 1))) => expr body ...))
|
||||||
((loop () body ...)
|
((loop () body ...)
|
||||||
(let () body ...))
|
(loop ((:for ensure-once (up-from 0 1))) body ...))
|
||||||
((loop name () => expr body ...)
|
((loop name () => expr body ...)
|
||||||
expr)
|
(loop name ((:for ensure-once (up-from 0 1))) => expr body ...))
|
||||||
((loop name () body ...)
|
((loop name () body ...)
|
||||||
(if #f #f))
|
(loop name ((:for ensure-once (up-from 0 1))) body ...))
|
||||||
((loop (clauses ...) body ...)
|
((loop (clauses ...) body ...)
|
||||||
(ensure-for-clause (loop (clauses ...) body ...)
|
(ensure-for-clause (loop (clauses ...) body ...)
|
||||||
loop-name (clauses ...)
|
loop-name (clauses ...)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
(define-module (helpers)
|
(define-module (goof helpers)
|
||||||
#:export (define-aux-syntax define-aux-syntaxes))
|
#:export (define-aux-syntax define-aux-syntaxes))
|
||||||
|
|
||||||
(define-syntax define-aux-syntax
|
(define-syntax define-aux-syntax
|
|
@ -1,4 +1,4 @@
|
||||||
(define-module (ref-let)
|
(define-module (goof ref-let)
|
||||||
#:export (ref-let)
|
#:export (ref-let)
|
||||||
#:use-module (ice-9 match)
|
#:use-module (ice-9 match)
|
||||||
#:use-module (srfi srfi-71))
|
#:use-module (srfi srfi-71))
|
Loading…
Add table
Add a link
Reference in a new issue