Ask for the syntax of representing operators in Common-Lisp
- Subject: Ask for the syntax of representing operators in Common-Lisp
- From: Richard Fateman
- Date: Wed, 12 Jul 2006 15:46:44 -0700
Try this, which changes x/y to (/ x y) instead of (* x (expt y -1)).
The trick is to use nformat.
(defun $common_lisp (e)
(let (($listconstvars nil))
(print `(lambda ,(sort (mapcar 'stripdollar (margs ($listofvars e)))
'string<) ,(tocl (nformat($ratdisrep e)))))
'$done))
(setf (get 'mplus 'cl-function) '+)
(setf (get 'mtimes 'cl-function) '*)
(setf (get 'mexpt 'cl-function) 'expt)
(setf (get 'mquotient 'cl-function) '/)
(defun mapatom-to-cl (e)
(cond ((eq e '$%i) (complex 0 1))
(($ratnump e) `(/ ,($num e) ,($denom e)))
((eq e '$%pi) pi)
(($constantp e) ($float e)) ;; converts big floats to doubles
(t (stripdollar e))))
(defun tocl (e)
(if ($mapatom e) (mapatom-to-cl e)
`(,(or (get (mop e) 'cl-function) (stripdollar (mop e))) ,@(mapcar
'tocl (margs e)))))