Skip to content

Instantly share code, notes, and snippets.

@noqisofon
Created September 14, 2024 03:00
Show Gist options
  • Save noqisofon/97c5e16a1692ca7d8de902e6a3cd342c to your computer and use it in GitHub Desktop.
Save noqisofon/97c5e16a1692ca7d8de902e6a3cd342c to your computer and use it in GitHub Desktop.
( ノ╹◡◡╹)ノ くりかえしまくろ~~~~
(include "./reiteration.scm")
(dolist (i '(0 1 2 3 4 5 6 7 8 9))
(display i)
(display " "))
(define-syntax dolist
(syntax-rules ()
((_ (it seq result) body ...)
(let loop ((xs seq))
(if (null? xs)
result
(begin
(let ((it (car xs)))
body
...)
(loop (cdr xs))))))
((_ (it seq) body ...)
(let loop ((xs seq))
(if (null? xs)
'()
(begin
(let ((it (car xs)))
body
...)
(loop (cdr xs))))))
((_ (seq) body ...)
(let loop ((xs seq))
(if (null? xs)
'()
(begin
body
...
(loop (cdr xs))))))))
(define-syntax dotimes
(syntax-rules ()
((_ (it num-expr) body ...)
(let loop ((n 0))
(if (< num-expr n)
'()
(begin
(let ((it n))
body
...)
(loop (+ n 1))))))
((_ (num-expr) body ...)
(let loop ((n 0))
(if (< num-expr n)
'()
(begin
body
...
(loop (+ n 1))))))))
(define-syntax while
(syntax-rules ()
((_ expr body ...)
(let loop ()
(if expr
(begin
body
...
(loop))
'())))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment