changeset 41266:c08a55ae8e5d

(calc-wrapper, calc-slow-wrapper) (math-showing-full-precision, math-with-extra-prec, math-working) (calc-with-default-simplification) (calc-with-trail-buffer): Use backtick. (Math-zerop, Math-integer-negp, Math-integer-posp, Math-negp) (Math-looks-negp, Math-posp, Math-integerp, Math-natnump) (Math-ratp, Math-realp, Math-anglep, Math-numberp, Math-scalarp) (Math-vectorp, Math-messy-integerp, Math-objectp, Math-objvecp) (Math-integer-neg, Math-equal, Math-lessp, Math-primp) (Math-num-integerp, Math-bignum-test, Math-equal-int) (Math-natnum-lessp, math-format-radix-digit): Change to `defsubst'. (calc-record-compilation-date-macro): Deleted. Callers updated. (math-format-radix-digit): Move to calc-bin.el. Change all toplevel `setq' forms to `defvar' forms, and move them before their first use. Use `when', `unless'. Remove trailing periods from error forms. Add description and headers suggested by Emacs Lisp coding conventions.
author Colin Walters <walters@gnu.org>
date Mon, 19 Nov 2001 07:35:49 +0000
parents eb26445485bc
children e9718841a5b1
files lisp/calc/calc-macs.el
diffstat 1 files changed, 143 insertions(+), 168 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/calc/calc-macs.el	Mon Nov 19 07:34:59 2001 +0000
+++ b/lisp/calc/calc-macs.el	Mon Nov 19 07:35:49 2001 +0000
@@ -1,6 +1,9 @@
-;; Calculator for GNU Emacs, part I [calc-macs.el]
+;;; calc-macs.el --- important macros for Calc
+
 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc.
-;; Written by Dave Gillespie, daveg@synaptics.com.
+
+;; Author: David Gillespie <daveg@synaptics.com>
+;; Maintainer: Colin Walters <walters@debian.org>
 
 ;; This file is part of GNU Emacs.
 
@@ -19,211 +22,183 @@
 ;; file named COPYING.  Among other things, the copyright notice
 ;; and this notice must be preserved on all copies.
 
