33ec50895f68

Add 1in
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Fri, 07 Aug 2020 14:50:01 -0400 (2020-08-07)
parents c5a16c723abb
children c15cbbfc3d37 652d3e91c0f9
branches/tags (none)
files src/math.lisp

Changes

--- a/src/math.lisp	Fri Feb 28 20:36:35 2020 -0500
+++ b/src/math.lisp	Fri Aug 07 14:50:01 2020 -0400
@@ -54,11 +54,17 @@
   "Coerce the top of the stack to a DOUBLE-FLOAT."
   (push! (coerce x 'double-float)))
 
+(define-command 1in (p)
+  "Convert a probability to `1 in X` form and push `X`."
+  (let ((p (rationalize p)))
+    (push! (coerce (/ (denominator p) (numerator p))
+                   'double-float))))
+
 (define-command range (from below)
-  (map nil #'push! (range from below)))
+  (loop for x :from from :below below :do (push! x)))
 
 (define-command irange (from to)
-  (map nil #'push! (range from (1+ to))))
+  (loop for x :from from :to to :do (push! x)))
 
 (define-command base (n)
   "Set the print base and read base for numbers to the top element of the stack.