[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 0fac3f5: * lisp/calc: Fix a few issues introduced by lexical scop
From: |
Stefan Monnier |
Subject: |
master 0fac3f5: * lisp/calc: Fix a few issues introduced by lexical scoping |
Date: |
Wed, 14 Oct 2020 18:03:58 -0400 (EDT) |
branch: master
commit 0fac3f55325cf33e797b33be9935bf39f344c7c9
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>
* lisp/calc: Fix a few issues introduced by lexical scoping
Fix a few places I missed, where we incorrectly used lexical scoping on a
var
that needed dynamic scoping.
These were detected thanks to a bit of footwork by Mattias EngdegÄrd!
* lisp/calc/calc-ext.el (math-read-big-lines): Declare as dynbound.
(math-read-big-bigp): Bind it inside a `let`.
* lisp/calc/calc-graph.el (math-arglist): Declare as dynbound.
* lisp/calc/calc-map.el (math-arglist): Declare as dynbound.
* lisp/calc/calc-misc.el (math-trunc-prec): Declare as dynbound.
(math-trunc): Bind it inside a `let`.
(math-floor-prec): Declare as dynbound.
(math-floor): Bind it inside a `let`.
* lisp/calc/calc-nlfit.el (calc-curve-varnames, calc-curve-coefnames):
Declare as dynbound.
* lisp/calc/calc-sel.el (math-comp-sel-tag): Declare as dynbound.
* lisp/calc/calcsel2.el (calc-sel-reselect): Declare as dynbound.
---
lisp/calc/calc-ext.el | 72 +++++++++++++++++++++++++------------------------
lisp/calc/calc-graph.el | 1 +
lisp/calc/calc-map.el | 2 ++
lisp/calc/calc-misc.el | 21 +++++++++------
lisp/calc/calc-nlfit.el | 2 ++
lisp/calc/calc-sel.el | 4 ++-
lisp/calc/calcalg2.el | 20 +++++++-------
lisp/calc/calcsel2.el | 1 +
8 files changed, 69 insertions(+), 54 deletions(-)
diff --git a/lisp/calc/calc-ext.el b/lisp/calc/calc-ext.el
index fc0a2c8..c48d159 100644
--- a/lisp/calc/calc-ext.el
+++ b/lisp/calc/calc-ext.el
@@ -3094,6 +3094,7 @@ If X is not an error form, return 1."
(defvar math-read-big-baseline)
(defvar math-read-big-h2)
(defvar math-read-big-err-msg)
+(defvar math-read-big-lines)
(defun math-read-big-expr (str)
(and (> (length calc-left-label) 0)
@@ -3138,41 +3139,42 @@ If X is not an error form, return 1."
(defvar math-rb-h2)
-(defun math-read-big-bigp (math-read-big-lines)
- (and (cdr math-read-big-lines)
- (let ((matrix nil)
- (v 0)
- (height (if (> (length (car math-read-big-lines)) 0) 1 0)))
- (while (and (cdr math-read-big-lines)
- (let* ((i 0)
- j
- (l1 (car math-read-big-lines))
- (l2 (nth 1 math-read-big-lines))
- (len (min (length l1) (length l2))))
- (if (> (length l2) 0)
- (setq height (1+ height)))
- (while (and (< i len)
- (or (memq (aref l1 i) '(?\ ?\- ?\_))
- (memq (aref l2 i) '(?\ ?\-))
- (and (memq (aref l1 i) '(?\| ?\,))
- (= (aref l2 i) (aref l1 i)))
- (and (eq (aref l1 i) ?\[)
- (eq (aref l2 i) ?\[)
- (let ((math-rb-h2 (length l1)))
- (setq j (math-read-big-balance
- (1+ i) v "[")))
- (setq i (1- j)))))
- (setq i (1+ i)))
- (or (= i len)
- (and (eq (aref l1 i) ?\[)
- (eq (aref l2 i) ?\[)
- (setq matrix t)
- nil))))
- (setq math-read-big-lines (cdr math-read-big-lines)
- v (1+ v)))
- (or (and (> height 1)
- (not (cdr math-read-big-lines)))
- matrix))))
+(defun math-read-big-bigp (read-big-lines)
+ (when (cdr read-big-lines)
+ (let ((math-read-big-lines read-big-lines)
+ (matrix nil)
+ (v 0)
+ (height (if (> (length (car read-big-lines)) 0) 1 0)))
+ (while (and (cdr math-read-big-lines)
+ (let* ((i 0)
+ j
+ (l1 (car math-read-big-lines))
+ (l2 (nth 1 math-read-big-lines))
+ (len (min (length l1) (length l2))))
+ (if (> (length l2) 0)
+ (setq height (1+ height)))
+ (while (and (< i len)
+ (or (memq (aref l1 i) '(?\ ?\- ?\_))
+ (memq (aref l2 i) '(?\ ?\-))
+ (and (memq (aref l1 i) '(?\| ?\,))
+ (= (aref l2 i) (aref l1 i)))
+ (and (eq (aref l1 i) ?\[)
+ (eq (aref l2 i) ?\[)
+ (let ((math-rb-h2 (length l1)))
+ (setq j (math-read-big-balance
+ (1+ i) v "[")))
+ (setq i (1- j)))))
+ (setq i (1+ i)))
+ (or (= i len)
+ (and (eq (aref l1 i) ?\[)
+ (eq (aref l2 i) ?\[)
+ (setq matrix t)
+ nil))))
+ (setq math-read-big-lines (cdr math-read-big-lines)
+ v (1+ v)))
+ (or (and (> height 1)
+ (not (cdr math-read-big-lines)))
+ matrix))))
;;; Nontrivial "flat" formatting.
diff --git a/lisp/calc/calc-graph.el b/lisp/calc/calc-graph.el
index 82e9335..829fa44 100644
--- a/lisp/calc/calc-graph.el
+++ b/lisp/calc/calc-graph.el
@@ -313,6 +313,7 @@
(defvar calc-graph-blank)
(defvar calc-graph-non-blank)
(defvar calc-graph-curve-num)
+(defvar math-arglist)
(defun calc-graph-plot (flag &optional printing)
(interactive "P")
diff --git a/lisp/calc/calc-map.el b/lisp/calc/calc-map.el
index 57483fc..0ee8282 100644
--- a/lisp/calc/calc-map.el
+++ b/lisp/calc/calc-map.el
@@ -493,6 +493,8 @@
(defvar calc-get-operator-history nil
"History for calc-get-operator.")
+(defvar math-arglist)
+
(defun calc-get-operator (msg &optional nargs)
(setq calc-aborted-prefix nil)
(let ((inv nil) (hyp nil) (prefix nil) (forcenargs nil)
diff --git a/lisp/calc/calc-misc.el b/lisp/calc/calc-misc.el
index 7c97dc6..2db09e2 100644
--- a/lisp/calc/calc-misc.el
+++ b/lisp/calc/calc-misc.el
@@ -757,19 +757,21 @@ loaded and the keystroke automatically re-typed."
;; The variable math-trunc-prec is local to math-trunc, but used by
;; math-trunc-fancy in calc-arith.el, which is called by math-trunc.
+(defvar math-trunc-prec)
;;;###autoload
-(defun math-trunc (a &optional math-trunc-prec)
- (cond (math-trunc-prec
+(defun math-trunc (a &optional trunc-prec)
+ (cond (trunc-prec
(require 'calc-ext)
- (math-trunc-special a math-trunc-prec))
+ (math-trunc-special a trunc-prec))
((Math-integerp a) a)
((Math-looks-negp a)
(math-neg (math-trunc (math-neg a))))
((eq (car a) 'float)
(math-scale-int (nth 1 a) (nth 2 a)))
(t (require 'calc-ext)
- (math-trunc-fancy a))))
+ (let ((math-trunc-prec trunc-prec))
+ (math-trunc-fancy a)))))
;;;###autoload
(defalias 'calcFunc-trunc 'math-trunc)
@@ -777,12 +779,13 @@ loaded and the keystroke automatically re-typed."
;; The variable math-floor-prec is local to math-floor, but used by
;; math-floor-fancy in calc-arith.el, which is called by math-floor.
+(defvar math-floor-prec)
;;;###autoload
-(defun math-floor (a &optional math-floor-prec) ; [Public]
- (cond (math-floor-prec
+(defun math-floor (a &optional floor-prec) ; [Public]
+ (cond (floor-prec
(require 'calc-ext)
- (math-floor-special a math-floor-prec))
+ (math-floor-special a floor-prec))
((Math-integerp a) a)
((Math-messy-integerp a) (math-trunc a))
((Math-realp a)
@@ -790,7 +793,9 @@ loaded and the keystroke automatically re-typed."
(math-add (math-trunc a) -1)
(math-trunc a)))
(t (require 'calc-ext)
- (math-floor-fancy a))))
+ (let ((math-floor-prec floor-prec))
+ (math-floor-fancy a)))))
+
;;;###autoload
(defalias 'calcFunc-floor 'math-floor)
diff --git a/lisp/calc/calc-nlfit.el b/lisp/calc/calc-nlfit.el
index 6f2a601..5ed85fe 100644
--- a/lisp/calc/calc-nlfit.el
+++ b/lisp/calc/calc-nlfit.el
@@ -665,6 +665,8 @@
(calc-handle-whys))
(defvar calc-curve-nvars)
+(defvar calc-curve-varnames)
+(defvar calc-curve-coefnames)
(defun math-nlfit-fit-curve (fn grad solnexpr initparms &optional sdv)
(calc-slow-wrapper
diff --git a/lisp/calc/calc-sel.el b/lisp/calc/calc-sel.el
index d294448..23c0e01 100644
--- a/lisp/calc/calc-sel.el
+++ b/lisp/calc/calc-sel.el
@@ -419,6 +419,7 @@
;; The variable math-comp-sel-tag is local to calc-find-selected-part,
;; but is used by math-comp-sel-flat-term and math-comp-add-string-sel
;; in calccomp.el, which are called (indirectly) by calc-find-selected-part.
+(defvar math-comp-sel-tag)
(defun calc-find-selected-part ()
(let* ((math-comp-sel-hpos (- (current-column) calc-selection-cache-offset))
@@ -437,7 +438,8 @@
(current-indentation))
lcount (1+ lcount)))
(- lcount (math-comp-ascent
- calc-selection-cache-comp) -1))))
+ calc-selection-cache-comp)
+ -1))))
(math-comp-sel-cpos (- (point) toppt calc-selection-cache-offset
spaces lcount))
(math-comp-sel-tag nil))
diff --git a/lisp/calc/calcalg2.el b/lisp/calc/calcalg2.el
index 99d0549..7894bd9 100644
--- a/lisp/calc/calcalg2.el
+++ b/lisp/calc/calcalg2.el
@@ -3259,16 +3259,16 @@
(let ((math-solve-simplifying t))
(math-solve-system-rec exprs math-solve-vars nil)))))
-;;; The following backtracking solver works by choosing a variable
-;;; and equation, and trying to solve the equation for the variable.
-;;; If it succeeds it calls itself recursively with that variable and
-;;; equation removed from their respective lists, and with the solution
-;;; added to solns as well as being substituted into all existing
-;;; equations. The algorithm terminates when any solution path
-;;; manages to remove all the variables from var-list.
-
-;;; To support calcFunc-roots, entries in eqn-list and solns are
-;;; actually lists of equations.
+;; The following backtracking solver works by choosing a variable
+;; and equation, and trying to solve the equation for the variable.
+;; If it succeeds it calls itself recursively with that variable and
+;; equation removed from their respective lists, and with the solution
+;; added to solns as well as being substituted into all existing
+;; equations. The algorithm terminates when any solution path
+;; manages to remove all the variables from `var-list'.
+
+;; To support calcFunc-roots, entries in eqn-list and solns are
+;; actually lists of equations.
;; The variables math-solve-system-res and math-solve-system-vv are
;; local to math-solve-system-rec, but are used by math-solve-system-subst.
diff --git a/lisp/calc/calcsel2.el b/lisp/calc/calcsel2.el
index faec230..d6842aa 100644
--- a/lisp/calc/calcsel2.el
+++ b/lisp/calc/calcsel2.el
@@ -34,6 +34,7 @@
;; The variable calc-sel-reselect is local to the methods below,
;; but is used by some functions in calc-sel.el which are called
;; by the functions below.
+(defvar calc-sel-reselect)
(defun calc-commute-left (arg)
(interactive "p")
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master 0fac3f5: * lisp/calc: Fix a few issues introduced by lexical scoping,
Stefan Monnier <=