Commit 77e61dbe authored by Liam M. Healy's avatar Liam M. Healy
Browse files

Dyadic functions with pq-grid arguments

Fixed funcall-dyadic, which is used by basic arithmetic functions like
#'*i, for cases where one or both arguments is a pq-grid.  In that
case, the units are simply removed.  This is not as good as restoring
the proper units after the calculation completes, but it is a step
towards that goal.  New type 'grid:grid.
parent aa63ffc9
;; Functions on grids
;; Liam Healy 2010-06-19 22:25:17EDT functions.lisp
;; Time-stamp: <2011-01-30 19:19:46EST functions.lisp>
;; Time-stamp: <2011-02-13 22:31:11EST functions.lisp>
;; Copyright 2010 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -20,7 +20,8 @@
(in-package :grid)
(export '(*grid-types* gridp grid-rank dimensions specification make-grid gref gref* contents))
(export '(*grid-types* gridp grid grid-rank dimensions
specification make-grid gref gref* contents))
(export '(make-simple-grid *default-grid-type* *default-element-type* *default-dimensions*))
;;;;****************************************************************************
......@@ -36,6 +37,8 @@
(or (antik::pq-gridp object)
(find-if (lambda (type) (typep object type)) *grid-types*)))
(deftype grid () '(satisfies gridp))
;;;;****************************************************************************
;;;; Properties of the grid
;;;;****************************************************************************
......
;; Generic functions for generalized numbers
;; Liam Healy Tue Feb 9 1999 - 21:38
;; Time-stamp: <2011-01-18 22:49:26EST generic.lisp>
;; Time-stamp: <2011-02-13 22:43:31EST generic.lisp>
;; Copyright 2011 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -73,7 +73,11 @@
other. If return-other is a function designator, funcall
return-other-monadic on the other argument if one passes that
test."
;; This should not be used if both a and b are numbers.
;; This should not be used if both a and b are numbers. Check that
;; both are arguments are not non-pq grids, otherwise it will
;; recurse indefinitely.
(assert (not (and (grid:gridp a) (not (typep a 'physical-quantity))
(grid:gridp b) (not (typep b 'physical-quantity)))))
(cond
((and return-other (funcall return-other a))
(funcall (or return-other-monadic 'identity) b))
......@@ -82,8 +86,15 @@
(t
(handler-case
(funcall op
(if (numberp a) (coerce a b))
(if (numberp b) (coerce b a)))
;; if args are pqs, just throw away units
(etypecase a
(number (coerce a b))
(physical-quantity (pqval a))
(grid:grid a))
(etypecase b
(number (coerce b a))
(physical-quantity (pqval b))
(grid:grid b)))
(coerce-undefined ()
;; This is redundant, but I'm leaving it here so that it
;; could be replaced with something more meaningful if
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment