diff options
| author | Jay Belanger | 2004-11-21 05:52:41 +0000 |
|---|---|---|
| committer | Jay Belanger | 2004-11-21 05:52:41 +0000 |
| commit | a6cecab98aabcefe94e451027b370a82733d3d8e (patch) | |
| tree | bd4a8d8eb3df389bc54132cf1b79e076a71454c1 | |
| parent | 07c8c65a65b9b9f7a41d3e0784b2702ea2a562ae (diff) | |
| download | emacs-a6cecab98aabcefe94e451027b370a82733d3d8e.tar.gz emacs-a6cecab98aabcefe94e451027b370a82733d3d8e.zip | |
(math-integral-cache-state, calc-lang)
(calc-original-buffer): Declare them.
(calc-user-formula-alist): New variable.
(calc-user-define-formula, calc-fix-user-formula)
(calc-user-define-composition, calc-finish-formula-edit):
Replace variable alist by declared variable.
(var-q0, var-q1, var-q2, var-q3, var-q4, var-q5, var-q6)
(var-q7, var-q7, var-q8, var-q9): Declare them.
(calc-kbd-push): Don't check to see if var-q0 through var-q9
are bound.
(calcFunc-typeof): Replace undeclared variable by correct expression.
(math-exp-env): New variable.
(math-define-body, math-define-exp): Replace exp-env by declared
variable.
(math-define-exp): Replace misplaced variable by expression.
| -rw-r--r-- | lisp/calc/calc-prog.el | 141 |
1 files changed, 91 insertions, 50 deletions
diff --git a/lisp/calc/calc-prog.el b/lisp/calc/calc-prog.el index 5733938ad7a..93250299f73 100644 --- a/lisp/calc/calc-prog.el +++ b/lisp/calc/calc-prog.el | |||
| @@ -3,8 +3,7 @@ | |||
| 3 | ;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | ;; Author: David Gillespie <daveg@synaptics.com> | 5 | ;; Author: David Gillespie <daveg@synaptics.com> |
| 6 | ;; Maintainers: D. Goel <deego@gnufans.org> | 6 | ;; Maintainer: Jay Belanger <belanger@truman.edu> |
| 7 | ;; Colin Walters <walters@debian.org> | ||
| 8 | 7 | ||
| 9 | ;; This file is part of GNU Emacs. | 8 | ;; This file is part of GNU Emacs. |
| 10 | 9 | ||
| @@ -157,6 +156,16 @@ | |||
| 157 | (error "No such user key is defined")) | 156 | (error "No such user key is defined")) |
| 158 | kmap)))) | 157 | kmap)))) |
| 159 | 158 | ||
| 159 | |||
| 160 | ;; math-integral-cache-state is originally declared in calcalg2.el, | ||
| 161 | ;; it is used in calc-user-define-variable. | ||
| 162 | (defvar math-integral-cache-state) | ||
| 163 | |||
| 164 | ;; calc-user-formula-alist is local to calc-user-define-formula, | ||
| 165 | ;; calc-user-define-compostion and calc-finish-formula-edit, | ||
| 166 | ;; but is used by calc-fix-user-formula. | ||
| 167 | (defvar calc-user-formula-alist) | ||
| 168 | |||
| 160 | (defun calc-user-define-formula () | 169 | (defun calc-user-define-formula () |
| 161 | (interactive) | 170 | (interactive) |
| 162 | (calc-wrapper | 171 | (calc-wrapper |
| @@ -164,7 +173,7 @@ | |||
| 164 | (arglist nil) | 173 | (arglist nil) |
| 165 | (is-lambda (and (eq (car-safe form) 'calcFunc-lambda) | 174 | (is-lambda (and (eq (car-safe form) 'calcFunc-lambda) |
| 166 | (>= (length form) 2))) | 175 | (>= (length form) 2))) |
| 167 | odef key keyname cmd cmd-base func alist is-symb) | 176 | odef key keyname cmd cmd-base func calc-user-formula-alist is-symb) |
| 168 | (if is-lambda | 177 | (if is-lambda |
| 169 | (setq arglist (mapcar (function (lambda (x) (nth 1 x))) | 178 | (setq arglist (mapcar (function (lambda (x) (nth 1 x))) |
| 170 | (nreverse (cdr (reverse (cdr form))))) | 179 | (nreverse (cdr (reverse (cdr form))))) |
| @@ -238,26 +247,28 @@ | |||
| 238 | (and cmd (symbol-name cmd)) | 247 | (and cmd (symbol-name cmd)) |
| 239 | (format "%05d" (% (random) 10000))))))) | 248 | (format "%05d" (% (random) 10000))))))) |
| 240 | (if is-lambda | 249 | (if is-lambda |
| 241 | (setq alist arglist) | 250 | (setq calc-user-formula-alist arglist) |
| 242 | (while | 251 | (while |
| 243 | (progn | 252 | (progn |
| 244 | (setq alist (read-from-minibuffer "Function argument list: " | 253 | (setq calc-user-formula-alist |
| 245 | (if arglist | 254 | (read-from-minibuffer "Function argument list: " |
| 246 | (prin1-to-string arglist) | 255 | (if arglist |
| 247 | "()") | 256 | (prin1-to-string arglist) |
| 248 | minibuffer-local-map | 257 | "()") |
| 249 | t)) | 258 | minibuffer-local-map |
| 250 | (and (not (calc-subsetp alist arglist)) | 259 | t)) |
| 260 | (and (not (calc-subsetp calc-user-formula-alist arglist)) | ||
| 251 | (not (y-or-n-p | 261 | (not (y-or-n-p |
| 252 | "Okay for arguments that don't appear in formula to be ignored? ")))))) | 262 | "Okay for arguments that don't appear in formula to be ignored? ")))))) |
| 253 | (setq is-symb (and alist | 263 | (setq is-symb (and calc-user-formula-alist |
| 254 | func | 264 | func |
| 255 | (y-or-n-p | 265 | (y-or-n-p |
| 256 | "Leave it symbolic for non-constant arguments? "))) | 266 | "Leave it symbolic for non-constant arguments? "))) |
| 257 | (setq alist (mapcar (function (lambda (x) | 267 | (setq calc-user-formula-alist |
| 258 | (or (cdr (assq x '((nil . arg-nil) | 268 | (mapcar (function (lambda (x) |
| 259 | (t . arg-t)))) | 269 | (or (cdr (assq x '((nil . arg-nil) |
| 260 | x))) alist)) | 270 | (t . arg-t)))) |
| 271 | x))) calc-user-formula-alist)) | ||
| 261 | (if cmd | 272 | (if cmd |
| 262 | (progn | 273 | (progn |
| 263 | (calc-need-macros) | 274 | (calc-need-macros) |
| @@ -267,7 +278,7 @@ | |||
| 267 | '(interactive) | 278 | '(interactive) |
| 268 | (list 'calc-wrapper | 279 | (list 'calc-wrapper |
| 269 | (list 'calc-enter-result | 280 | (list 'calc-enter-result |
| 270 | (length alist) | 281 | (length calc-user-formula-alist) |
| 271 | (let ((name (symbol-name (or func cmd)))) | 282 | (let ((name (symbol-name (or func cmd)))) |
| 272 | (and (string-match | 283 | (and (string-match |
| 273 | "\\([^-][^-]?[^-]?[^-]?\\)[^-]*\\'" | 284 | "\\([^-][^-]?[^-]?[^-]?\\)[^-]*\\'" |
| @@ -276,16 +287,16 @@ | |||
| 276 | (list 'cons | 287 | (list 'cons |
| 277 | (list 'quote func) | 288 | (list 'quote func) |
| 278 | (list 'calc-top-list-n | 289 | (list 'calc-top-list-n |
| 279 | (length alist))))))) | 290 | (length calc-user-formula-alist))))))) |
| 280 | (put cmd 'calc-user-defn t))) | 291 | (put cmd 'calc-user-defn t))) |
| 281 | (let ((body (list 'math-normalize (calc-fix-user-formula form)))) | 292 | (let ((body (list 'math-normalize (calc-fix-user-formula form)))) |
| 282 | (fset func | 293 | (fset func |
| 283 | (append | 294 | (append |
| 284 | (list 'lambda alist) | 295 | (list 'lambda calc-user-formula-alist) |
| 285 | (and is-symb | 296 | (and is-symb |
| 286 | (mapcar (function (lambda (v) | 297 | (mapcar (function (lambda (v) |
| 287 | (list 'math-check-const v t))) | 298 | (list 'math-check-const v t))) |
| 288 | alist)) | 299 | calc-user-formula-alist)) |
| 289 | (list body)))) | 300 | (list body)))) |
| 290 | (put func 'calc-user-defn form) | 301 | (put func 'calc-user-defn form) |
| 291 | (setq math-integral-cache-state nil) | 302 | (setq math-integral-cache-state nil) |
| @@ -324,7 +335,7 @@ | |||
| 324 | (memq (setq temp (or (cdr (assq (nth 1 f) '((nil . arg-nil) | 335 | (memq (setq temp (or (cdr (assq (nth 1 f) '((nil . arg-nil) |
| 325 | (t . arg-t)))) | 336 | (t . arg-t)))) |
| 326 | (nth 1 f))) | 337 | (nth 1 f))) |
| 327 | alist)) | 338 | calc-user-formula-alist)) |
| 328 | temp) | 339 | temp) |
| 329 | ((or (math-constp f) (eq (car f) 'var)) | 340 | ((or (math-constp f) (eq (car f) 'var)) |
| 330 | (list 'quote f)) | 341 | (list 'quote f)) |
| @@ -356,7 +367,7 @@ | |||
| 356 | (comps (get func 'math-compose-forms)) | 367 | (comps (get func 'math-compose-forms)) |
| 357 | entry entry2 | 368 | entry entry2 |
| 358 | (arglist nil) | 369 | (arglist nil) |
| 359 | (alist nil)) | 370 | (calc-user-formula-alist nil)) |
| 360 | (if (math-zerop comp) | 371 | (if (math-zerop comp) |
| 361 | (if (setq entry (assq calc-language comps)) | 372 | (if (setq entry (assq calc-language comps)) |
| 362 | (put func 'math-compose-forms (delq entry comps))) | 373 | (put func 'math-compose-forms (delq entry comps))) |
| @@ -364,22 +375,25 @@ | |||
| 364 | (setq arglist (sort arglist 'string-lessp)) | 375 | (setq arglist (sort arglist 'string-lessp)) |
| 365 | (while | 376 | (while |
| 366 | (progn | 377 | (progn |
| 367 | (setq alist (read-from-minibuffer "Composition argument list: " | 378 | (setq calc-user-formula-alist |
| 368 | (if arglist | 379 | (read-from-minibuffer "Composition argument list: " |
| 369 | (prin1-to-string arglist) | 380 | (if arglist |
| 370 | "()") | 381 | (prin1-to-string arglist) |
| 371 | minibuffer-local-map | 382 | "()") |
| 372 | t)) | 383 | minibuffer-local-map |
| 373 | (and (not (calc-subsetp alist arglist)) | 384 | t)) |
| 385 | (and (not (calc-subsetp calc-user-formula-alist arglist)) | ||
| 374 | (y-or-n-p | 386 | (y-or-n-p |
| 375 | "Okay for arguments that don't appear in formula to be invisible? ")))) | 387 | "Okay for arguments that don't appear in formula to be invisible? ")))) |
| 376 | (or (setq entry (assq calc-language comps)) | 388 | (or (setq entry (assq calc-language comps)) |
| 377 | (put func 'math-compose-forms | 389 | (put func 'math-compose-forms |
| 378 | (cons (setq entry (list calc-language)) comps))) | 390 | (cons (setq entry (list calc-language)) comps))) |
| 379 | (or (setq entry2 (assq (length alist) (cdr entry))) | 391 | (or (setq entry2 (assq (length calc-user-formula-alist) (cdr entry))) |
| 380 | (setcdr entry | 392 | (setcdr entry |
| 381 | (cons (setq entry2 (list (length alist))) (cdr entry)))) | 393 | (cons (setq entry2 |
| 382 | (setcdr entry2 (list 'lambda alist (calc-fix-user-formula comp)))) | 394 | (list (length calc-user-formula-alist))) (cdr entry)))) |
| 395 | (setcdr entry2 | ||
| 396 | (list 'lambda calc-user-formula-alist (calc-fix-user-formula comp)))) | ||
| 383 | (calc-pop-stack 1) | 397 | (calc-pop-stack 1) |
| 384 | (calc-do-refresh)))) | 398 | (calc-do-refresh)))) |
| 385 | 399 | ||
| @@ -445,6 +459,8 @@ | |||
| 445 | lang))) | 459 | lang))) |
| 446 | (calc-show-edit-buffer)) | 460 | (calc-show-edit-buffer)) |
| 447 | 461 | ||
| 462 | (defvar calc-original-buffer) | ||
| 463 | |||
| 448 | (defun calc-finish-user-syntax-edit (lang) | 464 | (defun calc-finish-user-syntax-edit (lang) |
| 449 | (let ((tab (calc-read-parse-table calc-original-buffer lang)) | 465 | (let ((tab (calc-read-parse-table calc-original-buffer lang)) |
| 450 | (entry (assq lang calc-user-parse-tables))) | 466 | (entry (assq lang calc-user-parse-tables))) |
| @@ -458,6 +474,13 @@ | |||
| 458 | (delq entry calc-user-parse-tables))))) | 474 | (delq entry calc-user-parse-tables))))) |
| 459 | (switch-to-buffer calc-original-buffer)) | 475 | (switch-to-buffer calc-original-buffer)) |
| 460 | 476 | ||
| 477 | ;; The variable calc-lang is local to calc-write-parse-table, but is | ||
| 478 | ;; used by calc-write-parse-table-part which is called by | ||
| 479 | ;; calc-write-parse-table. The variable is also local to | ||
| 480 | ;; calc-read-parse-table, but is used by calc-fix-token-name which | ||
| 481 | ;; is called (indirectly) by calc-read-parse-table. | ||
| 482 | (defvar calc-lang) | ||
| 483 | |||
| 461 | (defun calc-write-parse-table (tab calc-lang) | 484 | (defun calc-write-parse-table (tab calc-lang) |
| 462 | (let ((p tab)) | 485 | (let ((p tab)) |
| 463 | (while p | 486 | (while p |
| @@ -876,7 +899,7 @@ | |||
| 876 | (goto-char (+ start (nth 1 val))) | 899 | (goto-char (+ start (nth 1 val))) |
| 877 | (error (nth 2 val)))) | 900 | (error (nth 2 val)))) |
| 878 | (setcar (cdr body) | 901 | (setcar (cdr body) |
| 879 | (let ((alist (nth 1 (symbol-function func)))) | 902 | (let ((calc-user-formula-alist (nth 1 (symbol-function func)))) |
| 880 | (calc-fix-user-formula val))) | 903 | (calc-fix-user-formula val))) |
| 881 | (put func 'calc-user-defn val)))) | 904 | (put func 'calc-user-defn val)))) |
| 882 | 905 | ||
| @@ -1277,20 +1300,33 @@ | |||
| 1277 | 1300 | ||
| 1278 | 1301 | ||
| 1279 | (defvar calc-kbd-push-level 0) | 1302 | (defvar calc-kbd-push-level 0) |
| 1303 | |||
| 1304 | ;; The variables var-q0 through var-q9 are the "quick" variables. | ||
| 1305 | (defvar var-q0 nil) | ||
| 1306 | (defvar var-q1 nil) | ||
| 1307 | (defvar var-q2 nil) | ||
| 1308 | (defvar var-q3 nil) | ||
| 1309 | (defvar var-q4 nil) | ||
| 1310 | (defvar var-q5 nil) | ||
| 1311 | (defvar var-q6 nil) | ||
| 1312 | (defvar var-q7 nil) | ||
| 1313 | (defvar var-q8 nil) | ||
| 1314 | (defvar var-q9 nil) | ||
| 1315 | |||
| 1280 | (defun calc-kbd-push (arg) | 1316 | (defun calc-kbd-push (arg) |
| 1281 | (interactive "P") | 1317 | (interactive "P") |
| 1282 | (calc-wrapper | 1318 | (calc-wrapper |
| 1283 | (let* ((defs (and arg (> (prefix-numeric-value arg) 0))) | 1319 | (let* ((defs (and arg (> (prefix-numeric-value arg) 0))) |
| 1284 | (var-q0 (and (boundp 'var-q0) var-q0)) | 1320 | (var-q0 var-q0) |
| 1285 | (var-q1 (and (boundp 'var-q1) var-q1)) | 1321 | (var-q1 var-q1) |
| 1286 | (var-q2 (and (boundp 'var-q2) var-q2)) | 1322 | (var-q2 var-q2) |
| 1287 | (var-q3 (and (boundp 'var-q3) var-q3)) | 1323 | (var-q3 var-q3) |
| 1288 | (var-q4 (and (boundp 'var-q4) var-q4)) | 1324 | (var-q4 var-q4) |
| 1289 | (var-q5 (and (boundp 'var-q5) var-q5)) | 1325 | (var-q5 var-q5) |
| 1290 | (var-q6 (and (boundp 'var-q6) var-q6)) | 1326 | (var-q6 var-q6) |
| 1291 | (var-q7 (and (boundp 'var-q7) var-q7)) | 1327 | (var-q7 var-q7) |
| 1292 | (var-q8 (and (boundp 'var-q8) var-q8)) | 1328 | (var-q8 var-q8) |
| 1293 | (var-q9 (and (boundp 'var-q9) var-q9)) | 1329 | (var-q9 var-q9) |
| 1294 | (calc-internal-prec (if defs 12 calc-internal-prec)) | 1330 | (calc-internal-prec (if defs 12 calc-internal-prec)) |
| 1295 | (calc-word-size (if defs 32 calc-word-size)) | 1331 | (calc-word-size (if defs 32 calc-word-size)) |
| 1296 | (calc-angle-mode (if defs 'deg calc-angle-mode)) | 1332 | (calc-angle-mode (if defs 'deg calc-angle-mode)) |
| @@ -1613,7 +1649,7 @@ | |||
| 1613 | ((eq (car a) 'var) | 1649 | ((eq (car a) 'var) |
| 1614 | (if (memq (nth 2 a) '(var-inf var-uinf var-nan)) 12 100)) | 1650 | (if (memq (nth 2 a) '(var-inf var-uinf var-nan)) 12 100)) |
| 1615 | ((eq (car a) 'vec) (if (math-matrixp a) 102 101)) | 1651 | ((eq (car a) 'vec) (if (math-matrixp a) 102 101)) |
| 1616 | (t (math-calcFunc-to-var func)))) | 1652 | (t (math-calcFunc-to-var (car a))))) |
| 1617 | 1653 | ||
| 1618 | (defun calcFunc-integer (a) | 1654 | (defun calcFunc-integer (a) |
| 1619 | (if (Math-integerp a) | 1655 | (if (Math-integerp a) |
| @@ -1868,7 +1904,12 @@ | |||
| 1868 | (list (cons 'catch (cons '(quote math-return) body))) | 1904 | (list (cons 'catch (cons '(quote math-return) body))) |
| 1869 | body))) | 1905 | body))) |
| 1870 | 1906 | ||
| 1871 | (defun math-define-body (body exp-env) | 1907 | ;; The variable math-exp-env is local to math-define-body, but is |
| 1908 | ;; used by math-define-exp, which is called (indirectly) by | ||
| 1909 | ;; by math-define-body. | ||
| 1910 | (defvar math-exp-env) | ||
| 1911 | |||
| 1912 | (defun math-define-body (body math-exp-env) | ||
| 1872 | (math-define-list body)) | 1913 | (math-define-list body)) |
| 1873 | 1914 | ||
| 1874 | (defun math-define-list (body &optional quote) | 1915 | (defun math-define-list (body &optional quote) |
| @@ -1897,7 +1938,7 @@ | |||
| 1897 | (if (and (consp (nth 1 exp)) | 1938 | (if (and (consp (nth 1 exp)) |
| 1898 | (eq (car (nth 1 exp)) 'lambda)) | 1939 | (eq (car (nth 1 exp)) 'lambda)) |
| 1899 | (cons 'quote | 1940 | (cons 'quote |
| 1900 | (math-define-lambda (nth 1 exp) exp-env)) | 1941 | (math-define-lambda (nth 1 exp) math-exp-env)) |
| 1901 | exp)) | 1942 | exp)) |
| 1902 | ((memq func '(let let* for foreach)) | 1943 | ((memq func '(let let* for foreach)) |
| 1903 | (let ((head (nth 1 exp)) | 1944 | (let ((head (nth 1 exp)) |
| @@ -1914,7 +1955,7 @@ | |||
| 1914 | (math-define-body body | 1955 | (math-define-body body |
| 1915 | (nconc | 1956 | (nconc |
| 1916 | (math-define-let-env head) | 1957 | (math-define-let-env head) |
| 1917 | exp-env))))))) | 1958 | math-exp-env))))))) |
| 1918 | ((and (memq func '(setq setf)) | 1959 | ((and (memq func '(setq setf)) |
| 1919 | (math-complicated-lhs (cdr exp))) | 1960 | (math-complicated-lhs (cdr exp))) |
| 1920 | (if (> (length exp) 3) | 1961 | (if (> (length exp) 3) |
| @@ -1925,7 +1966,7 @@ | |||
| 1925 | (cons (nth 1 exp) | 1966 | (cons (nth 1 exp) |
| 1926 | (math-define-body (cdr (cdr exp)) | 1967 | (math-define-body (cdr (cdr exp)) |
| 1927 | (cons (nth 1 exp) | 1968 | (cons (nth 1 exp) |
| 1928 | exp-env))))) | 1969 | math-exp-env))))) |
| 1929 | ((eq func 'cond) | 1970 | ((eq func 'cond) |
| 1930 | (cons func | 1971 | (cons func |
| 1931 | (math-define-cond (cdr exp)))) | 1972 | (math-define-cond (cdr exp)))) |
| @@ -2023,13 +2064,13 @@ | |||
| 2023 | (cons func args)) | 2064 | (cons func args)) |
| 2024 | (t | 2065 | (t |
| 2025 | (cons cfunc args))))))))) | 2066 | (cons cfunc args))))))))) |
| 2026 | (t (cons func args))))) | 2067 | (t (cons func (math-define-list (cdr exp))))))) ;;args |
| 2027 | ((symbolp exp) | 2068 | ((symbolp exp) |
| 2028 | (let ((prim (assq exp math-prim-vars)) | 2069 | (let ((prim (assq exp math-prim-vars)) |
| 2029 | (name (symbol-name exp))) | 2070 | (name (symbol-name exp))) |
| 2030 | (cond (prim | 2071 | (cond (prim |
| 2031 | (cdr prim)) | 2072 | (cdr prim)) |
| 2032 | ((memq exp exp-env) | 2073 | ((memq exp math-exp-env) |
| 2033 | exp) | 2074 | exp) |
| 2034 | ((string-match "-" name) | 2075 | ((string-match "-" name) |
| 2035 | exp) | 2076 | exp) |