Case-sensitivity goals, policy and implementation



>>>>> "James" == James Amundson <amundson@users.sourceforge.net> writes:

    James> Yes, that would be great. I won't declare victory until I see the
    James> implementation, though. I spent a little bit of time last night trying
    James> to figure out where to stick the readtable-changing statements in the
    James> maxima source, but I quickly became confused. If you feel like giving it
    James> a shot, please do.

I'm attaching a patch that implements this.  This is just a proof of
concept to make the repl work.  But the transcript below shows that it
basically works.  The tests don't pass (and don't even run to
completion), so there's still a lot of work left.

    (%i1) sin(%pi);

    (%o1)                                  0
    (%i2) cos(%pi);

    (%o2)                                 - 1
    (%i3) Sin(%pi);

    (%o3)                              Sin(%pi)
    (%i4) bessel_j(2,3);

    (%o4)                           bessel_j(2, 3)
    (%i5) bessel_j(2,3.0);

    (%o5)                          .4860912605858912
    (%i6) diff(sin(x),x);

    (%o6)                               cos(x)
    (%i7) F:G*m*MM/(r-RR)^2;

                                        G m MM
    (%o7)                              ---------
                                               2
                                       (r - RR)
    (%i8) to_lisp();

    Type (to-maxima) to restart

    MAXIMA> $%o7
    ((MTIMES SIMP) |$g| $M |$mm|
             ((MEXPT SIMP) ((MPLUS SIMP) $R ((MTIMES SIMP) -1 |$rr|)) -2))
    MAXIMA> (readtable-case *readtable*)
    :UPCASE
    MAXIMA> (to-maxima)
    Returning to Maxima
    (%o8)                                true
    (%i9) exp(%i*%pi);

    (%o9)                                 - 1
    (%i10) %I;

    (%o10)                                %I
    (%i11) exp(%I*%pi);

                                         %pi %I
    (%o11)                             %e
    (%i12) 

Ray

Index: src/commac.lisp
===================================================================
RCS file: /cvsroot/maxima/maxima/src/commac.lisp,v
retrieving revision 1.16
diff -u -r1.16 commac.lisp
--- src/commac.lisp	4 Oct 2004 02:25:55 -0000	1.16
+++ src/commac.lisp	13 Oct 2004 18:22:06 -0000
@@ -468,7 +468,8 @@
   (let* (#+(and gcl (not gmp)) (big-chunk-size 120)
 	   #+(and gcl (not gmp)) (tentochunksize (expt 10 big-chunk-size))
 	   string)
-    (cond ((symbolp symb)(setq string (symbol-name symb)))
+    (cond ((symbolp symb)
+	   (setq string (write-to-string symb :case :upcase)))
 	  ((floatp symb)
 	   (let ((a (abs symb)))
 	     (cond ((or (eql a 0.0)
@@ -512,6 +513,7 @@
 
 (defun implode (lis) (implode1 lis nil))
 
+
 (defun implode1 (lis upcase &aux (ar *string-for-implode*) (leng 0))
   (declare (type string ar) (fixnum leng))
   (or (> (array-total-size ar) (setq leng (length lis)))
@@ -523,34 +525,11 @@
 	 (cond ((typep v 'character))
 	       ((symbolp v) (setq v (aref (symbol-name v) 0)))
 	       ((numberp v) (setq v (code-char v))))
-	 (setf (aref ar i) (if upcase (char-upcase v) v)))
-  (intern ar))
+	 (setf (aref ar i) v))
+  (intern (symbol-name (read-from-string ar)) :maxima))
 
 (defun bothcase-implode (lis  &aux tem )
-  (cond ((not (eql (car lis) #\$))
-	 (return-from bothcase-implode (implode1 lis nil))))
-  (multiple-value-bind
-	(sym there)
-      (implode1 lis nil)
-    (cond (there (if (setq tem (get sym 'upcase)) tem sym))
-	  (t
-	   ;; if all upper case lets not bother interning...
-	   (sloop for v in lis with haslower
-		  when (not (eql (char-upcase v) v))
-		  do (setq haslower t) (loop-finish)
-		  finally (or haslower (return-from bothcase-implode sym)))
-	   (multiple-value-bind
-		 (symup there)
-	       (implode1 lis t)
-	     (cond ((and there (or
-				;; not single symbols
-				(cddr lis)
-				(fboundp symup) (symbol-plist symup)))
-		       
-		    (setf (get sym 'upcase) symup)
-		    symup)
-		   (t (or there (unintern symup))
-		      sym)))))))
+  (implode1 lis nil))
 
 
 (defun explode (symb &aux tem)
Index: src/init-cl.lisp
===================================================================
RCS file: /cvsroot/maxima/maxima/src/init-cl.lisp,v
retrieving revision 1.39
diff -u -r1.39 init-cl.lisp
--- src/init-cl.lisp	4 Oct 2004 02:25:55 -0000	1.39
+++ src/init-cl.lisp	13 Oct 2004 18:22:06 -0000
@@ -405,6 +405,7 @@
   (setf *debugger-hook* #'maxima-lisp-debugger)
   (let ((input-stream *standard-input*)
 	(batch-flag nil))
+    (setf (readtable-case *readtable*) :invert)
     #+allegro
     (progn
       (set-readtable-for-macsyma)
@@ -429,7 +430,8 @@
 
 (defun $to_lisp ()
   (format t "~&Type (to-maxima) to restart~%")
-  (let ((old-debugger-hook *debugger-hook*))
+  (let ((old-debugger-hook *debugger-hook*)
+	(*readtable* (copy-readtable nil)))
     (catch 'to-maxima
       (unwind-protect
 	   (maxima-read-eval-print-loop)
Index: src/suprv1.lisp
===================================================================
RCS file: /cvsroot/maxima/maxima/src/suprv1.lisp,v
retrieving revision 1.17
diff -u -r1.17 suprv1.lisp
--- src/suprv1.lisp	4 Oct 2004 02:25:54 -0000	1.17
+++ src/suprv1.lisp	13 Oct 2004 18:22:07 -0000
@@ -159,19 +159,20 @@
 (defmvar $% '$% "The last out-line computed, corresponds to lisp *"
 	 no-reset)
 
-(defmvar $inchar '|$%i|
+(defmvar $inchar '$%I
   "The alphabetic prefix of the names of expressions typed by the user.")
 ;;; jfa: begin case-sensitivity hack
 ;;;      delete this when case-sensitivity is fixed!!!! 05/11/2004
 
+#+nil
 (defmvar |$%i| '|$%I|
   "%i = %I until maxima's case behavior is fixed.")
 ;;; jfa: end case-sensitivity hack
 
-(defmvar $outchar '|$%o|
+(defmvar $outchar '$%O
   "The alphabetic prefix of the names of expressions returned by the system.")
 
-(defmvar $linechar '|$%t|
+(defmvar $linechar '$%T
   "The alphabetic prefix of the names of intermediate displayed expressions.")
 
 (defmvar $linenum 1 "the line number of the last expression."