+;;; Commentary:
+
+;;; Code:
 
 (provide 'calc-macs)
 
 (defun calc-need-macros () nil)
 
-
-(defmacro calc-record-compilation-date-macro ()
-  `(setq calc-installed-date ,(concat (current-time-string)
-				      " by "
-				      (user-full-name))))
-
-
 (defmacro calc-wrapper (&rest body)
-  (list 'calc-do (list 'function (append (list 'lambda ()) body))))
+  `(calc-do (function (lambda ()
+			,@body))))
 
-;; We use "point" here to generate slightly smaller byte-code than "t".
 (defmacro calc-slow-wrapper (&rest body)
-  (list 'calc-do (list 'function (append (list 'lambda ()) body)) (point)))
-
+  `(calc-do
+    (function (lambda () ,@body) (point))))
 
-(defmacro math-showing-full-precision (body)
-  (list 'let
-	'((calc-float-format calc-full-float-format))
-	body))
-
+(defmacro math-showing-full-precision (form)
+  `(let ((calc-float-format calc-full-float-format))
+     ,form))
 
 (defmacro math-with-extra-prec (delta &rest body)
-  (` (math-normalize
-      (let ((calc-internal-prec (+ calc-internal-prec (, delta))))
-	(,@ body)))))
+  `(math-normalize
+    (let ((calc-internal-prec (+ calc-internal-prec ,delta)))
+      ,@body)))
+
+(defmacro math-working (msg arg)	; [Public]
+  `(if (eq calc-display-working-message 'lots)
+       (math-do-working ,msg ,arg)))
 
+(defmacro calc-with-default-simplification (body)
+  `(let ((calc-simplify-mode (and (not (memq calc-simplify-mode '(none num)))
+				  calc-simplify-mode)))
+     ,@body))
+
+(defmacro calc-with-trail-buffer (&rest body)
+  `(let ((save-buf (current-buffer))
+	 (calc-command-flags nil))
+     (with-current-buffer (calc-trail-display t)
+       (progn
+	 (goto-char calc-trail-pointer)
+	 ,@body))))
 
 ;;; Faster in-line version zerop, normalized values only.
-(defmacro Math-zerop (a)   ; [P N]
-  (` (if (consp (, a))
-	 (and (not (memq (car (, a)) '(bigpos bigneg)))
-	      (if (eq (car (, a)) 'float)
-		  (eq (nth 1 (, a)) 0)
-		(math-zerop (, a))))
-       (eq (, a) 0))))
+(defsubst Math-zerop (a)		; [P N]
+  (if (consp a)
+      (and (not (memq (car a) '(bigpos bigneg)))
+	   (if (eq (car a) 'float)
+	       (eq (nth 1 a) 0)
+	     (math-zerop a)))
+    (eq a 0)))
 
-(defmacro Math-integer-negp (a)
-  (` (if (consp (, a))
-	 (eq (car (, a)) 'bigneg)
-       (< (, a) 0))))
+(defsubst Math-integer-negp (a)
+  (if (consp a)
+      (eq (car a) 'bigneg)
+    (< a 0)))
 
-(defmacro Math-integer-posp (a)
-  (` (if (consp (, a))
-	 (eq (car (, a)) 'bigpos)
-       (> (, a) 0))))
-
+(defsubst Math-integer-posp (a)
+  (if (consp a)
+      (eq (car a) 'bigpos)
+    (> a 0)))
 
-(defmacro Math-negp (a)
-  (` (if (consp (, a))
-	 (or (eq (car (, a)) 'bigneg)
-	     (and (not (eq (car (, a)) 'bigpos))
-		  (if (memq (car (, a)) '(frac float))
-		      (Math-integer-negp (nth 1 (, a)))
-		    (math-negp (, a)))))
-       (< (, a) 0))))
-
+(defsubst Math-negp (a)
+  (if (consp a)
+      (or (eq (car a) 'bigneg)
+	  (and (not (eq (car a) 'bigpos))
+	       (if (memq (car a) '(frac float))
+		   (Math-integer-negp (nth 1 a))
+		 (math-negp a))))
+    (< a 0)))
 
-(defmacro Math-looks-negp (a)   ; [P x] [Public]
-  (` (or (Math-negp (, a))
-	 (and (consp (, a)) (or (eq (car (, a)) 'neg)
-				(and (memq (car (, a)) '(* /))
-				     (or (math-looks-negp (nth 1 (, a)))
-					 (math-looks-negp (nth 2 (, a))))))))))
-
+(defsubst Math-looks-negp (a)		; [P x] [Public]
+  (or (Math-negp a)
+      (and (consp a) (or (eq (car a) 'neg)
+			 (and (memq (car a) '(* /))
+			      (or (math-looks-negp (nth 1 a))
+				  (math-looks-negp (nth 2 a))))))))
 
-(defmacro Math-posp (a)
-  (` (if (consp (, a))
-	 (or (eq (car (, a)) 'bigpos)
-	     (and (not (eq (car (, a)) 'bigneg))
-		  (if (memq (car (, a)) '(frac float))
-		      (Math-integer-posp (nth 1 (, a)))
-		    (math-posp (, a)))))
-       (> (, a) 0))))
-
+(defsubst Math-posp (a)
+  (if (consp a)
+      (or (eq (car a) 'bigpos)
+	  (and (not (eq (car a) 'bigneg))
+	       (if (memq (car a) '(frac float))
+		   (Math-integer-posp (nth 1 a))
+		 (math-posp a))))
+    (> a 0)))
 
-(defmacro Math-integerp (a)
-  (` (or (not (consp (, a)))
-	 (memq (car (, a)) '(bigpos bigneg)))))
-
+(defsubst Math-integerp (a)
+  (or (not (consp a))
+      (memq (car a) '(bigpos bigneg))))
 
-(defmacro Math-natnump (a)
-  (` (if (consp (, a))
-	 (eq (car (, a)) 'bigpos)
-       (>= (, a) 0))))
+(defsubst Math-natnump (a)
+  (if (consp a)
+      (eq (car a) 'bigpos)
+    (>= a 0)))
 
-(defmacro Math-ratp (a)
-  (` (or (not (consp (, a)))
-	 (memq (car (, a)) '(bigpos bigneg frac)))))
+(defsubst Math-ratp (a)
+  (or (not (consp a))
+      (memq (car a) '(bigpos bigneg frac))))
 
-(defmacro Math-realp (a)
-  (` (or (not (consp (, a)))
-	 (memq (car (, a)) '(bigpos bigneg frac float)))))
+(defsubst Math-realp (a)
+  (or (not (consp a))
+      (memq (car a) '(bigpos bigneg frac float))))
 
-(defmacro Math-anglep (a)
-  (` (or (not (consp (, a)))
-	 (memq (car (, a)) '(bigpos bigneg frac float hms)))))
+(defsubst Math-anglep (a)
+  (or (not (consp a))
+      (memq (car a) '(bigpos bigneg frac float hms))))
 
-(defmacro Math-numberp (a)
-  (` (or (not (consp (, a)))
-	 (memq (car (, a)) '(bigpos bigneg frac float cplx polar)))))
+(defsubst Math-numberp (a)
+  (or (not (consp a))
+      (memq (car a) '(bigpos bigneg frac float cplx polar))))
 
-(defmacro Math-scalarp (a)
-  (` (or (not (consp (, a)))
-	 (memq (car (, a)) '(bigpos bigneg frac float cplx polar hms)))))
+(defsubst Math-scalarp (a)
+  (or (not (consp a))
+      (memq (car a) '(bigpos bigneg frac float cplx polar hms))))
 
-(defmacro Math-vectorp (a)
-  (` (and (consp (, a)) (eq (car (, a)) 'vec))))
+(defsubst Math-vectorp (a)
+  (and (consp a) (eq (car a) 'vec)))
 
-(defmacro Math-messy-integerp (a)
-  (` (and (consp (, a))
-	  (eq (car (, a)) 'float)
-	  (>= (nth 2 (, a)) 0))))
+(defsubst Math-messy-integerp (a)
+  (and (consp a)
+       (eq (car a) 'float)
+       (>= (nth 2 a) 0)))
 
-(defmacro Math-objectp (a)    ;  [Public]
-  (` (or (not (consp (, a)))
-	 (memq (car (, a))
-	       '(bigpos bigneg frac float cplx polar hms date sdev intv mod)))))
+(defsubst Math-objectp (a)		;  [Public]
+  (or (not (consp a))
+      (memq (car a)
+	    '(bigpos bigneg frac float cplx polar hms date sdev intv mod))))
 
-(defmacro Math-objvecp (a)    ;  [Public]
-  (` (or (not (consp (, a)))
-	 (memq (car (, a))
-	       '(bigpos bigneg frac float cplx polar hms date
-			sdev intv mod vec)))))
-
+(defsubst Math-objvecp (a)		;  [Public]
+  (or (not (consp a))
+      (memq (car a)
+	    '(bigpos bigneg frac float cplx polar hms date
+		     sdev intv mod vec))))
 
 ;;; Compute the negative of A.  [O O; o o] [Public]
-(defmacro Math-integer-neg (a)
-  (` (if (consp (, a))
-	 (if (eq (car (, a)) 'bigpos)
-	     (cons 'bigneg (cdr (, a)))
-	   (cons 'bigpos (cdr (, a))))
-       (- (, a)))))
-
-
-(defmacro Math-equal (a b)
-  (` (= (math-compare (, a) (, b)) 0)))
-
-(defmacro Math-lessp (a b)
-  (` (= (math-compare (, a) (, b)) -1)))
-
+(defsubst Math-integer-neg (a)
+  (if (consp a)
+      (if (eq (car a) 'bigpos)
+	  (cons 'bigneg (cdr a))
+	(cons 'bigpos (cdr a)))
+    (- a)))
 
-(defmacro math-working (msg arg)    ; [Public]
-  (` (if (eq calc-display-working-message 'lots)
-	 (math-do-working (, msg) (, arg)))))
-
+(defsubst Math-equal (a b)
+  (= (math-compare a b) 0))
 
-(defmacro calc-with-default-simplification (body)
-  (list 'let
-	'((calc-simplify-mode (and (not (memq calc-simplify-mode '(none num)))
-				   calc-simplify-mode)))
-	body))
+(defsubst Math-lessp (a b)
+  (= (math-compare a b) -1))
 
-
-(defmacro Math-primp (a)
-  (` (or (not (consp (, a)))
-	 (memq (car (, a)) '(bigpos bigneg frac float cplx polar
-				    hms date mod var)))))
-
+(defsubst Math-primp (a)
+  (or (not (consp a))
+      (memq (car a) '(bigpos bigneg frac float cplx polar
+			     hms date mod var))))
 
-(defmacro calc-with-trail-buffer (&rest body)
-  (` (let ((save-buf (current-buffer))
-	   (calc-command-flags nil))
-       (unwind-protect
-	   (, (append '(progn
-			 (set-buffer (calc-trail-display t))
-			 (goto-char calc-trail-pointer))
-		      body))
-	 (set-buffer save-buf)))))
+(defsubst Math-num-integerp (a)
+  (or (not (consp a))
+      (memq (car a) '(bigpos bigneg))
+      (and (eq (car a) 'float)
+	   (>= (nth 2 a) 0))))
 
-
-(defmacro Math-num-integerp (a)
-  (` (or (not (consp (, a)))
-	 (memq (car (, a)) '(bigpos bigneg))
-	 (and (eq (car (, a)) 'float)
-	      (>= (nth 2 (, a)) 0)))))
-
+(defsubst Math-bignum-test (a)		; [B N; B s; b b]
+  (if (consp a)
+      a
+    (math-bignum a)))
 
-(defmacro Math-bignum-test (a)   ; [B N; B s; b b]
-  (` (if (consp (, a))
-	 (, a)
-       (math-bignum (, a)))))
-
+(defsubst Math-equal-int (a b)
+  (or (eq a b)
+      (and (consp a)
+	   (eq (car a) 'float)
+	   (eq (nth 1 a) b)
+	   (= (nth 2 a) 0))))
 
-(defmacro Math-equal-int (a b)
-  (` (or (eq (, a) (, b))
-	 (and (consp (, a))
-	      (eq (car (, a)) 'float)
-	      (eq (nth 1 (, a)) (, b))
-	      (= (nth 2 (, a)) 0)))))
-
-(defmacro Math-natnum-lessp (a b)
-  (` (if (consp (, a))
-	 (and (consp (, b))
-	      (= (math-compare-bignum (cdr (, a)) (cdr (, b))) -1))
-       (or (consp (, b))
-	   (< (, a) (, b))))))
-
-
-(defmacro math-format-radix-digit (a)   ; [X D]
-  (` (aref math-radix-digits (, a))))
+(defsubst Math-natnum-lessp (a b)
+  (if (consp a)
+      (and (consp b)
+	   (= (math-compare-bignum (cdr a) (cdr b)) -1))
+    (or (consp b)
+	(< a b))))
 
 ;;; calc-macs.el ends here