Skip to content

Instantly share code, notes, and snippets.

@cordawyn
Created May 9, 2013 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cordawyn/0ea8cc1727e14857eecf to your computer and use it in GitHub Desktop.
Save cordawyn/0ea8cc1727e14857eecf to your computer and use it in GitHub Desktop.
(define-syntax nested-loop
(syntax-rules ()
((NESTED-LOOP continuation ((state initial) ...) combiner
clause0 clause1+ ...)
(%NESTED-LOOP LOOP continuation ((state initial) ...) combiner
clause0 clause1+ ...))))
(define-syntax %nested-loop
(syntax-rules (PARALLEL NESTED DO LET LET-VALUES IF NOT AND OR)
((%NESTED-LOOP looper continuation ((state initial) ...) combiner
expression)
(LET ((state initial) ...)
(combiner (LAMBDA () expression) continuation)))
((%NESTED-LOOP looper continuation ((state initial) ...) combiner
(PARALLEL (iterator ...) ...)
clause0 clause1+ ...)
(looper CONTINUE ((WITH state initial)
...
(iterator ...)
...)
=> (continuation state ...)
(%NESTED-LOOP looper (LAMBDA (state ...) (CONTINUE state ...))
((state state) ...)
combiner
clause0 clause1+ ...)))
((%NESTED-LOOP looper continuation ((state initial) ...) combiner
(NESTED clause ...)
clause0 clause1+ ...)
(%NESTED-LOOP looper continuation ((state initial) ...) combiner
clause ... clause0 clause1+ ...))
((%NESTED-LOOP looper continuation ((state initial) ...) combiner
(DO command ...)
clause0 clause1+ ...)
(BEGIN command ...
(%NESTED-LOOP looper continuation ((state initial) ...) combiner
clause0 clause1+ ...)))
((%NESTED-LOOP looper continuation ((state initial) ...) combiner
(LET ((variable value) ...))
clause0 clause1+ ...)
(LET ((variable value) ...)
(%NESTED-LOOP looper continuation ((state initial) ...) combiner
clause0 clause1+ ...)))
((%NESTED-LOOP looper continuation ((state initial) ...) combiner
(LET variable value)
clause0 clause1+ ...)
(LET ((variable value))
(%NESTED-LOOP looper continuation ((state initial) ...) combiner
clause0 clause1+ ...)))
((%NESTED-LOOP looper continuation ((state initial) ...) combiner
(LET-VALUES ((bvl expression) ...))
clause0 clause1+ ...)
(LET-VALUES ((bvl expression) ...)
(%NESTED-LOOP looper continuation ((state initial) ...) combiner
clause0 clause1+ ...)))
((%NESTED-LOOP looper continuation ((state initial) ...) combiner
(LET-VALUES bvl expression)
clause0 clause1+ ...)
(LET-VALUES ((bvl expression))
(%NESTED-LOOP looper continuation ((state initial) ...) combiner
clause0 clause1+ ...)))
((%NESTED-LOOP looper continuation ((state initial) ...) combiner
(IF condition)
clause0 clause1+ ...)
(IF condition
(%NESTED-LOOP looper continuation ((state initial) ...) combiner
clause0 clause1+ ...)
(continuation initial ...)))
((%NESTED-LOOP looper continuation ((state initial) ...) combiner
((iterator ...) ...)
clause0 clause1+ ...)
(%NESTED-LOOP looper continuation ((state initial) ...) combiner
(PARALLEL (iterator ...) ...)
clause0 clause1+ ...))
;** This clause must come last! It would shadow the others.
((%NESTED-LOOP looper continuation ((state initial) ...) combiner
(iterator ...)
clause0 clause1+ ...)
(%NESTED-LOOP looper continuation ((state initial) ...) combiner
(PARALLEL (iterator ...))
clause0 clause1+ ...))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment