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

  • 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)
      [(define main
         (lambda (x)
             [(>= (current-milliseconds) (+ x (* n 1000)))
              (main x)])))]
      (main (current-milliseconds)))))