DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Waiting For N Seconds In Scheme

07.03.2009
| 4958 views |
  • submit to reddit
        // A means of causing evaluation to be delayed for a certain number of seconds in Scheme. May also be useful in LISP; I don't know. Most useful in begin expressions because it returns (void).

#lang scheme

;; wait : number -> void
;; Calls a local function that recurs on itself until n seconds have passed since wait was called.
(define wait
  (lambda (n)
    (local
      [(define main
         (lambda (x)
           (cond
             [(>= (current-milliseconds) (+ x (* n 1000)))
              (void)]
             [else
              (main x)])))]
      (main (current-milliseconds)))))