Mercurial > emacs
annotate lisp/calc/calc-incom.el @ 41091:418fff19f92e
Minor clarification.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Thu, 15 Nov 2001 18:53:38 +0000 |
parents | 73f364fd8aaa |
children | fcd507927105 |
rev | line source |
---|---|
40785 | 1 ;; Calculator for GNU Emacs, part II [calc-incom.el] |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc. |
40785 | 3 ;; Written by Dave Gillespie, daveg@synaptics.com. |
4 | |
5 ;; This file is part of GNU Emacs. | |
6 | |
7 ;; GNU Emacs is distributed in the hope that it will be useful, | |
8 ;; but WITHOUT ANY WARRANTY. No author or distributor | |
9 ;; accepts responsibility to anyone for the consequences of using it | |
10 ;; or for whether it serves any particular purpose or works at all, | |
11 ;; unless he says so in writing. Refer to the GNU Emacs General Public | |
12 ;; License for full details. | |
13 | |
14 ;; Everyone is granted permission to copy, modify and redistribute | |
15 ;; GNU Emacs, but only under the conditions described in the | |
16 ;; GNU Emacs General Public License. A copy of this license is | |
17 ;; supposed to have been given to you along with GNU Emacs so you | |
18 ;; can know your rights and responsibilities. It should be in a | |
19 ;; file named COPYING. Among other things, the copyright notice | |
20 ;; and this notice must be preserved on all copies. | |
21 | |
22 | |
23 | |
24 ;; This file is autoloaded from calc-ext.el. | |
25 (require 'calc-ext) | |
26 | |
27 (require 'calc-macs) | |
28 | |
29 (defun calc-Need-calc-incom () nil) | |
30 | |
31 | |
32 ;;; Incomplete forms. | |
33 | |
34 (defun calc-begin-complex () | |
35 (interactive) | |
36 (calc-wrapper | |
37 (if (or calc-algebraic-mode calc-incomplete-algebraic-mode) | |
38 (calc-alg-entry "(") | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
39 (calc-push (list 'incomplete calc-complex-mode))))) |
40785 | 40 |
41 (defun calc-end-complex () | |
42 (interactive) | |
43 (calc-comma t) | |
44 (calc-wrapper | |
45 (let ((top (calc-top 1))) | |
46 (if (and (eq (car-safe top) 'incomplete) | |
47 (eq (nth 1 top) 'intv)) | |
48 (progn | |
49 (if (< (length top) 4) | |
50 (setq top (append top '((neg (var inf var-inf)))))) | |
51 (if (< (length top) 5) | |
52 (setq top (append top '((var inf var-inf))))) | |
53 (calc-enter-result 1 "..)" (cdr top))) | |
54 (if (not (and (eq (car-safe top) 'incomplete) | |
55 (memq (nth 1 top) '(cplx polar)))) | |
56 (error "Not entering a complex number")) | |
57 (while (< (length top) 4) | |
58 (setq top (append top '(0)))) | |
59 (if (not (and (math-realp (nth 2 top)) | |
60 (math-anglep (nth 3 top)))) | |
61 (error "Components must be real")) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
62 (calc-enter-result 1 "()" (cdr top)))))) |
40785 | 63 |
64 (defun calc-begin-vector () | |
65 (interactive) | |
66 (calc-wrapper | |
67 (if (or calc-algebraic-mode calc-incomplete-algebraic-mode) | |
68 (calc-alg-entry "[") | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
69 (calc-push '(incomplete vec))))) |
40785 | 70 |
71 (defun calc-end-vector () | |
72 (interactive) | |
73 (calc-comma t) | |
74 (calc-wrapper | |
75 (let ((top (calc-top 1))) | |
76 (if (and (eq (car-safe top) 'incomplete) | |
77 (eq (nth 1 top) 'intv)) | |
78 (progn | |
79 (if (< (length top) 4) | |
80 (setq top (append top '((neg (var inf var-inf)))))) | |
81 (if (< (length top) 5) | |
82 (setq top (append top '((var inf var-inf))))) | |
83 (setcar (cdr (cdr top)) (1+ (nth 2 top))) | |
84 (calc-enter-result 1 "..]" (cdr top))) | |
85 (if (not (and (eq (car-safe top) 'incomplete) | |
86 (eq (nth 1 top) 'vec))) | |
87 (error "Not entering a vector")) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
88 (calc-pop-push-record 1 "[]" (cdr top)))))) |
40785 | 89 |
90 (defun calc-comma (&optional allow-polar) | |
91 (interactive) | |
92 (calc-wrapper | |
93 (let ((num (calc-find-first-incomplete | |
94 (nthcdr calc-stack-top calc-stack) 1))) | |
95 (if (= num 0) | |
96 (error "Not entering a vector or complex number")) | |
97 (let* ((inc (calc-top num)) | |
98 (stuff (calc-top-list (1- num))) | |
99 (new (append inc stuff))) | |
100 (if (and (null stuff) | |
101 (not allow-polar) | |
102 (or (eq (nth 1 inc) 'vec) | |
103 (< (length new) 4))) | |
104 (setq new (append new | |
105 (if (= (length new) 2) | |
106 '(0) | |
107 (nthcdr (1- (length new)) new))))) | |
108 (or allow-polar | |
109 (if (eq (nth 1 new) 'polar) | |
110 (setq new (append '(incomplete cplx) (cdr (cdr new)))) | |
111 (if (eq (nth 1 new) 'intv) | |
112 (setq new (append '(incomplete cplx) | |
113 (cdr (cdr (cdr new)))))))) | |
114 (if (and (memq (nth 1 new) '(cplx polar)) | |
115 (> (length new) 4)) | |
116 (error "Too many components in complex number")) | |
117 (if (and (eq (nth 1 new) 'intv) | |
118 (> (length new) 5)) | |
119 (error "Too many components in interval form")) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
120 (calc-pop-push num new))))) |
40785 | 121 |
122 (defun calc-semi () | |
123 (interactive) | |
124 (calc-wrapper | |
125 (let ((num (calc-find-first-incomplete | |
126 (nthcdr calc-stack-top calc-stack) 1))) | |
127 (if (= num 0) | |
128 (error "Not entering a vector or complex number")) | |
129 (let ((inc (calc-top num)) | |
130 (stuff (calc-top-list (1- num)))) | |
131 (if (eq (nth 1 inc) 'cplx) | |
132 (setq inc (append '(incomplete polar) (cdr (cdr inc)))) | |
133 (if (eq (nth 1 inc) 'intv) | |
134 (setq inc (append '(incomplete polar) (cdr (cdr (cdr inc))))))) | |
135 (cond ((eq (nth 1 inc) 'polar) | |
136 (let ((new (append inc stuff))) | |
137 (if (> (length new) 4) | |
138 (error "Too many components in complex number") | |
139 (if (= (length new) 2) | |
140 (setq new (append new '(1))))) | |
141 (calc-pop-push num new))) | |
142 ((null stuff) | |
143 (if (> (length inc) 2) | |
144 (if (math-vectorp (nth 2 inc)) | |
145 (calc-comma) | |
146 (calc-pop-push 1 | |
147 (list 'incomplete 'vec (cdr (cdr inc))) | |
148 (list 'incomplete 'vec))))) | |
149 ((math-vectorp (car stuff)) | |
150 (calc-comma)) | |
151 ((eq (car-safe (car-safe (nth (+ num calc-stack-top) | |
152 calc-stack))) 'incomplete) | |
153 (calc-end-vector) | |
154 (calc-comma) | |
155 (let ((calc-algebraic-mode nil) | |
156 (calc-incomplete-algebraic-mode nil)) | |
157 (calc-begin-vector))) | |
158 ((or (= (length inc) 2) | |
159 (math-vectorp (nth 2 inc))) | |
160 (calc-pop-push num | |
161 (append inc (list (cons 'vec stuff))) | |
162 (list 'incomplete 'vec))) | |
163 (t | |
164 (calc-pop-push num | |
165 (list 'incomplete 'vec | |
166 (cons 'vec (append (cdr (cdr inc)) stuff))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
167 (list 'incomplete 'vec)))))))) |
40785 | 168 |
169 (defun calc-digit-dots () | |
170 (if (eq calc-prev-char ?.) | |
171 (progn | |
172 (delete-backward-char 1) | |
173 (if (calc-minibuffer-contains ".*\\.\\'") | |
174 (delete-backward-char 1)) | |
175 (setq calc-prev-char 'dots | |
176 last-command-char 32) | |
177 (if calc-prev-prev-char | |
178 (calcDigit-nondigit) | |
179 (setq calc-digit-value nil) | |
180 (erase-buffer) | |
181 (exit-minibuffer))) | |
182 ;; just ignore extra decimal point, anticipating ".." | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
183 (delete-backward-char 1))) |
40785 | 184 |
185 (defun calc-dots () | |
186 (interactive) | |
187 (calc-wrapper | |
188 (let ((num (calc-find-first-incomplete | |
189 (nthcdr calc-stack-top calc-stack) 1))) | |
190 (if (= num 0) | |
191 (error "Not entering an interval form")) | |
192 (let* ((inc (calc-top num)) | |
193 (stuff (calc-top-list (1- num))) | |
194 (new (append inc stuff))) | |
195 (if (not (eq (nth 1 new) 'intv)) | |
196 (setq new (append '(incomplete intv) | |
197 (if (eq (nth 1 new) 'vec) '(2) '(0)) | |
198 (cdr (cdr new))))) | |
199 (if (and (null stuff) | |
200 (= (length new) 3)) | |
201 (setq new (append new '((neg (var inf var-inf)))))) | |
202 (if (> (length new) 5) | |
203 (error "Too many components in interval form")) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
204 (calc-pop-push num new))))) |
40785 | 205 |
206 (defun calc-find-first-incomplete (stack n) | |
207 (cond ((null stack) | |
208 0) | |
209 ((eq (car-safe (car-safe (car stack))) 'incomplete) | |
210 n) | |
211 (t | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
212 (calc-find-first-incomplete (cdr stack) (1+ n))))) |
40785 | 213 |
214 (defun calc-incomplete-error (a) | |
215 (cond ((memq (nth 1 a) '(cplx polar)) | |
216 (error "Complex number is incomplete")) | |
217 ((eq (nth 1 a) 'vec) | |
218 (error "Vector is incomplete")) | |
219 ((eq (nth 1 a) 'intv) | |
220 (error "Interval form is incomplete")) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
221 (t (error "Object is incomplete")))) |
40785 | 222 |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
223 ;;; calc-incom.el ends here |