1 (in-package :parenscript
)
3 ;;; Handy utilities for doing common tasks found in many web browser
4 ;;; JavaScript implementations
6 (defpsmacro do-set-timeout
((timeout) &body body
)
7 `(set-timeout (lambda () ,@body
) ,timeout
))
11 (defmacro def-js-maths
(&rest mathdefs
)
12 `(progn ,@(mapcar (lambda (def) (cons 'defpsmacro def
)) mathdefs
)))
15 (min (&rest nums
) `(*math.min
,@nums
))
16 (max (&rest nums
) `(*math.max
,@nums
))
17 (ceiling (n &optional divisor
) `(*math.ceil
,(if divisor
`(/ ,n
,divisor
) n
)))
18 (abs (n) `(*math.abs
,n
))
19 (sin (n) `(*math.sin
,n
))
20 (cos (n) `(*math.cos
,n
))
21 (tan (n) `(*math.tan
,n
))
22 (acos (n) `(*math.acos
,n
))
23 (asin (n) `(*math.asin
,n
))
24 (atan (n) `(*math.atan
,n
))
25 (exp (n) `(*math.exp
,n
))
26 (floor (n &optional divisor
) `(*math.floor
,(if divisor
`(/ ,n
,divisor
) n
)))
27 (expt (base power
) `(*math.pow
,base
,power
))
28 (round (n &optional divisor
) `(*math.round
,(if divisor
`(/ ,n
,divisor
) n
)))
29 (random (&optional upto
) (if upto
30 `(floor (* ,upto
(*math.random
)))
33 (evenp (n) `(not (oddp ,n
))))
35 ;;; Exception handling
37 (defpsmacro ignore-errors
(&body body
)
38 `(try (progn ,@body
) (:catch
(e))))