;;; -*- Mode: Lisp; Package: Maxima; Syntax: Common-Lisp; Base: 10 -*- ;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; The data in this file contains enhancments. ;;;;; ;;; ;;;;; ;;; Copyright (c) 1984,1987 by William Schelter,University of Texas ;;;;; ;;; All rights reserved ;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (in-package :maxima) (defun memq (x lis) (member x lis :test #'eq)) (eval-when #+gcl (compile load) #-gcl (:compile-toplevel :load-toplevel) ;;this will make operators which ;;declare the type and result of numerical operations (defmacro def-op (name type op &optional return-type) `(setf (macro-function ',name) (make-operation ',type ',op ',return-type))) ;;make very sure .type .op and .return are not special!! (defun make-operation (.type .op .return) (or .return (setf .return .type)) #'(lambda (bod env) (declare (ignore env)) (loop for v in (cdr bod) when (eq t .type) collect v into body else collect `(the , .type ,v) into body finally (setq body `(, .op ,@body)) (return (if (eq t .return) body `(the , .return ,body)))))) #+fix-debug (progn ;; these allow running of code and they print out where the error occurred (defvar *dbreak* t) (defun chk-type (lis na typ sho) (unless (every #'(lambda (v) (typep v typ)) lis) (format t "~%Bad call ~a types:~a" (cons na sho) (mapcar #'type-of lis)) (when *dbreak* (break "hi")))) (defmacro def-op (name type old) `(defmacro ,name (&rest l) `(progn (chk-type (list ,@l) ',',name ',',type ',l) (,',old ,@l))))) (def-op f+ fixnum +) (def-op f* fixnum *) (def-op f- fixnum -) (def-op f1- fixnum 1-) (def-op f1+ fixnum 1+) (def-op quotient t quot) (def-op // t quot)) ;;this is essentially what the quotient is supposed to do. (defun quot (a &rest b) (cond ((null b) (quot 1 a)) ((null (cdr b)) (setq b (car b)) (cond ((and (integerp a) (integerp b)) (values (truncate a b))) (t (/ a b)))) (t (apply #'quot (quot a (car b)) (cdr b))))) (defmacro status (option &optional item) (cond ((equal (symbol-name option) (symbol-name '#:feature)) `(member ,(intern (string item) (find-package 'keyword)) *features*)) ((equal option 'gctime) 0))) ;;numbers (length ar) 0) (set-up-cursor ar) (loop while (aset-by-cursor ar (car x)) do (and (cdr x) (setq x (cdr x)))))) (defun listarray (x) (when (symbolp x) (setq x (get x 'array))) (if (eql (array-rank x) 1) (coerce x 'list) (coerce (make-array (apply '* (array-dimensions x)) :displaced-to x :element-type (array-element-type x)) 'list))) (defmacro check-arg (place pred &rest res) (when (atom pred) (setq pred (list pred place))) `(assert ,pred (,place) ,@res)) (defmacro deff (fun val) `(setf (symbol-function ',fun) ,val)) (defmacro xcons (x y) (cond ((atom x) `(cons ,y,x)) (t (let ((g (gensym))) `(let ((,g ,x)) (cons ,y ,g)))))) (defun make-equal-hash-table (not-dim1) (let ((table (make-hash-table :test 'equal))) (or not-dim1 (setf (gethash 'dim1 table) t)) table)) ;;range of atan should be [0,2*pi] (defun atan (y x) (let ((tem (cl:atan y x))) (if (>= tem 0) tem (+ tem (* 2 pi))))) ;;range of atan2 should be (-pi,pi] ;;CL manual says that's what lisp::atan is supposed to have. (deff atan2 #'cl:atan) ;;exp is shadowed to save trouble for other packages--its declared special (deff exp #'cl:exp) (setq *read-default-float-format* 'double-float) #+clisp (progn ;; This used to be enabled, but ;; http://clisp.cons.org/impnotes/num-dict.html seems to indicate ;; that the result of float, coerce, sqrt, etc., on a rational will ;; return a float of the specified type. But ANSI CL says we must ;; return a single-float. I (rtoy) am commenting this out for now. ;; (setq custom:*default-float-format* 'double-float) ;; We currently don't want any warnings about floating-point contagion. (setq custom::*warn-on-floating-point-contagion* nil) ;; We definitely want ANSI-style floating-point contagion. (setq custom:*floating-point-contagion-ansi* t) ;; Set custom:*floating-point-rational-contagion-ansi* so that ;; contagion is done as per the ANSI CL standard. Has an effect only ;; in those few cases when the mathematical result is exact although ;; one of the arguments is a floating-point number, such as (* 0 ;; 1.618), (/ 0 1.618), (atan 0 1.0), (expt 2.0 0) (setq custom:*floating-point-rational-contagion-ansi* t)) (defmacro float (x &optional (y 1d0)) `(cl:float ,x ,y))