Commit 11c9343f authored by Stefan Monnier's avatar Stefan Monnier

calc.el, calc-(ext|poly), calccomp: Use lexical-binding

* lisp/calc/calc-ext.el: Use lexical-binding, silence warnings.
(calc-init-extensions): Remove a few functions which can't be called
directly since they depend on dynamically scoped vars.
(calc-embedded-quiet): Declare.
(math-defcache): Use 'declare'.
(math-normalize-a): Remove declaration.
(math-normalize-nonstandard): Receive 'a' as arg instead.
(math-defintegral): Use 'declare'.
(math-exp-pos, math-exp-old-pos, math-exp-keep-spaces, math-rb-h2)
(math-read-big-baseline, math-read-big-h2, math-read-big-err-msg)
(math-exp-token, math-expr-data, math-exp-str): Declare.
(math-map-tree, math-read-expr): Avoid dynvars as formal arguments.

* lisp/calc/calc-poly.el: Use lexical-binding, silence warnings.
Turn some comments into docstrings.
(math-poly-div): Avoid dynvars as formal arguments.
(math-poly-base-top-expr): Move declaration before first use.
(calcFunc-factors, math-factor-expr, math-factor-expr-try)
(calcFunc-factor): Avoid dynvars as formal arguments.

* lisp/calc/calc.el: Use lexical-binding, silence warnings.
(math-normalize-a): Remove.
(math-normalize): Use lexical var 'a' instead.
(math-svo-c): Remove.
(math-stack-value-offset): Pass 'c' explicitly as arg to
math-stack-value-offset-fancy instead.

