emacs/lisp/calc/calc-stuff.el

294 lines
9.4 KiB
EmacsLisp
Raw Normal View History

* lisp/calc/: Use lexical scoping in all the files Includes the following pervasive changes: - Move some defvars earlier in the file so they cover earlier let-bindings - Change dynamically scoped `calc-FOO` or `math-FOO` function arguments to just FOO and then let-bind the `calc-FOO` or `math-FOO` variable explicitly in the body of the function. In some cases, the beginning of the function was changed to refer to FOO so as to delay the binding to a nearby `let` when I could ensure that it did not make a difference. - Add an underscore in front of unused vars or comment them out altogether. - Replace unused `err` arg to `condition-case` with nil. Plus the additional itemized changes below. * lisp/calc/calc-map.el (calcFunc-reducer): * lisp/calc/calc-arith.el (math-setup-declarations): * lisp/calc/calc-help.el (calc-full-help, calc-help-index-entries) (calc-full-help): Use `ignore-errors`. * lisp/calc/calc-embed.el (calc-embedded-modes-change): Declare `the-language` and `the-display-just` as dynamically scoped. * lisp/calc/calc-forms.el (math-setup-year-holidays): Use `dolist`. * lisp/calc/calc-graph.el (calc-graph-set-styles): Use `symbol-value` rather than `eval.` (calc-graph-delete-temps, calc-graph-set-styles): Use ignore-errors. * lisp/calc/calc-macs.el (calc-with-trail-buffer): Add artificial use of `save-buf` to silence compiler warnings in all the cases where `body` doesn't make use of it. * lisp/calc/calc-math.el (math-largest-emacs-expt) (math-smallest-emacs-expt, math-use-emacs-fn): Use ignore-errors. * lisp/calc/calc-mode.el (calc-total-algebraic-mode): Remove "P" from interactive spec since it's not used anyway. * lisp/calc/calc-rewr.el (calc-match): Simplify. * lisp/calc/calc.el (calc-buffer): Give it a global nil value, so it's automatically declared dynbound in any file that requires `calc`. (calcDigit-nondigit): Adjust accordingly. * lisp/calc/calcalg2.el (calcFunc-table): Declare `var-dummy` as dynbound. (math-scan-for-limits): Comment out dead code. * lisp/calc/calcalg3.el (math-general-fit): Declare `var-YVAL` and `var-YVALX` as dynbound.
2020-10-10 16:00:51 -04:00
;;; calc-stuff.el --- miscellaneous functions for Calc -*- lexical-binding:t -*-
;; Copyright (C) 1990-1993, 2001-2025 Free Software Foundation, Inc.
;; Author: David Gillespie <daveg@synaptics.com>
2001-11-06 18:59:06 +00:00
;; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
2001-11-06 18:59:06 +00:00
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
2001-11-06 18:59:06 +00:00
;;; Commentary:
2001-11-06 18:59:06 +00:00
;;; Code:
2001-11-06 18:59:06 +00:00
;; This file is autoloaded from calc-ext.el.
(require 'calc-ext)
2001-11-06 18:59:06 +00:00
(require 'calc-macs)
(defun calc-num-prefix (n)
"Use the number at the top of stack as the numeric prefix for the next command.
With a prefix, push that prefix as a number onto the stack."
(interactive "P")
(calc-wrapper
(if n
(calc-enter-result 0 "" (prefix-numeric-value n))
(let ((num (calc-top 1)))
(if (math-messy-integerp num)
(setq num (math-trunc num)))
(or (integerp num)
(error "Argument must be a small integer"))
(calc-pop-stack 1)
(setq prefix-arg num)
(message "%d-" num))))) ; a (lame) simulation of the real thing...
2001-11-06 18:59:06 +00:00
(defun calc-more-recursion-depth (n)
(interactive "P")
(calc-wrapper
(if (calc-is-inverse)
(calc-less-recursion-depth n)
(let ((n (if n (prefix-numeric-value n) 2)))
(if (> n 1)
Abolish max-specpdl-size (bug#57911) The max-lisp-eval-depth limit is sufficient to prevent unbounded stack growth including the specbind stack; simplify matters for the user by not having them to worry about two different limits. This change turns max-specpdl-size into a harmless variable with no effects, to keep existing code happy. * lisp/subr.el (max-specpdl-size): Define as an ordinary (but obsolete) dynamic variable. * admin/grammars/Makefile.in: * doc/lispintro/emacs-lisp-intro.texi (Loops & Recursion): * doc/lispref/control.texi (Cleanups): * doc/lispref/edebug.texi (Checking Whether to Stop): * doc/lispref/eval.texi (Eval): * doc/lispref/variables.texi (Local Variables): * doc/misc/calc.texi (Recursion Depth): Update documentation. * etc/NEWS: Announce. * src/eval.c (FletX): Use safe iteration to guard against circular bindings list. (syms_of_eval): Remove old max-specpdl-size definition. (init_eval_once, restore_stack_limits, call_debugger) (signal_or_quit, grow_specpdl_allocation): * leim/Makefile.in: * lisp/Makefile.in: * lisp/calc/calc-stuff.el (calc-more-recursion-depth) (calc-less-recursion-depth): * lisp/calc/calc.el (calc-do): * lisp/cedet/semantic/ede-grammar.el (ede-proj-makefile-insert-rules): * lisp/cedet/semantic/grammar.el (semantic-grammar-batch-build-one-package): * lisp/cus-start.el (standard): * lisp/emacs-lisp/comp.el (comp--native-compile): * lisp/emacs-lisp/edebug.el (edebug-max-depth): (edebug-read-and-maybe-wrap-form, edebug-default-enter): * lisp/emacs-lisp/regexp-opt.el (regexp-opt): * lisp/eshell/esh-mode.el (eshell-mode): * lisp/loadup.el (max-specpdl-size): * lisp/mh-e/mh-e.el (mh-invisible-headers): * lisp/net/shr.el (shr-insert-document, shr-descend): * lisp/play/hanoi.el (hanoi-internal): * lisp/progmodes/cperl-mode.el: * src/fileio.c (Fdo_auto_save): Remove references to and modifications of max-specpdl-size.
2022-09-19 10:55:09 +02:00
(setq max-lisp-eval-depth (* max-lisp-eval-depth n))))
(message "max-lisp-eval-depth is now %d" max-lisp-eval-depth))))
2001-11-06 18:59:06 +00:00
(defun calc-less-recursion-depth (n)
(interactive "P")
(let ((n (if n (prefix-numeric-value n) 2)))
(if (> n 1)
Abolish max-specpdl-size (bug#57911) The max-lisp-eval-depth limit is sufficient to prevent unbounded stack growth including the specbind stack; simplify matters for the user by not having them to worry about two different limits. This change turns max-specpdl-size into a harmless variable with no effects, to keep existing code happy. * lisp/subr.el (max-specpdl-size): Define as an ordinary (but obsolete) dynamic variable. * admin/grammars/Makefile.in: * doc/lispintro/emacs-lisp-intro.texi (Loops & Recursion): * doc/lispref/control.texi (Cleanups): * doc/lispref/edebug.texi (Checking Whether to Stop): * doc/lispref/eval.texi (Eval): * doc/lispref/variables.texi (Local Variables): * doc/misc/calc.texi (Recursion Depth): Update documentation. * etc/NEWS: Announce. * src/eval.c (FletX): Use safe iteration to guard against circular bindings list. (syms_of_eval): Remove old max-specpdl-size definition. (init_eval_once, restore_stack_limits, call_debugger) (signal_or_quit, grow_specpdl_allocation): * leim/Makefile.in: * lisp/Makefile.in: * lisp/calc/calc-stuff.el (calc-more-recursion-depth) (calc-less-recursion-depth): * lisp/calc/calc.el (calc-do): * lisp/cedet/semantic/ede-grammar.el (ede-proj-makefile-insert-rules): * lisp/cedet/semantic/grammar.el (semantic-grammar-batch-build-one-package): * lisp/cus-start.el (standard): * lisp/emacs-lisp/comp.el (comp--native-compile): * lisp/emacs-lisp/edebug.el (edebug-max-depth): (edebug-read-and-maybe-wrap-form, edebug-default-enter): * lisp/emacs-lisp/regexp-opt.el (regexp-opt): * lisp/eshell/esh-mode.el (eshell-mode): * lisp/loadup.el (max-specpdl-size): * lisp/mh-e/mh-e.el (mh-invisible-headers): * lisp/net/shr.el (shr-insert-document, shr-descend): * lisp/play/hanoi.el (hanoi-internal): * lisp/progmodes/cperl-mode.el: * src/fileio.c (Fdo_auto_save): Remove references to and modifications of max-specpdl-size.
2022-09-19 10:55:09 +02:00
(setq max-lisp-eval-depth (max (/ max-lisp-eval-depth n) 200))))
(message "max-lisp-eval-depth is now %d" max-lisp-eval-depth))
2001-11-06 18:59:06 +00:00
(defvar calc-which-why nil)
(defvar calc-last-why-command nil)
2001-11-06 18:59:06 +00:00
(defun calc-explain-why (why &optional more)
(if (eq (car why) '*)
(setq why (cdr why)))
(let* ((pred (car why))
(arg (nth 1 why))
(msg (cond ((not pred) "Wrong type of argument")
((stringp pred) pred)
((eq pred 'integerp) "Integer expected")
((eq pred 'natnump)
(if (and arg (Math-objvecp arg) (not (Math-integerp arg)))
"Integer expected"
"Nonnegative integer expected"))
((eq pred 'posintp)
(if (and arg (Math-objvecp arg) (not (Math-integerp arg)))
"Integer expected"
"Positive integer expected"))
((eq pred 'fixnump)
(if (and arg (Math-integerp arg))
"Small integer expected"
"Integer expected"))
((eq pred 'fixnatnump)
(if (and arg (Math-natnump arg))
"Small integer expected"
(if (and arg (Math-objvecp arg)
(not (Math-integerp arg)))
"Integer expected"
"Nonnegative integer expected")))
((eq pred 'fixposintp)
(if (and arg (Math-integerp arg) (Math-posp arg))
"Small integer expected"
(if (and arg (Math-objvecp arg)
(not (Math-integerp arg)))
"Integer expected"
"Positive integer expected")))
((eq pred 'posp) "Positive number expected")
((eq pred 'negp) "Negative number expected")
((eq pred 'nonzerop) "Nonzero number expected")
((eq pred 'realp) "Real number expected")
((eq pred 'anglep) "Real number expected")
((eq pred 'hmsp) "HMS form expected")
((eq pred 'datep)
(if (and arg (Math-objectp arg)
(not (Math-realp arg)))
"Real number or date form expected"
"Date form expected"))
((eq pred 'numberp) "Number expected")
((eq pred 'scalarp) "Number expected")
((eq pred 'vectorp) "Vector or matrix expected")
((eq pred 'numvecp) "Number or vector expected")
((eq pred 'matrixp) "Matrix expected")
((eq pred 'square-matrixp)
(if (and arg (math-matrixp arg))
"Square matrix expected"
"Matrix expected"))
((eq pred 'objectp) "Number expected")
((eq pred 'constp) "Constant expected")
((eq pred 'range) "Argument out of range")
(t (format "%s expected" pred))))
(punc ": ")
(calc-can-abbrev-vectors t))
(while (setq why (cdr why))
(and (car why)
(setq msg (concat msg punc (if (stringp (car why))
(car why)
(math-format-flat-expr (car why) 0)))
punc ", ")))
(message "%s%s" msg (if more " [w=more]" ""))))
2001-11-06 18:59:06 +00:00
(defun calc-why ()
(interactive)
(if (not (eq this-command last-command))
(if (eq last-command calc-last-why-command)
(setq calc-which-why (cdr calc-why))
(setq calc-which-why calc-why)))
(if calc-which-why
(progn
(calc-explain-why (car calc-which-why) (cdr calc-which-why))
(setq calc-which-why (cdr calc-which-why)))
(if calc-why
(progn
(message "(No further explanations available)")
(setq calc-which-why calc-why))
(message "No explanations available"))))
2001-11-06 18:59:06 +00:00
;; The following caches are declared in other files, but are
;; reset here.
(defvar math-lud-cache) ; calc-mtx.el
(defvar math-log2-cache) ; calc-bin.el
(defvar math-radix-digits-cache) ; calc-bin.el
(defvar math-radix-float-cache-tag) ; calc-bin.el
(defvar math-random-cache) ; calc-comb.el
(defvar math-max-digits-cache) ; calc-bin.el
(defvar math-integral-cache) ; calcalg2.el
(defvar math-units-table) ; calc-units.el
2005-05-28 04:38:23 +00:00
(defvar math-decls-cache-tag) ; calc-arith.el
(defvar math-format-date-cache) ; calc-forms.el
(defvar math-holidays-cache-tag) ; calc-forms.el
2001-11-06 18:59:06 +00:00
(defun calc-flush-caches (&optional inhibit-msg)
(interactive "P")
2001-11-06 18:59:06 +00:00
(calc-wrapper
(setq math-lud-cache nil
math-log2-cache nil
math-radix-digits-cache nil
math-radix-float-cache-tag nil
math-random-cache nil
math-max-digits-cache nil
math-integral-cache nil
math-units-table nil
math-decls-cache-tag nil
math-eval-rules-cache-tag t
math-format-date-cache nil
math-holidays-cache-tag t)
Don't quote lambdas with 'function' in calc/*.el * lisp/calc/calc-aent.el (calc-do-quick-calc) (calc-do-calc-eval, math-build-parse-table): * lisp/calc/calc-alg.el (math-polynomial-base): * lisp/calc/calc-alg.el (math-is-poly-rec): * lisp/calc/calc-arith.el (calcFunc-scf): * lisp/calc/calc-arith.el (math-ceiling, math-round): * lisp/calc/calc-arith.el (math-trunc-fancy, math-floor-fancy): * lisp/calc/calc-ext.el (calc-init-extensions, calc-reset) (calc-refresh-top, calc-z-prefix-help, calc-binary-op-fancy) (calc-unary-op-fancy): * lisp/calc/calc-forms.el (math-make-mod): * lisp/calc/calc-frac.el (calcFunc-frac): * lisp/calc/calc-funcs.el (calcFunc-euler): * lisp/calc/calc-help.el (calc-full-help): * lisp/calc/calc-lang.el (c, pascal, fortran, tex, latex, eqn) (yacas, maxima, giac, math, maple): * lisp/calc/calc-macs.el (calc-wrapper, calc-slow-wrapper): * lisp/calc/calc-map.el (calc-get-operator, calcFunc-mapeqr) (calcFunc-reducea, calcFunc-rreducea, calcFunc-reduced) (calcFunc-rreduced, calcFunc-outer): * lisp/calc/calc-misc.el (another-calc, calc-do-handle-whys): * lisp/calc/calc-mode.el (calc-save-modes): * lisp/calc/calc-mtx.el (math-col-matrix, math-mul-mat-vec): * lisp/calc/calc-poly.el (math-sort-terms, math-poly-div-list) (math-mul-list, math-sort-poly-base-list) (math-partial-fractions): * lisp/calc/calc-prog.el (calc-user-define-formula): * lisp/calc/calc-rewr.el (math-rewrite, math-compile-patterns) (math-compile-rewrites, math-parse-schedule) (math-rwcomp-pattern): * lisp/calc/calc-store.el (calc-var-name-map, calc-let) (calc-permanent-variable, calc-insert-variables): * lisp/calc/calc-stuff.el (calc-flush-caches, calcFunc-pclean) (calcFunc-pfrac): * lisp/calc/calc-units.el (math-build-units-table) (math-decompose-units): * lisp/calc/calc-vec.el (calcFunc-mrow, math-mat-col) (calcFunc-mcol, math-mat-less-col, math-mimic-ident): * lisp/calc/calc-yank.el (calc-edit): * lisp/calc/calc.el (calc-mode-var-list-restore-default-values) (calc-mode-var-list-restore-saved-values, calc-mode, calc-quit): * lisp/calc/calccomp.el (math-compose-expr) (math-compose-matrix, math-vector-to-string): Don't quote lambdas with 'function'.
2020-11-17 02:51:30 +01:00
(mapc (lambda (x) (set x -100)) math-cache-list)
(unless inhibit-msg
(message "All internal calculator caches have been reset"))))
2001-11-06 18:59:06 +00:00
;;; Conversions.
(defun calc-clean (n)
(interactive "P")
(calc-slow-wrapper
(calc-with-default-simplification
(let ((func (if (calc-is-hyperbolic) 'calcFunc-clean 'calcFunc-pclean)))
(calc-enter-result 1 "cln"
(if n
(let ((n (prefix-numeric-value n)))
(list func
(calc-top-n 1)
(if (<= n 0)
(+ n calc-internal-prec)
n)))
(list func (calc-top-n 1))))))))
2001-11-06 18:59:06 +00:00
(defun calc-clean-num (num)
(interactive "P")
(calc-clean (- (if num
2003-02-04 13:24:35 +00:00
(prefix-numeric-value num)
(if (and (>= last-command-event ?0)
(<= last-command-event ?9))
(- last-command-event ?0)
(error "Number required"))))))
2001-11-06 18:59:06 +00:00
(defvar math-chopping-small nil)
2001-11-06 18:59:06 +00:00
(defun calcFunc-clean (a &optional prec) ; [X X S] [Public]
(if prec
(cond ((Math-messy-integerp prec)
(calcFunc-clean a (math-trunc prec)))
((or (not (integerp prec))
(< prec 3))
(calc-record-why "*Precision must be an integer 3 or above")
(list 'calcFunc-clean a prec))
((not (Math-objvecp a))
(list 'calcFunc-clean a prec))
(t (let ((calc-internal-prec prec)
(math-chopping-small t))
(calcFunc-clean (math-normalize a)))))
(cond ((eq (car-safe a) 'polar)
(let ((theta (math-mod (nth 2 a)
(if (eq calc-angle-mode 'rad)
(math-two-pi)
360))))
(math-neg
(math-neg
(math-normalize
(list 'polar
(calcFunc-clean (nth 1 a))
(calcFunc-clean theta)))))))
((memq (car-safe a) '(vec date hms))
(cons (car a) (mapcar 'calcFunc-clean (cdr a))))
((memq (car-safe a) '(cplx mod sdev intv))
(math-normalize (cons (car a) (mapcar 'calcFunc-clean (cdr a)))))
((eq (car-safe a) 'float)
(if math-chopping-small
(if (or (> (nth 2 a) (- calc-internal-prec))
(Math-lessp (- calc-internal-prec) (calcFunc-xpon a)))
(if (and (math-num-integerp a)
(math-lessp (calcFunc-xpon a) calc-internal-prec))
(math-trunc a)
a)
0)
a))
((Math-objectp a) a)
((math-infinitep a) a)
(t (list 'calcFunc-clean a)))))
2001-11-06 18:59:06 +00:00
(defun calcFunc-pclean (a &optional prec)
Don't quote lambdas with 'function' in calc/*.el * lisp/calc/calc-aent.el (calc-do-quick-calc) (calc-do-calc-eval, math-build-parse-table): * lisp/calc/calc-alg.el (math-polynomial-base): * lisp/calc/calc-alg.el (math-is-poly-rec): * lisp/calc/calc-arith.el (calcFunc-scf): * lisp/calc/calc-arith.el (math-ceiling, math-round): * lisp/calc/calc-arith.el (math-trunc-fancy, math-floor-fancy): * lisp/calc/calc-ext.el (calc-init-extensions, calc-reset) (calc-refresh-top, calc-z-prefix-help, calc-binary-op-fancy) (calc-unary-op-fancy): * lisp/calc/calc-forms.el (math-make-mod): * lisp/calc/calc-frac.el (calcFunc-frac): * lisp/calc/calc-funcs.el (calcFunc-euler): * lisp/calc/calc-help.el (calc-full-help): * lisp/calc/calc-lang.el (c, pascal, fortran, tex, latex, eqn) (yacas, maxima, giac, math, maple): * lisp/calc/calc-macs.el (calc-wrapper, calc-slow-wrapper): * lisp/calc/calc-map.el (calc-get-operator, calcFunc-mapeqr) (calcFunc-reducea, calcFunc-rreducea, calcFunc-reduced) (calcFunc-rreduced, calcFunc-outer): * lisp/calc/calc-misc.el (another-calc, calc-do-handle-whys): * lisp/calc/calc-mode.el (calc-save-modes): * lisp/calc/calc-mtx.el (math-col-matrix, math-mul-mat-vec): * lisp/calc/calc-poly.el (math-sort-terms, math-poly-div-list) (math-mul-list, math-sort-poly-base-list) (math-partial-fractions): * lisp/calc/calc-prog.el (calc-user-define-formula): * lisp/calc/calc-rewr.el (math-rewrite, math-compile-patterns) (math-compile-rewrites, math-parse-schedule) (math-rwcomp-pattern): * lisp/calc/calc-store.el (calc-var-name-map, calc-let) (calc-permanent-variable, calc-insert-variables): * lisp/calc/calc-stuff.el (calc-flush-caches, calcFunc-pclean) (calcFunc-pfrac): * lisp/calc/calc-units.el (math-build-units-table) (math-decompose-units): * lisp/calc/calc-vec.el (calcFunc-mrow, math-mat-col) (calcFunc-mcol, math-mat-less-col, math-mimic-ident): * lisp/calc/calc-yank.el (calc-edit): * lisp/calc/calc.el (calc-mode-var-list-restore-default-values) (calc-mode-var-list-restore-saved-values, calc-mode, calc-quit): * lisp/calc/calccomp.el (math-compose-expr) (math-compose-matrix, math-vector-to-string): Don't quote lambdas with 'function'.
2020-11-17 02:51:30 +01:00
(math-map-over-constants (lambda (x) (calcFunc-clean x prec))
a))
2001-11-06 18:59:06 +00:00
(defun calcFunc-pfloat (a)
(math-map-over-constants 'math-float a))
2001-11-06 18:59:06 +00:00
(defun calcFunc-pfrac (a &optional tol)
Don't quote lambdas with 'function' in calc/*.el * lisp/calc/calc-aent.el (calc-do-quick-calc) (calc-do-calc-eval, math-build-parse-table): * lisp/calc/calc-alg.el (math-polynomial-base): * lisp/calc/calc-alg.el (math-is-poly-rec): * lisp/calc/calc-arith.el (calcFunc-scf): * lisp/calc/calc-arith.el (math-ceiling, math-round): * lisp/calc/calc-arith.el (math-trunc-fancy, math-floor-fancy): * lisp/calc/calc-ext.el (calc-init-extensions, calc-reset) (calc-refresh-top, calc-z-prefix-help, calc-binary-op-fancy) (calc-unary-op-fancy): * lisp/calc/calc-forms.el (math-make-mod): * lisp/calc/calc-frac.el (calcFunc-frac): * lisp/calc/calc-funcs.el (calcFunc-euler): * lisp/calc/calc-help.el (calc-full-help): * lisp/calc/calc-lang.el (c, pascal, fortran, tex, latex, eqn) (yacas, maxima, giac, math, maple): * lisp/calc/calc-macs.el (calc-wrapper, calc-slow-wrapper): * lisp/calc/calc-map.el (calc-get-operator, calcFunc-mapeqr) (calcFunc-reducea, calcFunc-rreducea, calcFunc-reduced) (calcFunc-rreduced, calcFunc-outer): * lisp/calc/calc-misc.el (another-calc, calc-do-handle-whys): * lisp/calc/calc-mode.el (calc-save-modes): * lisp/calc/calc-mtx.el (math-col-matrix, math-mul-mat-vec): * lisp/calc/calc-poly.el (math-sort-terms, math-poly-div-list) (math-mul-list, math-sort-poly-base-list) (math-partial-fractions): * lisp/calc/calc-prog.el (calc-user-define-formula): * lisp/calc/calc-rewr.el (math-rewrite, math-compile-patterns) (math-compile-rewrites, math-parse-schedule) (math-rwcomp-pattern): * lisp/calc/calc-store.el (calc-var-name-map, calc-let) (calc-permanent-variable, calc-insert-variables): * lisp/calc/calc-stuff.el (calc-flush-caches, calcFunc-pclean) (calcFunc-pfrac): * lisp/calc/calc-units.el (math-build-units-table) (math-decompose-units): * lisp/calc/calc-vec.el (calcFunc-mrow, math-mat-col) (calcFunc-mcol, math-mat-less-col, math-mimic-ident): * lisp/calc/calc-yank.el (calc-edit): * lisp/calc/calc.el (calc-mode-var-list-restore-default-values) (calc-mode-var-list-restore-saved-values, calc-mode, calc-quit): * lisp/calc/calccomp.el (math-compose-expr) (math-compose-matrix, math-vector-to-string): Don't quote lambdas with 'function'.
2020-11-17 02:51:30 +01:00
(math-map-over-constants (lambda (x) (calcFunc-frac x tol))
a))
2001-11-06 18:59:06 +00:00
;; The variable math-moc-func is local to math-map-over-constants,
;; but is used by math-map-over-constants-rec, which is called by
;; math-map-over-constants.
(defvar math-moc-func)
* lisp/calc/: Use lexical scoping in all the files Includes the following pervasive changes: - Move some defvars earlier in the file so they cover earlier let-bindings - Change dynamically scoped `calc-FOO` or `math-FOO` function arguments to just FOO and then let-bind the `calc-FOO` or `math-FOO` variable explicitly in the body of the function. In some cases, the beginning of the function was changed to refer to FOO so as to delay the binding to a nearby `let` when I could ensure that it did not make a difference. - Add an underscore in front of unused vars or comment them out altogether. - Replace unused `err` arg to `condition-case` with nil. Plus the additional itemized changes below. * lisp/calc/calc-map.el (calcFunc-reducer): * lisp/calc/calc-arith.el (math-setup-declarations): * lisp/calc/calc-help.el (calc-full-help, calc-help-index-entries) (calc-full-help): Use `ignore-errors`. * lisp/calc/calc-embed.el (calc-embedded-modes-change): Declare `the-language` and `the-display-just` as dynamically scoped. * lisp/calc/calc-forms.el (math-setup-year-holidays): Use `dolist`. * lisp/calc/calc-graph.el (calc-graph-set-styles): Use `symbol-value` rather than `eval.` (calc-graph-delete-temps, calc-graph-set-styles): Use ignore-errors. * lisp/calc/calc-macs.el (calc-with-trail-buffer): Add artificial use of `save-buf` to silence compiler warnings in all the cases where `body` doesn't make use of it. * lisp/calc/calc-math.el (math-largest-emacs-expt) (math-smallest-emacs-expt, math-use-emacs-fn): Use ignore-errors. * lisp/calc/calc-mode.el (calc-total-algebraic-mode): Remove "P" from interactive spec since it's not used anyway. * lisp/calc/calc-rewr.el (calc-match): Simplify. * lisp/calc/calc.el (calc-buffer): Give it a global nil value, so it's automatically declared dynbound in any file that requires `calc`. (calcDigit-nondigit): Adjust accordingly. * lisp/calc/calcalg2.el (calcFunc-table): Declare `var-dummy` as dynbound. (math-scan-for-limits): Comment out dead code. * lisp/calc/calcalg3.el (math-general-fit): Declare `var-YVAL` and `var-YVALX` as dynbound.
2020-10-10 16:00:51 -04:00
(defun math-map-over-constants (moc-func expr)
(let ((math-moc-func moc-func))
(math-map-over-constants-rec expr)))
2001-11-06 18:59:06 +00:00
(defun math-map-over-constants-rec (expr)
(cond ((or (Math-primp expr)
(memq (car expr) '(intv sdev)))
(or (and (Math-objectp expr)
(funcall math-moc-func expr))
2001-11-06 18:59:06 +00:00
expr))
((and (memq (car expr) '(^ calcFunc-subscr))
(eq math-moc-func 'math-float)
2001-11-06 18:59:06 +00:00
(= (length expr) 3)
(Math-integerp (nth 2 expr)))
(list (car expr)
(math-map-over-constants-rec (nth 1 expr))
(nth 2 expr)))
(t (cons (car expr) (mapcar 'math-map-over-constants-rec (cdr expr))))))
2001-11-06 18:59:06 +00:00
(provide 'calc-stuff)
;;; calc-stuff.el ends here