2 ;;; Copyright (c) 2005--2007, by A.J. Rossini <blindglobe@gmail.com>
3 ;;; See COPYRIGHT file for any additional restrictions (BSD license).
4 ;;; Since 1991, ANSI was finally finished. Edited for ANSI Common Lisp.
6 ;;;; lsmacros -- Various macros
8 ;;;; Copyright (c) 1991, by Luke Tierney. Permission is granted for
12 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14 ;;; Macros for LISP-STAT-BASICS Package
16 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
18 (in-package :lisp-stat-macros
)
20 ;;; Floating Point Macros
22 (defmacro declare-double
(&rest vars
) `(declare (long-float ,@vars
)))
24 ;;; Macros for Defining Vectorized Funcitons
26 (defmacro make-vectorized-function
(sym fcn
)
27 `(defun ,sym
(&rest args
)
28 (apply #'map-elements
#',fcn args
)))
30 (defmacro fixup-vectorized-doc-list
(sym)
31 `(let ((doc (documentation ',sym
'function
)))
32 (if doc
(list (format nil
"~s~%Vectorized." ,sym
)))))
36 ;; recursively vectorizes (rv) functions in dists and lispstat-math.
37 (defmacro make-rv-function
(sym fcn
&rest args
)
39 ((and args
(= (length args
) 1))
41 ,@(fixup-vectorized-doc-list fcn
)
42 (declare (inline compound-data-p
,fcn
,sym recursive-map-elements list
))
43 (if (compound-data-p ,@args
)
44 (recursive-map-elements #',fcn
#',sym
,@args
)
48 ,@(fixup-vectorized-doc-list fcn
)
49 (declare (inline compound-data-p
,fcn
,sym recursive-map-elements list
))
50 (if ,(cons 'or
(mapcar #'(lambda (x) (list 'compound-data-p x
)) args
))
51 (recursive-map-elements #',fcn
#',sym
,@args
)
54 `(defun ,sym
(&optional
(x nil has-x
) (y nil has-y
) &rest args
)
55 ,@(fixup-vectorized-doc-list fcn
)
56 (declare (inline compound-data-p
,fcn
,sym recursive-map-elements list
))
59 (if (or args
(compound-data-p x
) (compound-data-p y
))
60 (apply #'recursive-map-elements
#',fcn
#',sym x y args
)
62 (if (compound-data-p x
)
63 (recursive-map-elements #',fcn
#',sym x
)
67 (defmacro make-rv-function-1
(sym fcn
&rest args
)
69 ((and args
(= (length args
) 1))
71 ,@(fixup-vectorized-doc-list fcn
)
72 (declare (inline compound-data-p
,fcn
,sym recursive-map-elements list
))
73 (if (compound-data-p ,@args
)
74 (recursive-map-elements #',fcn
#',sym
,@args
)
78 ,@(fixup-vectorized-doc-list fcn
)
79 (declare (inline compound-data-p
,fcn
,sym recursive-map-elements list
))
80 (if ,(cons 'or
(mapcar #'(lambda (x) (list 'compound-data-p x
)) args
))
81 (recursive-map-elements #',fcn
#',sym
,@args
)
84 `(defun ,sym
(x &optional
(y nil has-y
) &rest args
)
85 ,@(fixup-vectorized-doc-list fcn
)
86 (declare (inline compound-data-p
,fcn
,sym recursive-map-elements list
))
88 (if (or args
(compound-data-p x
) (compound-data-p y
))
89 (apply #'recursive-map-elements
#',fcn
#',sym x y args
)
91 (if (compound-data-p x
)
92 (recursive-map-elements #',fcn
#',sym x
)