* lisp/calc/calccomp.el: Use lexical-binding, silence warnings.
(math-svo-c): Remove.
(math-stack-value-offset-fancy): Use new arg 'c' instead.
(math-comp-to-string-flat): Avoid dynvars as formal arguments.
parent 336681f3
Pipeline #103 failed with stage
in 20 minutes and 59 seconds
;;; calc-ext.el --- various extension functions for Calc
;;; calc-ext.el --- various extension functions for Calc -*- lexical-binding:t -*-
;; Copyright (C) 1990-1993, 2001-2018 Free Software Foundation, Inc.
......@@ -88,7 +88,7 @@
(defvar calc-alg-map)
(defvar calc-alg-esc-map)
;;; The following was made a function so that it could be byte-compiled.
;; The following was made a function so that it could be byte-compiled.
(defun calc-init-extensions ()
(define-key calc-mode-map ":" 'calc-fdiv)
......@@ -894,8 +894,8 @@ calcFunc-pcont calcFunc-pdeg calcFunc-pdiv calcFunc-pdivide
calcFunc-pdivrem calcFunc-pgcd calcFunc-plead calcFunc-pprim
calcFunc-prem math-accum-factors math-atomic-factorp
math-div-poly-const math-div-thru math-expand-power math-expand-term
math-factor-contains math-factor-expr math-factor-expr-part
math-factor-expr-try math-factor-finish math-factor-poly-coefs
math-factor-contains math-factor-expr
math-factor-finish
math-factor-protect math-mul-thru math-padded-polynomial
math-partial-fractions math-poly-degree math-poly-deriv-coefs
math-poly-gcd-frac-list math-poly-modulus-rec math-ratpoly-p
......@@ -984,8 +984,8 @@ calc-force-refresh calc-locate-cursor-element calc-show-edit-buffer)
))
(mapcar (function (lambda (x)
(mapcar (function (lambda (cmd)
(autoload cmd (car x) nil t))) (cdr x))))
(mapcar (function (lambda (cmd) (autoload cmd (car x) nil t)))
(cdr x))))
'(
("calc-alg" calc-alg-evaluate calc-apart calc-collect calc-expand
......@@ -1307,8 +1307,9 @@ calc-kill calc-kill-region calc-yank))))
(message "%s" (if msg
(concat group ": " msg ":"
(make-string
(- (apply 'max (mapcar 'length msgs))
(length msg)) 32)
(- (apply #'max (mapcar #'length msgs))
(length msg))
?\s)
" [MORE]"
(if key
(concat " " (char-to-string key)
......@@ -1334,6 +1335,8 @@ calc-kill calc-kill-region calc-yank))))
;;; General.
(defvar calc-embedded-quiet)
(defun calc-reset (arg)
(interactive "P")
(setq arg (if arg (prefix-numeric-value arg) nil))
......@@ -1398,7 +1401,7 @@ calc-kill calc-kill-region calc-yank))))
(defun calc-scroll-up (n)
(interactive "P")
(condition-case err
(condition-case nil
(scroll-up (or n (/ (window-height) 2)))
(error nil))
(if (pos-visible-in-window-p (max 1 (- (point-max) 2)))
......@@ -1657,7 +1660,7 @@ calc-kill calc-kill-region calc-yank))))
(let ((entries (calc-top-list n 1 'entry))
(calc-undo-list nil) (calc-redo-list nil))
(calc-pop-stack n 1 t)
(calc-push-list (mapcar 'car entries)
(calc-push-list (mapcar #'car entries)
1
(mapcar (function (lambda (x) (nth 2 x)))
entries)))))))
......@@ -1707,7 +1710,7 @@ calc-kill calc-kill-region calc-yank))))
(calc-pop-push-record-list 1 "eval"
(math-evaluate-expr (calc-top (- n)))
(- n))
(calc-pop-push-record-list n "eval" (mapcar 'math-evaluate-expr
(calc-pop-push-record-list n "eval" (mapcar #'math-evaluate-expr
(calc-top-list n)))))
(calc-handle-whys)))
......@@ -1928,7 +1931,7 @@ calc-kill calc-kill-region calc-yank))))
(calc-z-prefix-buf "")
(kmap (sort (copy-sequence (calc-user-key-map))
(function (lambda (x y) (< (car x) (car y))))))
(flags (apply 'logior
(flags (apply #'logior
(mapcar (function
(lambda (k)
(calc-user-function-classify (car k))))
......@@ -2003,12 +2006,13 @@ calc-kill calc-kill-region calc-yank))))
;;;; Caches.
(defmacro math-defcache (name init form)
(declare (indent 2) (debug (symbolp sexp form)))
(let ((cache-prec (intern (concat (symbol-name name) "-cache-prec")))
(cache-val (intern (concat (symbol-name name) "-cache")))
(last-prec (intern (concat (symbol-name name) "-last-prec")))
(last-val (intern (concat (symbol-name name) "-last"))))
`(progn
; (defvar ,cache-prec ,(if init (math-numdigs (nth 1 init)) -100))
;; (defvar ,cache-prec ,(if init (math-numdigs (nth 1 init)) -100))
(defvar ,cache-prec (cond
((consp ,init) (math-numdigs (nth 1 ,init)))
(,init
......@@ -2037,7 +2041,6 @@ calc-kill calc-kill-region calc-yank))))
,cache-val))
,last-prec calc-internal-prec))
,last-val))))
(put 'math-defcache 'lisp-indent-hook 2)
;;; Betcha didn't know that pi = 16 atan(1/5) - 4 atan(1/239). [F] [Public]
(defconst math-approx-pi
......@@ -2400,7 +2403,7 @@ If X is not an error form, return 1."
(list 'calcFunc-intv mask lo hi)
(math-make-intv mask lo hi))))
((eq (car a) 'vec)
(cons 'vec (mapcar 'math-normalize (cdr a))))
(cons 'vec (mapcar #'math-normalize (cdr a))))
((eq (car a) 'quote)
(math-normalize (nth 1 a)))
((eq (car a) 'special-const)
......@@ -2412,7 +2415,7 @@ If X is not an error form, return 1."
(math-normalize-logical-op a))
((memq (car a) '(calcFunc-lambda calcFunc-quote calcFunc-condition))
(let ((calc-simplify-mode 'none))
(cons (car a) (mapcar 'math-normalize (cdr a)))))
(cons (car a) (mapcar #'math-normalize (cdr a)))))
((eq (car a) 'calcFunc-evalto)
(setq a (or (nth 1 a) 0))
(or calc-refreshing-evaltos
......@@ -2435,27 +2438,25 @@ If X is not an error form, return 1."
;; The variable math-normalize-a is local to math-normalize in calc.el,
;; but is used by math-normalize-nonstandard, which is called by
;; math-normalize.
(defvar math-normalize-a)
(defun math-normalize-nonstandard ()
(defun math-normalize-nonstandard (a)
(if (consp calc-simplify-mode)
(progn
(setq calc-simplify-mode 'none
math-simplify-only (car-safe (cdr-safe math-normalize-a)))
math-simplify-only (car-safe (cdr-safe a)))
nil)
(and (symbolp (car math-normalize-a))
(and (symbolp (car a))
(or (eq calc-simplify-mode 'none)
(and (eq calc-simplify-mode 'num)
(let ((aptr (setq math-normalize-a
(let ((aptr (setq a
(cons
(car math-normalize-a)
(mapcar 'math-normalize
(cdr math-normalize-a))))))
(car a)
(mapcar #'math-normalize
(cdr a))))))
(while (and aptr (math-constp (car aptr)))
(setq aptr (cdr aptr)))
aptr)))
(cons (car math-normalize-a)
(mapcar 'math-normalize (cdr math-normalize-a))))))
(cons (car a)
(mapcar #'math-normalize (cdr a))))))
;;; Normalize a bignum digit list by trimming high-end zeros. [L l]
......@@ -2808,7 +2809,7 @@ If X is not an error form, return 1."
x)
(if (Math-primp x)
x
(cons (car x) (mapcar 'math-evaluate-expr-rec (cdr x))))))
(cons (car x) (mapcar #'math-evaluate-expr-rec (cdr x))))))
x))
(defun math-any-floats (expr)
......@@ -2822,9 +2823,10 @@ If X is not an error form, return 1."
(defvar math-mt-many nil)
(defvar math-mt-func nil)
(defun math-map-tree (math-mt-func mmt-expr &optional math-mt-many)
(or math-mt-many (setq math-mt-many 1000000))
(math-map-tree-rec mmt-expr))
(defun math-map-tree (func mmt-expr &optional many)
(let ((math-mt-func func)
(math-mt-many (or many 1000000)))
(math-map-tree-rec mmt-expr)))
(defun math-map-tree-rec (mmt-expr)
(or (= math-mt-many 0)
......@@ -2842,7 +2844,7 @@ If X is not an error form, return 1."
(<= math-mt-many 0))
(setq mmt-done t)
(setq mmt-nextval (cons (car mmt-expr)
(mapcar 'math-map-tree-rec
(mapcar #'math-map-tree-rec
(cdr mmt-expr))))
(if (equal mmt-nextval mmt-expr)
(setq mmt-done t)
......@@ -2867,6 +2869,7 @@ If X is not an error form, return 1."
(defvar math-integral-cache)
(defmacro math-defintegral (funcs &rest code)
(declare (indent 1) (debug (sexp body)))
(setq math-integral-cache nil)
(cons 'progn
(mapcar #'(lambda (func)
......@@ -2876,9 +2879,9 @@ If X is not an error form, return 1."
(list
#'(lambda (u) ,@code)))))
(if (symbolp funcs) (list funcs) funcs))))
(put 'math-defintegral 'lisp-indent-hook 1)
(defmacro math-defintegral-2 (funcs &rest code)
(declare (indent 1) (debug (sexp body)))
(setq math-integral-cache nil)
(cons 'progn
(mapcar #'(lambda (func)
......@@ -2887,7 +2890,6 @@ If X is not an error form, return 1."
(get ',func 'math-integral-2)
(list #'(lambda (u v) ,@code)))))
(if (symbolp funcs) (list funcs) funcs))))
(put 'math-defintegral-2 'lisp-indent-hook 1)
(defvar var-IntegAfterRules 'calc-IntegAfterRules)
......@@ -3097,9 +3099,16 @@ If X is not an error form, return 1."
;;; Expression parsing.
(defvar math-expr-data)
(defvar math-exp-pos)
(defvar math-exp-old-pos)
(defvar math-exp-keep-spaces)
(defvar math-exp-token)
(defvar math-expr-data)
(defvar math-exp-str)
(defun math-read-expr (math-exp-str)
(defun math-read-expr (str)
(let ((math-exp-pos 0)
(math-exp-str str)
(math-exp-old-pos 0)
(math-exp-keep-spaces nil)
math-exp-token math-expr-data)
......@@ -3138,6 +3147,10 @@ If X is not an error form, return 1."
;;; They said it couldn't be done...
(defvar math-read-big-baseline)
(defvar math-read-big-h2)
(defvar math-read-big-err-msg)
(defun math-read-big-expr (str)
(and (> (length calc-left-label) 0)
(string-match (concat "^" (regexp-quote calc-left-label)) str)
......@@ -3179,6 +3192,8 @@ If X is not an error form, return 1."
'(error 0 "Syntax error"))
(math-read-expr str)))))
(defvar math-rb-h2)
(defun math-read-big-bigp (math-read-big-lines)
(and (cdr math-read-big-lines)
(let ((matrix nil)
......
This diff is collapsed.
This diff is collapsed.
;;; calccomp.el --- composition functions for Calc
;;; calccomp.el --- composition functions for Calc -*- lexical-binding:t -*-
;; Copyright (C) 1990-1993, 2001-2018 Free Software Foundation, Inc.
......@@ -121,7 +121,8 @@
calc-lang-slash-idiv)
(math-float (nth 1 aa))
(nth 1 aa))
(nth 2 aa)) prec))
(nth 2 aa))
prec))
(if (and (eq calc-language 'big)
(= (length (car calc-frac-format)) 1))
(let* ((aa (math-adjust-fraction a))
......@@ -203,7 +204,8 @@
(math-comp-comma (or calc-vector-commas ""))
(math-comp-vector-prec (if (or (and calc-vector-commas
(math-vector-no-parens a))
(memq 'P calc-matrix-brackets)) 0 1000))
(memq 'P calc-matrix-brackets))
0 1000))
(math-comp-just (cond ((eq calc-matrix-just 'right) 'vright)
((eq calc-matrix-just 'center) 'vcent)
(t 'vleft)))
......@@ -803,8 +805,7 @@
( % . calcFunc-mod )
( ^ . calcFunc-pow )
( neg . calcFunc-neg )
( | . calcFunc-vconcat ))))
left right args)
( | . calcFunc-vconcat )))))
(if func2
(setq func (cdr func2)))
(if (setq func2 (rassq func math-expr-function-mapping))
......@@ -858,7 +859,7 @@
(or (cdr (cdr a))
(not (eq (car-safe (nth 1 a)) '*))))
(defun math-compose-matrix (a col cols base)
(defun math-compose-matrix (a _col cols base)
(let ((col 0)
(res nil))
(while (<= (setq col (1+ col)) cols)
......@@ -968,8 +969,8 @@
(and (memq (car a) '(^ calcFunc-subscr))
(math-tex-expr-is-flat (nth 1 a)))))
(put 'calcFunc-log 'math-compose-big 'math-compose-log)
(defun math-compose-log (a prec)
(put 'calcFunc-log 'math-compose-big #'math-compose-log)
(defun math-compose-log (a _prec)
(and (= (length a) 3)
(list 'horiz
(list 'subscr "log"
......@@ -979,8 +980,8 @@
(math-compose-expr (nth 1 a) 1000)
")")))
(put 'calcFunc-log10 'math-compose-big 'math-compose-log10)
(defun math-compose-log10 (a prec)
(put 'calcFunc-log10 'math-compose-big #'math-compose-log10)
(defun math-compose-log10 (a _prec)
(and (= (length a) 2)
(list 'horiz
(list 'subscr "log" "10")
......@@ -988,8 +989,8 @@
(math-compose-expr (nth 1 a) 1000)
")")))
(put 'calcFunc-deriv 'math-compose-big 'math-compose-deriv)
(put 'calcFunc-tderiv 'math-compose-big 'math-compose-deriv)
(put 'calcFunc-deriv 'math-compose-big #'math-compose-deriv)
(put 'calcFunc-tderiv 'math-compose-big #'math-compose-deriv)
(defun math-compose-deriv (a prec)
(when (= (length a) 3)
(math-compose-expr (list '/
......@@ -1003,8 +1004,8 @@
(nth 2 a))))
prec)))
(put 'calcFunc-sqrt 'math-compose-big 'math-compose-sqrt)
(defun math-compose-sqrt (a prec)
(put 'calcFunc-sqrt 'math-compose-big #'math-compose-sqrt)
(defun math-compose-sqrt (a _prec)
(when (= (length a) 2)
(let* ((c (math-compose-expr (nth 1 a) 0))
(a (math-comp-ascent c))
......@@ -1024,8 +1025,8 @@
" "
c)))))
(put 'calcFunc-choose 'math-compose-big 'math-compose-choose)
(defun math-compose-choose (a prec)
(put 'calcFunc-choose 'math-compose-big #'math-compose-choose)
(defun math-compose-choose (a _prec)
(let ((a1 (math-compose-expr (nth 1 a) 0))
(a2 (math-compose-expr (nth 2 a) 0)))
(list 'horiz
......@@ -1035,7 +1036,7 @@
a1 " " a2)
")")))
(put 'calcFunc-integ 'math-compose-big 'math-compose-integ)
(put 'calcFunc-integ 'math-compose-big #'math-compose-integ)
(defun math-compose-integ (a prec)
(and (memq (length a) '(3 5))
(eq (car-safe (nth 2 a)) 'var)
......@@ -1072,7 +1073,7 @@
(list 'horiz " d" var))
(if parens ")" "")))))
(put 'calcFunc-sum 'math-compose-big 'math-compose-sum)
(put 'calcFunc-sum 'math-compose-big #'math-compose-sum)
(defun math-compose-sum (a prec)
(and (memq (length a) '(3 5 6))
(let* ((expr (math-compose-expr (nth 1 a) 185))
......@@ -1097,7 +1098,7 @@
expr
(if (memq prec '(180 201)) ")" "")))))
(put 'calcFunc-prod 'math-compose-big 'math-compose-prod)
(put 'calcFunc-prod 'math-compose-big #'math-compose-prod)
(defun math-compose-prod (a prec)
(and (memq (length a) '(3 5 6))
(let* ((expr (math-compose-expr (nth 1 a) 198))
......@@ -1124,12 +1125,11 @@
;; The variables math-svo-c, math-svo-wid and math-svo-off are local
;; to math-stack-value-offset in calc.el, but are used by
;; math-stack-value-offset-fancy, which is called by math-stack-value-offset..
(defvar math-svo-c)
(defvar math-svo-wid)
(defvar math-svo-off)
(defun math-stack-value-offset-fancy ()
(let ((cwid (+ (math-comp-width math-svo-c))))
(defun math-stack-value-offset-fancy (c)
(let ((cwid (+ (math-comp-width c))))
(cond ((eq calc-display-just 'right)
(if calc-display-origin
(setq math-svo-wid (max calc-display-origin 5))
......@@ -1215,7 +1215,7 @@
;; which are called by math-comp-to-string-flat.
(defvar math-comp-pos)
(defun math-comp-to-string-flat (c math-comp-full-width)
(defun math-comp-to-string-flat (c full-width)
(if math-comp-sel-hpos
(let ((math-comp-pos 0))
(math-comp-sel-flat-term c))
......@@ -1224,6 +1224,7 @@
(math-comp-pos 0)
(math-comp-margin 0)
(math-comp-highlight (and math-comp-selected calc-show-selections))
(math-comp-full-width full-width)
(math-comp-level -1))
(math-comp-to-string-flat-term '(set -1 0))
(math-comp-to-string-flat-term c)
......@@ -1387,7 +1388,7 @@
(defvar math-comp-hpos)
(defvar math-comp-vpos)
(defun math-comp-simplify (c full-width)
(defun math-comp-simplify (c _full-width)
(let ((math-comp-buf (list ""))
(math-comp-base 0)
(math-comp-hgt 1)
......
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