Skip to content

Instantly share code, notes, and snippets.

@SYZYGY-DEV333
Created March 9, 2016 00:11
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 SYZYGY-DEV333/5d8c829438f283659b2d to your computer and use it in GitHub Desktop.
Save SYZYGY-DEV333/5d8c829438f283659b2d to your computer and use it in GitHub Desktop.
Simple while loop macro in Chicken Scheme
;; Chicken Scheme
;; While Macro in Chicken Scheme
;; SYZYGY-DEV333
;; Apache v2
(define-syntax loop
(ir-macro-transformer
(lambda (expr inject compare)
(let ((body (cdr expr)))
`(call-with-current-continuation
(lambda (,(inject 'exit))
(let f () ,@body (f))))))))
(define-syntax while
(ir-macro-transformer
(lambda (expr inject compare)
(let ((test (cadr expr))
(body (cddr expr)))
`(loop
(if (not ,test) (,(inject 'exit) #f))
,@body)))))
@SYZYGY-DEV333
Copy link
Author

Simple While Loop Macro in Chicken Scheme

Syntax:

(while (condition)
  <body>)

Pointless Example:

(while (= 1 1)
  (display "hello world\n"))

Have fun!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment