Commit | Line | Data |
---|---|---|
3132f345 CW |
1 | ;;; calc-incom.el --- complex data type input functions for Calc |
2 | ||
ba318903 | 3 | ;; Copyright (C) 1990-1993, 2001-2014 Free Software Foundation, Inc. |
3132f345 CW |
4 | |
5 | ;; Author: David Gillespie <daveg@synaptics.com> | |
e8fff8ed | 6 | ;; Maintainer: Jay Belanger <jay.p.belanger@gmail.com> |
136211a9 EZ |
7 | |
8 | ;; This file is part of GNU Emacs. | |
9 | ||
662c9c64 | 10 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
7c671b23 | 11 | ;; it under the terms of the GNU General Public License as published by |
662c9c64 GM |
12 | ;; the Free Software Foundation, either version 3 of the License, or |
13 | ;; (at your option) any later version. | |
7c671b23 | 14 | |
136211a9 | 15 | ;; GNU Emacs is distributed in the hope that it will be useful, |
7c671b23 GM |
16 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | ;; GNU General Public License for more details. | |
19 | ||
20 | ;; You should have received a copy of the GNU General Public License | |
662c9c64 | 21 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
136211a9 | 22 | |
3132f345 | 23 | ;;; Commentary: |
136211a9 | 24 | |
3132f345 | 25 | ;;; Code: |
136211a9 EZ |
26 | |
27 | ;; This file is autoloaded from calc-ext.el. | |
136211a9 | 28 | |
c66b0f18 | 29 | (require 'calc-ext) |
136211a9 EZ |
30 | (require 'calc-macs) |
31 | ||
136211a9 EZ |
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 "(") | |
bf77c646 | 39 | (calc-push (list 'incomplete calc-complex-mode))))) |
136211a9 EZ |
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")) | |
bf77c646 | 62 | (calc-enter-result 1 "()" (cdr top)))))) |
136211a9 EZ |
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 "[") | |
bf77c646 | 69 | (calc-push '(incomplete vec))))) |
136211a9 EZ |
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")) | |
bf77c646 | 88 | (calc-pop-push-record 1 "[]" (cdr top)))))) |
136211a9 EZ |
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")) | |
bf77c646 | 120 | (calc-pop-push num new))))) |
136211a9 EZ |
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))) | |
bf77c646 | 167 | (list 'incomplete 'vec)))))))) |
136211a9 | 168 | |
53cbeb3d JB |
169 | ;; The following variables are initially declared in calc.el, |
170 | ;; but are used by calc-digit-dots. | |
171 | (defvar calc-prev-char) | |
172 | (defvar calc-prev-prev-char) | |
173 | (defvar calc-digit-value) | |
174 | ||
136211a9 EZ |
175 | (defun calc-digit-dots () |
176 | (if (eq calc-prev-char ?.) | |
177 | (progn | |
d355a0b7 | 178 | (delete-char -1) |
136211a9 | 179 | (if (calc-minibuffer-contains ".*\\.\\'") |
d355a0b7 | 180 | (delete-char -1)) |
136211a9 | 181 | (setq calc-prev-char 'dots |
e93c003e | 182 | last-command-event 32) |
136211a9 EZ |
183 | (if calc-prev-prev-char |
184 | (calcDigit-nondigit) | |
185 | (setq calc-digit-value nil) | |
b89c5b71 JB |
186 | (let ((inhibit-read-only t)) |
187 | (erase-buffer)) | |
136211a9 EZ |
188 | (exit-minibuffer))) |
189 | ;; just ignore extra decimal point, anticipating ".." | |
d355a0b7 | 190 | (delete-char -1))) |
136211a9 EZ |
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")) | |
bf77c646 | 211 | (calc-pop-push num new))))) |
136211a9 EZ |
212 | |
213 | (defun calc-find-first-incomplete (stack n) | |
214 | (cond ((null stack) | |
215 | 0) | |
216 | ((eq (car-safe (car-safe (car stack))) 'incomplete) | |
217 | n) | |
218 | (t | |
bf77c646 | 219 | (calc-find-first-incomplete (cdr stack) (1+ n))))) |
136211a9 EZ |
220 | |
221 | (defun calc-incomplete-error (a) | |
222 | (cond ((memq (nth 1 a) '(cplx polar)) | |
223 | (error "Complex number is incomplete")) | |
224 | ((eq (nth 1 a) 'vec) | |
225 | (error "Vector is incomplete")) | |
226 | ((eq (nth 1 a) 'intv) | |
227 | (error "Interval form is incomplete")) | |
bf77c646 | 228 | (t (error "Object is incomplete")))) |
136211a9 | 229 | |
c66b0f18 JB |
230 | (provide 'calc-incom) |
231 | ||
bf77c646 | 232 | ;;; calc-incom.el ends here |