# HG changeset patch # User Aidan Kehoe # Date 1281875350 -3600 # Node ID 808131ba4a5737d4eb0ecee301c98cba84dab91c # Parent f3eca926258e6ae9d6a7af522c576d80a377ac2c Print symbols with ratio-like names and the associated ratios distinctly. src/ChangeLog addition: 2010-08-15 Aidan Kehoe * print.c (print_symbol): Escape any symbols that look like ratios, in the same way we do symbols that look like floats or integers. Prevents confusion in the Lisp reader. * lread.c (isratio_string): Make this available even on builds without HAVE_RATIO, so we can print symbols that look like ratios with the appropriate escapes. * lisp.h: Make isratio_string available even if HAVE_RATIO is not defined. tests/ChangeLog addition: 2010-08-15 Aidan Kehoe * automated/lisp-tests.el: Test that symbols with names that look like ratios are printed distinctly from the equivalent ratios. diff -r f3eca926258e -r 808131ba4a57 src/ChangeLog --- a/src/ChangeLog Sat Jul 24 17:38:35 2010 +0100 +++ b/src/ChangeLog Sun Aug 15 13:29:10 2010 +0100 @@ -1,3 +1,15 @@ +2010-08-15 Aidan Kehoe + + * print.c (print_symbol): + Escape any symbols that look like ratios, in the same way we do + symbols that look like floats or integers. Prevents confusion in + the Lisp reader. + * lread.c (isratio_string): Make this available even on builds + without HAVE_RATIO, so we can print symbols that look like ratios + with the appropriate escapes. + * lisp.h: + Make isratio_string available even if HAVE_RATIO is not defined. + 2010-07-24 Aidan Kehoe * lisp.h (PARSE_KEYWORDS): diff -r f3eca926258e -r 808131ba4a57 src/lisp.h --- a/src/lisp.h Sat Jul 24 17:38:35 2010 +0100 +++ b/src/lisp.h Sun Aug 15 13:29:10 2010 +0100 @@ -5355,9 +5355,7 @@ int locate_file (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object *, int); EXFUN (Flocate_file_clear_hashing, 1); int isfloat_string (const char *); -#ifdef HAVE_RATIO int isratio_string (const char *); -#endif /* Well, I've decided to enable this. -- ben */ /* And I've decided to make it work right. -- sb */ diff -r f3eca926258e -r 808131ba4a57 src/lread.c --- a/src/lread.c Sat Jul 24 17:38:35 2010 +0100 +++ b/src/lread.c Sun Aug 15 13:29:10 2010 +0100 @@ -2876,7 +2876,6 @@ || state == (DOT_CHAR|TRAIL_INT|E_CHAR|EXP_INT))); } -#ifdef HAVE_RATIO int isratio_string (const char *cp) { @@ -2907,7 +2906,7 @@ return *cp == '\0' || *cp == ' ' || *cp =='\t' || *cp == '\n' || *cp == '\r' || *cp == '\f'; } -#endif + static void * sequence_reader (Lisp_Object readcharfun, diff -r f3eca926258e -r 808131ba4a57 src/print.c --- a/src/print.c Sat Jul 24 17:38:35 2010 +0100 +++ b/src/print.c Sun Aug 15 13:29:10 2010 +0100 @@ -2027,7 +2027,7 @@ for (; confusing < size; confusing++) { - if (!isdigit (data[confusing])) + if (!isdigit (data[confusing]) && '/' != data[confusing]) { confusing = 0; break; @@ -2039,7 +2039,8 @@ /* #### Ugh, this is needlessly complex and slow for what we need here. It might be a good idea to copy equivalent code from FSF. --hniksic */ - confusing = isfloat_string ((char *) data); + confusing = isfloat_string ((char *) data) + || isratio_string ((char *) data); if (confusing) write_ascstring (printcharfun, "\\"); } diff -r f3eca926258e -r 808131ba4a57 tests/ChangeLog --- a/tests/ChangeLog Sat Jul 24 17:38:35 2010 +0100 +++ b/tests/ChangeLog Sun Aug 15 13:29:10 2010 +0100 @@ -1,3 +1,9 @@ +2010-08-15 Aidan Kehoe + + * automated/lisp-tests.el: + Test that symbols with names that look like ratios are printed + distinctly from the equivalent ratios. + 2010-07-24 Aidan Kehoe * automated/lisp-tests.el: diff -r f3eca926258e -r 808131ba4a57 tests/automated/lisp-tests.el --- a/tests/automated/lisp-tests.el Sat Jul 24 17:38:35 2010 +0100 +++ b/tests/automated/lisp-tests.el Sun Aug 15 13:29:10 2010 +0100 @@ -2374,4 +2374,10 @@ (garbage-collect)))))) "checking we can amputate lists without crashing #'reduce") +(when (featurep 'ratio) + (Assert (not (eql '1/2 (read (prin1-to-string (intern "1/2"))))) + "checking symbols with ratio-like names are printed distinctly") + (Assert (not (eql '1/5 (read (prin1-to-string (intern "2/10"))))) + "checking symbol named \"2/10\" not eql to ratio 1/5 on read")) + ;;; end of lisp-tests.el