Skip to content

Commit

Permalink
Changing sleep to accept (Rational :a) types
Browse files Browse the repository at this point in the history
  • Loading branch information
Izaakwltn committed Oct 14, 2024
1 parent 194c079 commit 42e913a
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions library/system.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#:coalton
#:coalton-library/builtin
#:coalton-library/classes)
(:local-nicknames
(#:arith #:coalton-library/math/arith)
(#:real #:coalton-library/math/real))
(:export
#:gc
#:time
Expand Down Expand Up @@ -61,12 +64,15 @@ While the result will always contain microseconds, some implementations may retu
(cl:* 1000000 (cl:- end start))
cl:internal-time-units-per-second)))))

(declare sleep (Integer -> Unit))
(declare sleep ((real:Rational :a) => :a -> Unit))
(define (sleep n)
"Sleep for `n` seconds."
(lisp Unit (n)
(cl:sleep n)
Unit)))
(if (arith:negative? n)
(error "must be a positive number.")
(let ((frac (real:best-approx n)))
(lisp Unit (frac)
(cl:sleep frac)
Unit)))))

;;;
;;; Pofiling
Expand Down

0 comments on commit 42e913a

Please sign in to comment.