Commit | Line | Data |
---|---|---|
136211a9 EZ |
1 | ;; Calculator for GNU Emacs, part II [calc-incom.el] |
2 | ;; Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc. | |
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 "(") | |
39 | (calc-push (list 'incomplete calc-complex-mode)))) | |
40 | ) | |
41 | ||
42 | (defun calc-end-complex () | |
43 | (interactive) | |
44 | (calc-comma t) | |
45 | (calc-wrapper | |
46 | (let ((top (calc-top 1))) | |
47 | (if (and (eq (car-safe top) 'incomplete) | |
48 | (eq (nth 1 top) 'intv)) | |
49 | (progn | |
50 | (if (< (length top) 4) | |
51 | (setq top (append top '((neg (var inf var-inf)))))) | |
52 | (if (< (length top) 5) | |
53 | (setq top (append top '((var inf var-inf))))) | |
54 | (calc-enter-result 1 "..)" (cdr top))) | |
55 | (if (not (and (eq (car-safe top) 'incomplete) | |
56 | (memq (nth 1 top) '(cplx polar)))) | |
57 | (error "Not entering a complex number")) | |
58 | (while (< (length top) 4) | |
59 | (setq top (append top '(0)))) | |
60 | (if (not (and (math-realp (nth 2 top)) | |
61 | (math-anglep (nth 3 top)))) | |
62 | (error "Components must be real")) | |
63 | (calc-enter-result 1 "()" (cdr top))))) | |
64 | ) | |
65 | ||
66 | (defun calc-begin-vector () | |
67 | (interactive) | |
68 | (calc-wrapper | |
69 | (if (or calc-algebraic-mode calc-incomplete-algebraic-mode) | |
70 | (calc-alg-entry "[") | |
71 | (calc-push '(incomplete vec)))) | |
72 | ) | |
73 | ||
74 | (defun calc-end-vector () | |
75 | (interactive) | |
76 | (calc-comma t) | |
77 | (calc-wrapper | |
78 | (let ((top (calc-top 1))) | |
79 | (if (and (eq (car-safe top) 'incomplete) | |
80 | (eq (nth 1 top) 'intv)) | |
81 | (progn | |
82 | (if (< (length top) 4) | |
83 | (setq top (append top '((neg (var inf var-inf)))))) | |
84 | (if (< (length top) 5) | |
85 | (setq top (append top '((var inf var-inf))))) | |
86 | (setcar (cdr (cdr top)) (1+ (nth 2 top))) | |
87 | (calc-enter-result 1 "..]" (cdr top))) | |
88 | (if (not (and (eq (car-safe top) 'incomplete) | |
89 | (eq (nth 1 top) 'vec))) | |
90 | (error "Not entering a vector")) | |
91 | (calc-pop-push-record 1 "[]" (cdr top))))) | |
92 | ) | |
93 | ||
94 | (defun calc-comma (&optional allow-polar) | |
95 | (interactive) | |
96 | (calc-wrapper | |
97 | (let ((num (calc-find-first-incomplete | |
98 | (nthcdr calc-stack-top calc-stack) 1))) | |
99 | (if (= num 0) | |
100 | (error "Not entering a vector or complex number")) | |
101 | (let* ((inc (calc-top num)) | |
102 | (stuff (calc-top-list (1- num))) | |
103 | (new (append inc stuff))) | |
104 | (if (and (null stuff) | |
105 | (not allow-polar) | |
106 | (or (eq (nth 1 inc) 'vec) | |
107 | (< (length new) 4))) | |
108 | (setq new (append new | |
109 | (if (= (length new) 2) | |
110 | '(0) | |
111 | (nthcdr (1- (length new)) new))))) | |
112 | (or allow-polar | |
113 | (if (eq (nth 1 new) 'polar) | |
114 | (setq new (append '(incomplete cplx) (cdr (cdr new)))) | |
115 | (if (eq (nth 1 new) 'intv) | |
116 | (setq new (append '(incomplete cplx) | |
117 | (cdr (cdr (cdr new)))))))) | |
118 | (if (and (memq (nth 1 new) '(cplx polar)) | |
119 | (> (length new) 4)) | |
120 | (error "Too many components in complex number")) | |
121 | (if (and (eq (nth 1 new) 'intv) | |
122 | (> (length new) 5)) | |
123 | (error "Too many components in interval form")) | |
124 | (calc-pop-push num new)))) | |
125 | ) | |
126 | ||
127 | (defun calc-semi () | |
128 | (interactive) | |
129 | (calc-wrapper | |
130 | (let ((num (calc-find-first-incomplete | |
131 | (nthcdr calc-stack-top calc-stack) 1))) | |
132 | (if (= num 0) | |
133 | (error "Not entering a vector or complex number")) | |
134 | (let ((inc (calc-top num)) | |
135 | (stuff (calc-top-list (1- num)))) | |
136 | (if (eq (nth 1 inc) 'cplx) | |
137 | (setq inc (append '(incomplete polar) (cdr (cdr inc)))) | |
138 | (if (eq (nth 1 inc) 'intv) | |
139 | (setq inc (append '(incomplete polar) (cdr (cdr (cdr inc))))))) | |
140 | (cond ((eq (nth 1 inc) 'polar) | |
141 | (let ((new (append inc stuff))) | |
142 | (if (> (length new) 4) | |
143 | (error "Too many components in complex number") | |
144 | (if (= (length new) 2) | |
145 | (setq new (append new '(1))))) | |
146 | (calc-pop-push num new))) | |
147 | ((null stuff) | |
148 | (if (> (length inc) 2) | |
149 | (if (math-vectorp (nth 2 inc)) | |
150 | (calc-comma) | |
151 | (calc-pop-push 1 | |
152 | (list 'incomplete 'vec (cdr (cdr inc))) | |
153 | (list 'incomplete 'vec))))) | |
154 | ((math-vectorp (car stuff)) | |
155 | (calc-comma)) | |
156 | ((eq (car-safe (car-safe (nth (+ num calc-stack-top) | |
157 | calc-stack))) 'incomplete) | |
158 | (calc-end-vector) | |
159 | (calc-comma) | |
160 | (let ((calc-algebraic-mode nil) | |
161 | (calc-incomplete-algebraic-mode nil)) | |
162 | (calc-begin-vector))) | |
163 | ((or (= (length inc) 2) | |
164 | (math-vectorp (nth 2 inc))) | |
165 | (calc-pop-push num | |
166 | (append inc (list (cons 'vec stuff))) | |
167 | (list 'incomplete 'vec))) | |
168 | (t | |
169 | (calc-pop-push num | |
170 | (list 'incomplete 'vec | |
171 | (cons 'vec (append (cdr (cdr inc)) stuff))) | |
172 | (list 'incomplete 'vec))))))) | |
173 | ) | |
174 | ||
175 | (defun calc-digit-dots () | |
176 | (if (eq calc-prev-char ?.) | |
177 | (progn | |
178 | (delete-backward-char 1) | |
179 | (if (calc-minibuffer-contains ".*\\.\\'") | |
180 | (delete-backward-char 1)) | |
181 | (setq calc-prev-char 'dots | |
182 | last-command-char 32) | |
183 | (if calc-prev-prev-char | |
184 | (calcDigit-nondigit) | |
185 | (setq calc-digit-value nil) | |
186 | (erase-buffer) | |
187 | (exit-minibuffer))) | |
188 | ;; just ignore extra decimal point, anticipating ".." | |
189 | (delete-backward-char 1)) | |
190 | ) | |
191 | ||
192 | (defun calc-dots () | |
193 | (interactive) | |
194 | (calc-wrapper | |
195 | (let ((num (calc-find-first-incomplete | |
196 | (nthcdr calc-stack-top calc-stack) 1))) | |
197 | (if (= num 0) | |
198 | (error "Not entering an interval form")) | |
199 | (let* ((inc (calc-top num)) | |
200 | (stuff (calc-top-list (1- num))) | |
201 | (new (append inc stuff))) | |
202 | (if (not (eq (nth 1 new) 'intv)) | |
203 | (setq new (append '(incomplete intv) | |
204 | (if (eq (nth 1 new) 'vec) '(2) '(0)) | |
205 | (cdr (cdr new))))) | |
206 | (if (and (null stuff) | |
207 | (= (length new) 3)) | |
208 | (setq new (append new '((neg (var inf var-inf)))))) | |
209 | (if (> (length new) 5) | |
210 | (error "Too many components in interval form")) | |
211 | (calc-pop-push num new)))) | |
212 | ) | |
213 | ||
214 | (defun calc-find-first-incomplete (stack n) | |
215 | (cond ((null stack) | |
216 | 0) | |
217 | ((eq (car-safe (car-safe (car stack))) 'incomplete) | |
218 | n) | |
219 | (t | |
220 | (calc-find-first-incomplete (cdr stack) (1+ n)))) | |
221 | ) | |
222 | ||
223 | (defun calc-incomplete-error (a) | |
224 | (cond ((memq (nth 1 a) '(cplx polar)) | |
225 | (error "Complex number is incomplete")) | |
226 | ((eq (nth 1 a) 'vec) | |
227 | (error "Vector is incomplete")) | |
228 | ((eq (nth 1 a) 'intv) | |
229 | (error "Interval form is incomplete")) | |
230 | (t (error "Object is incomplete"))) | |
231 | ) | |
232 | ||
233 | ||
234 |