sva36556.scm 654 B

123456789101112131415161718192021222324252627
  1. (define (bind-return loop-id k body)
  2. (let ((return-id (datum->syntax loop-id 'return)))
  3. #`(call/cc
  4. (lambda (#,k)
  5. (let-syntax ((#,return-id
  6. (syntax-rules ()
  7. ((_ exp)
  8. (call-with-values (lambda () exp) #,k)))))
  9. #,body)))))
  10. (define (simple-loop form)
  11. (syntax-case form ()
  12. ((loop-id forms ...)
  13. (bind-return
  14. #'loop-id #'k
  15. #`(let loop ()
  16. (begin forms ...)
  17. (loop))))))
  18. (define-syntax xloop simple-loop)
  19. (display (if (eq? (xloop (return #t)) #t)
  20. 'ok
  21. 'failed))
  22. (newline)
  23. ;; Output: ok