1 ;;; -*- Mode: Lisp; Package: Maxima; Syntax: Common-Lisp; Base: 10 -*- ;;;;
2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3 ;;; The data in this file contains enhancements. ;;;;;
5 ;;; Copyright (c) 1984,1987 by William Schelter,University of Texas ;;;;;
6 ;;; All rights reserved ;;;;;
7 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9 ;;; 1001 TRANSLATE properties for everyone. ;;;
10 ;;; (c) Copyright 1980 Massachusetts Institute of Technology ;;;
11 ;;; Maintained by GJC ;;;
12 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16 (macsyma-module trans4
)
18 ;;; These are translation properties for various operators.
20 (def%tr mnctimes
(form)
21 (setq form
(tr-args (cdr form
)))
22 (cond ((= (length form
) 2)
23 `($any ncmul2 .
,form
))
25 `($any ncmuln
(list .
,form
) nil
))))
27 (def%tr mncexpt
(form)
28 `($any .
(ncpower ,@(tr-args (cdr form
)))))
30 (def%tr $remainder
(form)
31 (let ((n (tr-nargs-check form
'(2 . nil
)))
32 (tr-args (mapcar 'translate
(cdr form
))))
34 (eq (caar tr-args
) '$fixnum
)
35 (eq (car (cadr tr-args
)) '$fixnum
))
36 `($fixnum .
(rem ,(cdr (car tr-args
))
37 ,(cdr (cadr tr-args
)))))
39 (call-and-simp '$any
'$remainder
(mapcar 'cdr tr-args
))))))
42 `($any .
(simplify (list '($beta
) ,@(tr-args (cdr form
))))))
44 (def%tr mfactorial
(form)
45 (setq form
(translate (cadr form
)))
46 (cond ((eq (car form
) '$fixnum
)
47 `($number .
(factorial ,(cdr form
))))
49 `($any .
(simplify (list '(mfactorial) ,(cdr form
)))))))
51 (defun yuk-su-meta-prop (f form
)
54 (funcall f
(cdr form
))
55 `($any .
(progn ,@(mapcar #'patch-up-meval-in-fset
(nreverse meta-prop-l
))))))
57 (def%tr $matchdeclare
(form)
58 (do ((l (cdr form
) (cddr l
))
62 ,@(mapcar #'(lambda (var)
63 (dtranslate `(($define_variable
)
68 ,(dtranslate `((sub_$matchdeclare
) ,@(cdr form
))))))
71 ((eq (caaar l
) 'mlist
)
72 (setq vars
(append (cdar l
) vars
))))))
74 (def%tr sub_$matchdeclare
(form)
75 (yuk-su-meta-prop 'proc-$matchdeclare
`(($matchdeclare
) ,@(cdr form
))))
77 (def%tr $defmatch
(form)
78 (yuk-su-meta-prop 'proc-$defmatch form
))
80 (def%tr $tellsimp
(form)
81 (yuk-su-meta-prop 'proc-$tellsimp form
))
83 (def%tr $tellsimpafter
(form)
84 (yuk-su-meta-prop 'proc-$tellsimpafter form
))
86 (def%tr $defrule
(form)
87 (yuk-su-meta-prop 'proc-$defrule form
))
89 (defun patch-up-meval-in-fset (form)
90 (cond ((not (eq (car form
) 'fset
))
94 ;; FORM is always generated by META-FSET
95 (destructuring-let ((((nil ssymbol
) (nil (nil definition
) nil
)) (cdr form
)))
96 (unless (eq (car definition
) 'lambda
)
99 "PATCH-UP-MEVAL-IN-FSET: not a lambda expression: ~A"
101 (tr-format (intl:gettext
"note: translating rule or match ~:M ...~%") ssymbol
)
102 (setq definition
(lisp->lisp-tr-lambda definition
))
103 (if (null definition
)
105 ;; If the definition is a lambda form, just use defun
107 (if (eq (car definition
) 'lambda
)
108 `(defun ,ssymbol
,@(cdr definition
))
109 `(fset ',ssymbol
,definition
)))))))
111 (defvar lisp-
>lisp-tr-lambda t
)
113 (defun lisp->lisp-tr-lambda
(l)
114 ;; basically, a lisp->lisp translation, setting up
115 ;; the proper lambda contexts for the special forms,
116 ;; and calling TRANSLATE on the "lusers" generated by
117 ;; Fateman braindamage, (MEVAL '$A), (MEVAL '(($F) $X)).
118 (if lisp-
>lisp-tr-lambda
119 (catch 'lisp-
>lisp-tr-lambda
123 (defun tr-lisp->lisp
(exp)
125 (cdr (translate-atom exp
))
126 (let ((op (car exp
)))
128 (funcall (or (get op
'tr-lisp-
>lisp
) #'tr-lisp-
>lisp-default
)
130 (progn (tr-format (intl:gettext
"error: found a non-symbolic operator; I give up.~%"))
131 (throw 'lisp-
>lisp-tr-lambda
()))))))
133 (defun tr-lisp->lisp-default
(exp)
134 (cond ((macsyma-special-op-p (car exp
))
135 (tr-format (intl:gettext
"error: unhandled special operator ~:@M~%") (car exp
))
136 (throw 'lisp-
>lisp-tr-lambda
()))
138 (tr-lisp->lisp-fun exp
))))
140 (defun tr-lisp->lisp-fun
(exp)
141 (cons (car exp
) (maptr-lisp->lisp
(cdr exp
))))
143 (defun maptr-lisp->lisp
(l)
144 (mapcar #'tr-lisp-
>lisp l
))
145 (defun-prop (declare tr-lisp-
>lisp
) (form)
148 (defun-prop (lambda tr-lisp-
>lisp
) (form)
149 (destructuring-let (((() arglist . body
) form
))
150 (mapc #'tbind arglist
)
151 (setq body
(maptr-lisp->lisp body
))
152 `(lambda ,(tunbinds arglist
) ,@body
)))
154 (defun-prop (prog tr-lisp-
>lisp
) (form)
155 (destructuring-let (((() arglist . body
) form
))
156 (mapc #'tbind arglist
)
157 (setq body
(mapcar #'(lambda (x)
161 `(prog ,(tunbinds arglist
) ,@body
)))
163 ;;(DEFUN RETLIST FEXPR (L)
164 ;; (CONS '(MLIST SIMP)
165 ;; (MAPCAR #'(LAMBDA (Z) (LIST '(MEQUAL SIMP) Z (MEVAL Z))) L)))
167 (defun-prop (retlist tr-lisp-
>lisp
) (form)
168 `(retlist_tr ,@(mapcan #'(lambda (z)
169 (list `',z
(tr-lisp->lisp z
)))
172 (defun-prop (quote tr-lisp-
>lisp
) (form) form
)
173 (defprop catch tr-lisp-
>lisp-fun tr-lisp-
>lisp
)
174 (defprop throw tr-lisp-
>lisp-fun tr-lisp-
>lisp
)
175 (defprop return tr-lisp-
>lisp-fun tr-lisp-
>lisp
)
176 (defprop function tr-lisp-
>lisp-fun tr-lisp-
>lisp
)
178 (defun-prop (setq tr-lisp-
>lisp
) (form)
179 (do ((l (cdr form
) (cddr l
))
181 ((null l
) (cons 'setq
(nreverse n
)))
183 (push (tr-lisp->lisp
(cadr l
)) n
)))
185 (defun-prop (msetq tr-lisp-
>lisp
) (form)
186 (cdr (translate `((msetq) ,@(cdr form
)))))
188 (defun-prop (cond tr-lisp-
>lisp
) (form)
189 (cons 'cond
(mapcar #'maptr-lisp-
>lisp
(cdr form
))))
191 (defprop not tr-lisp-
>lisp-fun tr-lisp-
>lisp
)
192 (defprop and tr-lisp-
>lisp-fun tr-lisp-
>lisp
)
193 (defprop or tr-lisp-
>lisp-fun tr-lisp-
>lisp
)
195 (defvar unbound-meval-kludge-fix t
)
197 (defun-prop (meval tr-lisp-
>lisp
) (form)
198 (setq form
(cadr form
))
199 (cond ((and (not (atom form
))
200 (eq (car form
) 'quote
))
201 (cdr (translate (cadr form
))))
202 (unbound-meval-kludge-fix
203 ;; only case of unbound MEVAL is in output of DEFMATCH,
204 ;; and appears like a useless double-evaluation of arguments.
207 (tr-format (intl:gettext
"error: found unbound MEVAL; I give up.~%"))
208 (throw 'lisp-
>lisp-tr-lambda
()))))
210 (defun-prop (is tr-lisp-
>lisp
) (form)
211 (setq form
(cadr form
))
212 (cond ((and (not (atom form
))
213 (eq (car form
) 'quote
))
214 (cdr (translate `(($is
) ,(cadr form
)))))
216 (tr-format (intl:gettext
"error: found unbound IS; I give up.~%"))
217 (throw 'lisp-
>lisp-tr-lambda
()))))