comparison lisp/calc/calc-ext.el @ 84886:9e97aa608e01

(calc-init-extensions, calc-reset): Use `mapc' rather than `mapcar'.
author Juanma Barranquero <lekktu@gmail.com>
date Wed, 26 Sep 2007 00:05:27 +0000
parents 01eedbaaac05
children 29e75576e47f bdb3fe0ba9fa
comparison
equal deleted inserted replaced
84885:69c173eabff4 84886:9e97aa608e01
616 (define-key calc-mode-map "Z=" 'calc-kbd-report) 616 (define-key calc-mode-map "Z=" 'calc-kbd-report)
617 (define-key calc-mode-map "Z#" 'calc-kbd-query) 617 (define-key calc-mode-map "Z#" 'calc-kbd-query)
618 618
619 (calc-init-prefixes) 619 (calc-init-prefixes)
620 620
621 (mapcar (function 621 (mapc (function
622 (lambda (x) 622 (lambda (x)
623 (define-key calc-mode-map (format "c%c" x) 'calc-clean-num) 623 (define-key calc-mode-map (format "c%c" x) 'calc-clean-num)
624 (define-key calc-mode-map (format "j%c" x) 'calc-select-part) 624 (define-key calc-mode-map (format "j%c" x) 'calc-select-part)
625 (define-key calc-mode-map (format "r%c" x) 'calc-recall-quick) 625 (define-key calc-mode-map (format "r%c" x) 'calc-recall-quick)
626 (define-key calc-mode-map (format "s%c" x) 'calc-store-quick) 626 (define-key calc-mode-map (format "s%c" x) 'calc-store-quick)
627 (define-key calc-mode-map (format "t%c" x) 'calc-store-into-quick) 627 (define-key calc-mode-map (format "t%c" x) 'calc-store-into-quick)
628 (define-key calc-mode-map (format "u%c" x) 'calc-quick-units))) 628 (define-key calc-mode-map (format "u%c" x) 'calc-quick-units)))
629 "0123456789") 629 "0123456789")
630 630
631 (let ((i ?A)) 631 (let ((i ?A))
632 (while (<= i ?z) 632 (while (<= i ?z)
633 (if (eq (car-safe (aref (nth 1 calc-mode-map) i)) 'keymap) 633 (if (eq (car-safe (aref (nth 1 calc-mode-map) i)) 'keymap)
634 (aset (nth 1 calc-mode-map) i 634 (aset (nth 1 calc-mode-map) i
635 (cons 'keymap (cons (cons ?\e (aref (nth 1 calc-mode-map) i)) 635 (cons 'keymap (cons (cons ?\e (aref (nth 1 calc-mode-map) i))
636 (cdr (aref (nth 1 calc-mode-map) i)))))) 636 (cdr (aref (nth 1 calc-mode-map) i))))))
637 (setq i (1+ i)))) 637 (setq i (1+ i))))
638 638
639 (setq calc-alg-map (copy-keymap calc-mode-map) 639 (setq calc-alg-map (copy-keymap calc-mode-map)
640 calc-alg-esc-map (copy-keymap esc-map)) 640 calc-alg-esc-map (copy-keymap esc-map))
641 (let ((i 32)) 641 (let ((i 32))
642 (while (< i 127) 642 (while (< i 127)
643 (or (memq i '(?' ?` ?= ??)) 643 (or (memq i '(?' ?` ?= ??))
649 (define-key calc-alg-map "\e\t" 'calc-roll-up) 649 (define-key calc-alg-map "\e\t" 'calc-roll-up)
650 (define-key calc-alg-map "\e\C-m" 'calc-last-args-stub) 650 (define-key calc-alg-map "\e\C-m" 'calc-last-args-stub)
651 (define-key calc-alg-map "\e\177" 'calc-pop-above) 651 (define-key calc-alg-map "\e\177" 'calc-pop-above)
652 652
653 ;;;; (Autoloads here) 653 ;;;; (Autoloads here)
654 (mapcar (function (lambda (x) 654 (mapc (function (lambda (x)
655 (mapcar (function (lambda (func) 655 (mapcar (function (lambda (func)
656 (autoload func (car x)))) (cdr x)))) 656 (autoload func (car x)))) (cdr x))))
657 '( 657 '(
658 658
659 ("calc-alg" calc-has-rules math-defsimplify 659 ("calc-alg" calc-has-rules math-defsimplify
1019 ("calc-math" calc-arccos calc-arccosh calc-arcsin calc-arcsinh 1019 ("calc-math" calc-arccos calc-arccosh calc-arcsin calc-arcsinh
1020 calc-arctan calc-arctan2 calc-arctanh calc-conj calc-cos calc-cosh 1020 calc-arctan calc-arctan2 calc-arctanh calc-conj calc-cos calc-cosh
1021 calc-cot calc-coth calc-csc calc-csch 1021 calc-cot calc-coth calc-csc calc-csch
1022 calc-degrees-mode calc-exp calc-expm1 calc-hypot calc-ilog 1022 calc-degrees-mode calc-exp calc-expm1 calc-hypot calc-ilog
1023 calc-imaginary calc-isqrt calc-ln calc-lnp1 calc-log calc-log10 1023 calc-imaginary calc-isqrt calc-ln calc-lnp1 calc-log calc-log10
1024 calc-pi calc-radians-mode calc-sec calc-sech 1024 calc-pi calc-radians-mode calc-sec calc-sech
1025 calc-sin calc-sincos calc-sinh calc-sqrt 1025 calc-sin calc-sincos calc-sinh calc-sqrt
1026 calc-tan calc-tanh calc-to-degrees calc-to-radians) 1026 calc-tan calc-tanh calc-to-degrees calc-to-radians)
1027 1027
1028 ("calc-mode" calc-alg-simplify-mode calc-algebraic-mode 1028 ("calc-mode" calc-alg-simplify-mode calc-algebraic-mode
1029 calc-always-load-extensions calc-auto-recompute calc-auto-why 1029 calc-always-load-extensions calc-auto-recompute calc-auto-why
1275 (setq calc-stack nil)) 1275 (setq calc-stack nil))
1276 (setq calc-undo-list nil 1276 (setq calc-undo-list nil
1277 calc-redo-list nil) 1277 calc-redo-list nil)
1278 (let (calc-stack calc-user-parse-tables calc-standard-date-formats 1278 (let (calc-stack calc-user-parse-tables calc-standard-date-formats
1279 calc-invocation-macro) 1279 calc-invocation-macro)
1280 (mapcar (function (lambda (v) (set v nil))) calc-local-var-list) 1280 (mapc (function (lambda (v) (set v nil))) calc-local-var-list)
1281 (if (and arg (<= arg 0)) 1281 (if (and arg (<= arg 0))
1282 (calc-mode-var-list-restore-default-values) 1282 (calc-mode-var-list-restore-default-values)
1283 (calc-mode-var-list-restore-saved-values))) 1283 (calc-mode-var-list-restore-saved-values)))
1284 (calc-set-language nil nil t) 1284 (calc-set-language nil nil t)
1285 (calc-mode) 1285 (calc-mode)
1355 (eq major-mode 'calc-keypad-mode) 1355 (eq major-mode 'calc-keypad-mode)
1356 (eq major-mode 'calc-trail-mode)) 1356 (eq major-mode 'calc-trail-mode))
1357 (with-current-buffer calc-main-buffer 1357 (with-current-buffer calc-main-buffer
1358 calc-hyperbolic-flag) 1358 calc-hyperbolic-flag)
1359 calc-hyperbolic-flag)) 1359 calc-hyperbolic-flag))
1360 (msg (if hyp-flag 1360 (msg (if hyp-flag
1361 "Inverse Hyperbolic..." 1361 "Inverse Hyperbolic..."
1362 "Inverse..."))) 1362 "Inverse...")))
1363 (calc-fancy-prefix 'calc-inverse-flag msg n))) 1363 (calc-fancy-prefix 'calc-inverse-flag msg n)))
1364 1364
1365 (defconst calc-fancy-prefix-map 1365 (defconst calc-fancy-prefix-map
1436 (eq major-mode 'calc-keypad-mode) 1436 (eq major-mode 'calc-keypad-mode)
1437 (eq major-mode 'calc-trail-mode)) 1437 (eq major-mode 'calc-trail-mode))
1438 (with-current-buffer calc-main-buffer 1438 (with-current-buffer calc-main-buffer
1439 calc-inverse-flag) 1439 calc-inverse-flag)
1440 calc-inverse-flag)) 1440 calc-inverse-flag))
1441 (msg (if inv-flag 1441 (msg (if inv-flag
1442 "Inverse Hyperbolic..." 1442 "Inverse Hyperbolic..."
1443 "Hyperbolic..."))) 1443 "Hyperbolic...")))
1444 (calc-fancy-prefix 'calc-hyperbolic-flag msg n))) 1444 (calc-fancy-prefix 'calc-hyperbolic-flag msg n)))
1445 1445
1446 (defun calc-hyperbolic-func () 1446 (defun calc-hyperbolic-func ()
1847 (char-to-string (upcase key))))) 1847 (char-to-string (upcase key)))))
1848 (if (= (length calc-z-prefix-buf) 0) 1848 (if (= (length calc-z-prefix-buf) 0)
1849 (setq calc-z-prefix-buf (concat (if (= flags 1) "SHIFT + " "") 1849 (setq calc-z-prefix-buf (concat (if (= flags 1) "SHIFT + " "")
1850 desc)) 1850 desc))
1851 (if (> (+ (length calc-z-prefix-buf) (length desc)) 58) 1851 (if (> (+ (length calc-z-prefix-buf) (length desc)) 58)
1852 (setq calc-z-prefix-msgs 1852 (setq calc-z-prefix-msgs
1853 (cons calc-z-prefix-buf calc-z-prefix-msgs) 1853 (cons calc-z-prefix-buf calc-z-prefix-msgs)
1854 calc-z-prefix-buf (concat (if (= flags 1) "SHIFT + " "") 1854 calc-z-prefix-buf (concat (if (= flags 1) "SHIFT + " "")
1855 desc)) 1855 desc))
1856 (setq calc-z-prefix-buf (concat calc-z-prefix-buf ", " desc)))))) 1856 (setq calc-z-prefix-buf (concat calc-z-prefix-buf ", " desc))))))
1857 (calc-user-function-list (cdr map) flags)))) 1857 (calc-user-function-list (cdr map) flags))))
1877 (cache-val (intern (concat (symbol-name name) "-cache"))) 1877 (cache-val (intern (concat (symbol-name name) "-cache")))
1878 (last-prec (intern (concat (symbol-name name) "-last-prec"))) 1878 (last-prec (intern (concat (symbol-name name) "-last-prec")))
1879 (last-val (intern (concat (symbol-name name) "-last")))) 1879 (last-val (intern (concat (symbol-name name) "-last"))))
1880 (list 'progn 1880 (list 'progn
1881 ; (list 'defvar cache-prec (if init (math-numdigs (nth 1 init)) -100)) 1881 ; (list 'defvar cache-prec (if init (math-numdigs (nth 1 init)) -100))
1882 (list 'defvar cache-prec 1882 (list 'defvar cache-prec
1883 `(cond 1883 `(cond
1884 ((consp ,init) (math-numdigs (nth 1 ,init))) 1884 ((consp ,init) (math-numdigs (nth 1 ,init)))
1885 (,init 1885 (,init
1886 (nth 1 (math-numdigs (eval ,init)))) 1886 (nth 1 (math-numdigs (eval ,init))))
1887 (t 1887 (t
1888 -100))) 1888 -100)))
1889 (list 'defvar cache-val 1889 (list 'defvar cache-val
1890 `(cond 1890 `(cond
1891 ((consp ,init) ,init) 1891 ((consp ,init) ,init)
1892 (,init (eval ,init)) 1892 (,init (eval ,init))
1893 (t ,init))) 1893 (t ,init)))
1894 (list 'defvar last-prec -100) 1894 (list 'defvar last-prec -100)
1961 (math-sqrt-float (math-two-pi))) 1961 (math-sqrt-float (math-two-pi)))
1962 1962
1963 (defconst math-approx-sqrt-e 1963 (defconst math-approx-sqrt-e
1964 (math-read-number-simple "1.648721270700128146849") 1964 (math-read-number-simple "1.648721270700128146849")
1965 "An approximation for sqrt(3).") 1965 "An approximation for sqrt(3).")
1966 1966
1967 (math-defcache math-sqrt-e math-approx-sqrt-e 1967 (math-defcache math-sqrt-e math-approx-sqrt-e
1968 (math-add-float '(float 1 0) (math-exp-minus-1-raw '(float 5 -1)))) 1968 (math-add-float '(float 1 0) (math-exp-minus-1-raw '(float 5 -1))))
1969 1969
1970 (math-defcache math-e nil 1970 (math-defcache math-e nil
1971 (math-pow (math-sqrt-e) 2)) 1971 (math-pow (math-sqrt-e) 2))
1973 (math-defcache math-phi nil 1973 (math-defcache math-phi nil
1974 (math-mul-float (math-add-float (math-sqrt-raw '(float 5 0)) '(float 1 0)) 1974 (math-mul-float (math-add-float (math-sqrt-raw '(float 5 0)) '(float 1 0))
1975 '(float 5 -1))) 1975 '(float 5 -1)))
1976 1976
1977 (defconst math-approx-gamma-const 1977 (defconst math-approx-gamma-const
1978 (math-read-number-simple 1978 (math-read-number-simple
1979 "0.5772156649015328606065120900824024310421593359399235988057672348848677267776646709369470632917467495") 1979 "0.5772156649015328606065120900824024310421593359399235988057672348848677267776646709369470632917467495")
1980 "An approximation for gamma.") 1980 "An approximation for gamma.")
1981 1981
1982 (math-defcache math-gamma-const nil 1982 (math-defcache math-gamma-const nil
1983 math-approx-gamma-const) 1983 math-approx-gamma-const)
1984 1984
1985 (defun math-half-circle (symb) 1985 (defun math-half-circle (symb)
1986 (if (eq calc-angle-mode 'rad) 1986 (if (eq calc-angle-mode 'rad)
1987 (if symb 1987 (if symb
2146 2146
2147 (defun math-ident-row-p (row n &optional a) 2147 (defun math-ident-row-p (row n &optional a)
2148 (unless a 2148 (unless a
2149 (setq a 1)) 2149 (setq a 1))
2150 (and 2150 (and
2151 (not (memq nil (mapcar 2151 (not (memq nil (mapcar
2152 (lambda (x) (eq x 0)) 2152 (lambda (x) (eq x 0))
2153 (nthcdr (1+ n) row)))) 2153 (nthcdr (1+ n) row))))
2154 (not (memq nil (mapcar 2154 (not (memq nil (mapcar
2155 (lambda (x) (eq x 0)) 2155 (lambda (x) (eq x 0))
2156 (butlast 2156 (butlast
2157 (cdr row) 2157 (cdr row)
2158 (- (length row) n))))) 2158 (- (length row) n)))))
2159 (eq (elt row n) a))) 2159 (eq (elt row n) a)))
2160 2160
2161 ;;; True if A is any scalar data object. [P x] 2161 ;;; True if A is any scalar data object. [P x]
2216 "Get the mean value of the error form X. 2216 "Get the mean value of the error form X.
2217 If X is not an error form, return X." 2217 If X is not an error form, return X."
2218 (if (eq (car-safe x) 'sdev) 2218 (if (eq (car-safe x) 'sdev)
2219 (nth 1 x) 2219 (nth 1 x)
2220 x)) 2220 x))
2221 2221
2222 (defun math-get-sdev (x &optional one) 2222 (defun math-get-sdev (x &optional one)
2223 "Get the standard deviation of the error form X. 2223 "Get the standard deviation of the error form X.
2224 If X is not an error form, return 1." 2224 If X is not an error form, return 1."
2225 (if (eq (car-safe x) 'sdev) 2225 (if (eq (car-safe x) 'sdev)
2226 (nth 2 x) 2226 (nth 2 x)
2329 math-simplify-only (car-safe (cdr-safe math-normalize-a))) 2329 math-simplify-only (car-safe (cdr-safe math-normalize-a)))
2330 nil) 2330 nil)
2331 (and (symbolp (car math-normalize-a)) 2331 (and (symbolp (car math-normalize-a))
2332 (or (eq calc-simplify-mode 'none) 2332 (or (eq calc-simplify-mode 'none)
2333 (and (eq calc-simplify-mode 'num) 2333 (and (eq calc-simplify-mode 'num)
2334 (let ((aptr (setq math-normalize-a 2334 (let ((aptr (setq math-normalize-a
2335 (cons 2335 (cons
2336 (car math-normalize-a) 2336 (car math-normalize-a)
2337 (mapcar 'math-normalize 2337 (mapcar 'math-normalize
2338 (cdr math-normalize-a)))))) 2338 (cdr math-normalize-a))))))
2339 (while (and aptr (math-constp (car aptr))) 2339 (while (and aptr (math-constp (car aptr)))
2340 (setq aptr (cdr aptr))) 2340 (setq aptr (cdr aptr)))
2341 aptr))) 2341 aptr)))
2342 (cons (car math-normalize-a) 2342 (cons (car math-normalize-a)
2343 (mapcar 'math-normalize (cdr math-normalize-a)))))) 2343 (mapcar 'math-normalize (cdr math-normalize-a))))))
2344 2344
2345 2345
2346 ;;; Normalize a bignum digit list by trimming high-end zeros. [L l] 2346 ;;; Normalize a bignum digit list by trimming high-end zeros. [L l]
2347 (defun math-norm-bignum (a) 2347 (defun math-norm-bignum (a)
2718 (while (not mmt-done) 2718 (while (not mmt-done)
2719 (while (and (/= math-mt-many 0) 2719 (while (and (/= math-mt-many 0)
2720 (setq mmt-nextval (funcall math-mt-func mmt-expr)) 2720 (setq mmt-nextval (funcall math-mt-func mmt-expr))
2721 (not (equal mmt-expr mmt-nextval))) 2721 (not (equal mmt-expr mmt-nextval)))
2722 (setq mmt-expr mmt-nextval 2722 (setq mmt-expr mmt-nextval
2723 math-mt-many (if (> math-mt-many 0) 2723 math-mt-many (if (> math-mt-many 0)
2724 (1- math-mt-many) 2724 (1- math-mt-many)
2725 (1+ math-mt-many)))) 2725 (1+ math-mt-many))))
2726 (if (or (Math-primp mmt-expr) 2726 (if (or (Math-primp mmt-expr)
2727 (<= math-mt-many 0)) 2727 (<= math-mt-many 0))
2728 (setq mmt-done t) 2728 (setq mmt-done t)
2729 (setq mmt-nextval (cons (car mmt-expr) 2729 (setq mmt-nextval (cons (car mmt-expr)
3044 (width 0) 3044 (width 0)
3045 (math-read-big-err-msg nil) 3045 (math-read-big-err-msg nil)
3046 math-read-big-baseline math-read-big-h2 3046 math-read-big-baseline math-read-big-h2
3047 new-pos p) 3047 new-pos p)
3048 (while (setq new-pos (string-match "\n" str pos)) 3048 (while (setq new-pos (string-match "\n" str pos))
3049 (setq math-read-big-lines 3049 (setq math-read-big-lines
3050 (cons (substring str pos new-pos) math-read-big-lines) 3050 (cons (substring str pos new-pos) math-read-big-lines)
3051 pos (1+ new-pos))) 3051 pos (1+ new-pos)))
3052 (setq math-read-big-lines 3052 (setq math-read-big-lines
3053 (nreverse (cons (substring str pos) math-read-big-lines)) 3053 (nreverse (cons (substring str pos) math-read-big-lines))
3054 p math-read-big-lines) 3054 p math-read-big-lines)
3055 (while p 3055 (while p
3056 (setq width (max width (length (car p))) 3056 (setq width (max width (length (car p)))
3057 p (cdr p))) 3057 p (cdr p)))