Mercurial > emacs
comparison lisp/calc/calc-vec.el @ 88155:d7ddb3e565de
sync with trunk
author | Henrik Enberg <henrik.enberg@telia.com> |
---|---|
date | Mon, 16 Jan 2006 00:03:54 +0000 |
parents | 0d8b17d428b5 |
children |
comparison
equal
deleted
inserted
replaced
88154:8ce476d3ba36 | 88155:d7ddb3e565de |
---|---|
1 ;;; calc-vec.el --- vector functions for Calc | 1 ;;; calc-vec.el --- vector functions for Calc |
2 | 2 |
3 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001, 2002, 2003, 2004, |
4 ;; 2005 Free Software Foundation, Inc. | |
4 | 5 |
5 ;; Author: David Gillespie <daveg@synaptics.com> | 6 ;; Author: David Gillespie <daveg@synaptics.com> |
6 ;; Maintainers: D. Goel <deego@gnufans.org> | 7 ;; Maintainer: Jay Belanger <belanger@truman.edu> |
7 ;; Colin Walters <walters@debian.org> | |
8 | 8 |
9 ;; This file is part of GNU Emacs. | 9 ;; This file is part of GNU Emacs. |
10 | 10 |
11 ;; GNU Emacs is distributed in the hope that it will be useful, | 11 ;; GNU Emacs is distributed in the hope that it will be useful, |
12 ;; but WITHOUT ANY WARRANTY. No author or distributor | 12 ;; but WITHOUT ANY WARRANTY. No author or distributor |
26 ;;; Commentary: | 26 ;;; Commentary: |
27 | 27 |
28 ;;; Code: | 28 ;;; Code: |
29 | 29 |
30 ;; This file is autoloaded from calc-ext.el. | 30 ;; This file is autoloaded from calc-ext.el. |
31 | |
31 (require 'calc-ext) | 32 (require 'calc-ext) |
32 | |
33 (require 'calc-macs) | 33 (require 'calc-macs) |
34 | |
35 (defun calc-Need-calc-vec () nil) | |
36 | |
37 | 34 |
38 (defun calc-display-strings (n) | 35 (defun calc-display-strings (n) |
39 (interactive "P") | 36 (interactive "P") |
40 (calc-wrapper | 37 (calc-wrapper |
41 (message (if (calc-change-mode 'calc-display-strings n t t) | 38 (message (if (calc-change-mode 'calc-display-strings n t t) |
1099 (defun calcFunc-rsort (vec) ; [Public] | 1096 (defun calcFunc-rsort (vec) ; [Public] |
1100 (if (math-vectorp vec) | 1097 (if (math-vectorp vec) |
1101 (cons 'vec (nreverse (sort (copy-sequence (cdr vec)) 'math-beforep))) | 1098 (cons 'vec (nreverse (sort (copy-sequence (cdr vec)) 'math-beforep))) |
1102 (math-reject-arg vec 'vectorp))) | 1099 (math-reject-arg vec 'vectorp))) |
1103 | 1100 |
1104 (defun calcFunc-grade (grade-vec) | 1101 ;; The variable math-grade-vec is local to calcFunc-grade and |
1105 (if (math-vectorp grade-vec) | 1102 ;; calcFunc-rgrade, but is used by math-grade-beforep, which is called |
1106 (let* ((len (1- (length grade-vec)))) | 1103 ;; by calcFunc-grade and calcFunc-rgrade. |
1104 (defvar math-grade-vec) | |
1105 | |
1106 (defun calcFunc-grade (math-grade-vec) | |
1107 (if (math-vectorp math-grade-vec) | |
1108 (let* ((len (1- (length math-grade-vec)))) | |
1107 (cons 'vec (sort (cdr (calcFunc-index len)) 'math-grade-beforep))) | 1109 (cons 'vec (sort (cdr (calcFunc-index len)) 'math-grade-beforep))) |
1108 (math-reject-arg grade-vec 'vectorp))) | 1110 (math-reject-arg math-grade-vec 'vectorp))) |
1109 | 1111 |
1110 (defun calcFunc-rgrade (grade-vec) | 1112 (defun calcFunc-rgrade (math-grade-vec) |
1111 (if (math-vectorp grade-vec) | 1113 (if (math-vectorp math-grade-vec) |
1112 (let* ((len (1- (length grade-vec)))) | 1114 (let* ((len (1- (length math-grade-vec)))) |
1113 (cons 'vec (nreverse (sort (cdr (calcFunc-index len)) | 1115 (cons 'vec (nreverse (sort (cdr (calcFunc-index len)) |
1114 'math-grade-beforep)))) | 1116 'math-grade-beforep)))) |
1115 (math-reject-arg grade-vec 'vectorp))) | 1117 (math-reject-arg math-grade-vec 'vectorp))) |
1116 | 1118 |
1117 (defun math-grade-beforep (i j) | 1119 (defun math-grade-beforep (i j) |
1118 (math-beforep (nth i grade-vec) (nth j grade-vec))) | 1120 (math-beforep (nth i math-grade-vec) (nth j math-grade-vec))) |
1119 | 1121 |
1120 | 1122 |
1121 ;;; Compile a histogram of data from a vector. | 1123 ;;; Compile a histogram of data from a vector. |
1122 (defun calcFunc-histogram (vec wts &optional n) | 1124 (defun calcFunc-histogram (vec wts &optional n) |
1123 (or n (setq n wts wts 1)) | 1125 (or n (setq n wts wts 1)) |
1459 (math-reject-arg b "*Three-vector expected")) | 1461 (math-reject-arg b "*Three-vector expected")) |
1460 (math-reject-arg a "*Three-vector expected"))) | 1462 (math-reject-arg a "*Three-vector expected"))) |
1461 | 1463 |
1462 | 1464 |
1463 | 1465 |
1464 | 1466 ;; The variable math-rb-close is local to math-read-brackets, but |
1465 | 1467 ;; is used by math-read-vector, which is called (directly and |
1466 (defun math-read-brackets (space-sep close) | 1468 ;; indirectly) by math-read-brackets. |
1469 (defvar math-rb-close) | |
1470 | |
1471 ;; The next few variables are local to math-read-exprs in calc-aent.el | |
1472 ;; and math-read-expr in calc-ext.el, but are set in functions they call. | |
1473 (defvar math-exp-pos) | |
1474 (defvar math-exp-str) | |
1475 (defvar math-exp-old-pos) | |
1476 (defvar math-exp-token) | |
1477 (defvar math-exp-keep-spaces) | |
1478 (defvar math-expr-data) | |
1479 | |
1480 (defun math-read-brackets (space-sep math-rb-close) | |
1467 (and space-sep (setq space-sep (not (math-check-for-commas)))) | 1481 (and space-sep (setq space-sep (not (math-check-for-commas)))) |
1468 (math-read-token) | 1482 (math-read-token) |
1469 (while (eq exp-token 'space) | 1483 (while (eq math-exp-token 'space) |
1470 (math-read-token)) | 1484 (math-read-token)) |
1471 (if (or (equal exp-data close) | 1485 (if (or (equal math-expr-data math-rb-close) |
1472 (eq exp-token 'end)) | 1486 (eq math-exp-token 'end)) |
1473 (progn | 1487 (progn |
1474 (math-read-token) | 1488 (math-read-token) |
1475 '(vec)) | 1489 '(vec)) |
1476 (let ((save-exp-pos exp-pos) | 1490 (let ((save-exp-pos math-exp-pos) |
1477 (save-exp-old-pos exp-old-pos) | 1491 (save-exp-old-pos math-exp-old-pos) |
1478 (save-exp-token exp-token) | 1492 (save-exp-token math-exp-token) |
1479 (save-exp-data exp-data) | 1493 (save-exp-data math-expr-data) |
1480 (vals (let ((exp-keep-spaces space-sep)) | 1494 (vals (let ((math-exp-keep-spaces space-sep)) |
1481 (if (or (equal exp-data "\\dots") | 1495 (if (or (equal math-expr-data "\\dots") |
1482 (equal exp-data "\\ldots")) | 1496 (equal math-expr-data "\\ldots")) |
1483 '(vec (neg (var inf var-inf))) | 1497 '(vec (neg (var inf var-inf))) |
1484 (catch 'syntax (math-read-vector)))))) | 1498 (catch 'syntax (math-read-vector)))))) |
1485 (if (stringp vals) | 1499 (if (stringp vals) |
1486 (if space-sep | 1500 (if space-sep |
1487 (let ((error-exp-pos exp-pos) | 1501 (let ((error-exp-pos math-exp-pos) |
1488 (error-exp-old-pos exp-old-pos) | 1502 (error-exp-old-pos math-exp-old-pos) |
1489 vals2) | 1503 vals2) |
1490 (setq exp-pos save-exp-pos | 1504 (setq math-exp-pos save-exp-pos |
1491 exp-old-pos save-exp-old-pos | 1505 math-exp-old-pos save-exp-old-pos |
1492 exp-token save-exp-token | 1506 math-exp-token save-exp-token |
1493 exp-data save-exp-data) | 1507 math-expr-data save-exp-data) |
1494 (let ((exp-keep-spaces nil)) | 1508 (let ((math-exp-keep-spaces nil)) |
1495 (setq vals2 (catch 'syntax (math-read-vector)))) | 1509 (setq vals2 (catch 'syntax (math-read-vector)))) |
1496 (if (and (not (stringp vals2)) | 1510 (if (and (not (stringp vals2)) |
1497 (or (assoc exp-data '(("\\ldots") ("\\dots") (";"))) | 1511 (or (assoc math-expr-data '(("\\ldots") ("\\dots") (";"))) |
1498 (equal exp-data close) | 1512 (equal math-expr-data math-rb-close) |
1499 (eq exp-token 'end))) | 1513 (eq math-exp-token 'end))) |
1500 (setq space-sep nil | 1514 (setq space-sep nil |
1501 vals vals2) | 1515 vals vals2) |
1502 (setq exp-pos error-exp-pos | 1516 (setq math-exp-pos error-exp-pos |
1503 exp-old-pos error-exp-old-pos) | 1517 math-exp-old-pos error-exp-old-pos) |
1504 (throw 'syntax vals))) | 1518 (throw 'syntax vals))) |
1505 (throw 'syntax vals))) | 1519 (throw 'syntax vals))) |
1506 (if (or (equal exp-data "\\dots") | 1520 (if (or (equal math-expr-data "\\dots") |
1507 (equal exp-data "\\ldots")) | 1521 (equal math-expr-data "\\ldots")) |
1508 (progn | 1522 (progn |
1509 (math-read-token) | 1523 (math-read-token) |
1510 (setq vals (if (> (length vals) 2) | 1524 (setq vals (if (> (length vals) 2) |
1511 (cons 'calcFunc-mul (cdr vals)) (nth 1 vals))) | 1525 (cons 'calcFunc-mul (cdr vals)) (nth 1 vals))) |
1512 (let ((exp2 (if (or (equal exp-data close) | 1526 (let ((exp2 (if (or (equal math-expr-data math-rb-close) |
1513 (equal exp-data ")") | 1527 (equal math-expr-data ")") |
1514 (eq exp-token 'end)) | 1528 (eq math-exp-token 'end)) |
1515 '(var inf var-inf) | 1529 '(var inf var-inf) |
1516 (math-read-expr-level 0)))) | 1530 (math-read-expr-level 0)))) |
1517 (setq vals | 1531 (setq vals |
1518 (list 'intv | 1532 (list 'intv |
1519 (if (equal exp-data ")") 2 3) | 1533 (if (equal math-expr-data ")") 2 3) |
1520 vals | 1534 vals |
1521 exp2))) | 1535 exp2))) |
1522 (if (not (or (equal exp-data close) | 1536 (if (not (or (equal math-expr-data math-rb-close) |
1523 (equal exp-data ")") | 1537 (equal math-expr-data ")") |
1524 (eq exp-token 'end))) | 1538 (eq math-exp-token 'end))) |
1525 (throw 'syntax "Expected `]'"))) | 1539 (throw 'syntax "Expected `]'"))) |
1526 (if (equal exp-data ";") | 1540 (if (equal math-expr-data ";") |
1527 (let ((exp-keep-spaces space-sep)) | 1541 (let ((math-exp-keep-spaces space-sep)) |
1528 (setq vals (cons 'vec (math-read-matrix (list vals)))))) | 1542 (setq vals (cons 'vec (math-read-matrix (list vals)))))) |
1529 (if (not (or (equal exp-data close) | 1543 (if (not (or (equal math-expr-data math-rb-close) |
1530 (eq exp-token 'end))) | 1544 (eq math-exp-token 'end))) |
1531 (throw 'syntax "Expected `]'"))) | 1545 (throw 'syntax "Expected `]'"))) |
1532 (or (eq exp-token 'end) | 1546 (or (eq math-exp-token 'end) |
1533 (math-read-token)) | 1547 (math-read-token)) |
1534 vals))) | 1548 vals))) |
1535 | 1549 |
1536 (defun math-check-for-commas (&optional balancing) | 1550 (defun math-check-for-commas (&optional balancing) |
1537 (let ((count 0) | 1551 (let ((count 0) |
1538 (pos (1- exp-pos))) | 1552 (pos (1- math-exp-pos))) |
1539 (while (and (>= count 0) | 1553 (while (and (>= count 0) |
1540 (setq pos (string-match | 1554 (setq pos (string-match |
1541 (if balancing "[],[{}()<>]" "[],[{}()]") | 1555 (if balancing "[],[{}()<>]" "[],[{}()]") |
1542 exp-str (1+ pos))) | 1556 math-exp-str (1+ pos))) |
1543 (or (/= (aref exp-str pos) ?,) (> count 0) balancing)) | 1557 (or (/= (aref math-exp-str pos) ?,) (> count 0) balancing)) |
1544 (cond ((memq (aref exp-str pos) '(?\[ ?\{ ?\( ?\<)) | 1558 (cond ((memq (aref math-exp-str pos) '(?\[ ?\{ ?\( ?\<)) |
1545 (setq count (1+ count))) | 1559 (setq count (1+ count))) |
1546 ((memq (aref exp-str pos) '(?\] ?\} ?\) ?\>)) | 1560 ((memq (aref math-exp-str pos) '(?\] ?\} ?\) ?\>)) |
1547 (setq count (1- count))))) | 1561 (setq count (1- count))))) |
1548 (if balancing | 1562 (if balancing |
1549 pos | 1563 pos |
1550 (and pos (= (aref exp-str pos) ?,))))) | 1564 (and pos (= (aref math-exp-str pos) ?,))))) |
1551 | 1565 |
1552 (defun math-read-vector () | 1566 (defun math-read-vector () |
1553 (let* ((val (list (math-read-expr-level 0))) | 1567 (let* ((val (list (math-read-expr-level 0))) |
1554 (last val)) | 1568 (last val)) |
1555 (while (progn | 1569 (while (progn |
1556 (while (eq exp-token 'space) | 1570 (while (eq math-exp-token 'space) |
1557 (math-read-token)) | 1571 (math-read-token)) |
1558 (and (not (eq exp-token 'end)) | 1572 (and (not (eq math-exp-token 'end)) |
1559 (not (equal exp-data ";")) | 1573 (not (equal math-expr-data ";")) |
1560 (not (equal exp-data close)) | 1574 (not (equal math-expr-data math-rb-close)) |
1561 (not (equal exp-data "\\dots")) | 1575 (not (equal math-expr-data "\\dots")) |
1562 (not (equal exp-data "\\ldots")))) | 1576 (not (equal math-expr-data "\\ldots")))) |
1563 (if (equal exp-data ",") | 1577 (if (equal math-expr-data ",") |
1564 (math-read-token)) | 1578 (math-read-token)) |
1565 (while (eq exp-token 'space) | 1579 (while (eq math-exp-token 'space) |
1566 (math-read-token)) | 1580 (math-read-token)) |
1567 (let ((rest (list (math-read-expr-level 0)))) | 1581 (let ((rest (list (math-read-expr-level 0)))) |
1568 (setcdr last rest) | 1582 (setcdr last rest) |
1569 (setq last rest))) | 1583 (setq last rest))) |
1570 (cons 'vec val))) | 1584 (cons 'vec val))) |
1571 | 1585 |
1572 (defun math-read-matrix (mat) | 1586 (defun math-read-matrix (mat) |
1573 (while (equal exp-data ";") | 1587 (while (equal math-expr-data ";") |
1574 (math-read-token) | 1588 (math-read-token) |
1575 (while (eq exp-token 'space) | 1589 (while (eq math-exp-token 'space) |
1576 (math-read-token)) | 1590 (math-read-token)) |
1577 (setq mat (nconc mat (list (math-read-vector))))) | 1591 (setq mat (nconc mat (list (math-read-vector))))) |
1578 mat) | 1592 mat) |
1579 | 1593 |
1594 (provide 'calc-vec) | |
1595 | |
1596 ;;; arch-tag: 7902a7af-ec69-440a-8635-ebb4db263402 | |
1580 ;;; calc-vec.el ends here | 1597 ;;; calc-vec.el ends here |