diff --git a/sexp.c b/sexp.c index 4f879e35..95490dc5 100644 --- a/sexp.c +++ b/sexp.c @@ -1191,7 +1191,9 @@ sexp sexp_intern(sexp ctx, const char *str, sexp_sint_t len) { #if SEXP_USE_HUFF_SYMS res = 0; space = 3; - if (len == 0) goto normal_intern; + if (len == 0 || sexp_isdigit(p[0]) + || ((p[0] == '+' || p[0] == '-') && len > 1 && sexp_isdigit(p[1]))) + goto normal_intern; for ( ; i 127 || c == '\\' || c == '.' || sexp_is_separator(c)) @@ -1914,7 +1916,15 @@ sexp sexp_write_one (sexp ctx, sexp obj, sexp out) { break; case SEXP_SYMBOL: str = sexp_lsymbol_data(obj); - c = (sexp_lsymbol_length(obj) > 1 || (sexp_lsymbol_length(obj) == 1 && str[0] != '.')) ? EOF : '|'; + c = (sexp_lsymbol_length(obj) == 0 || + (sexp_lsymbol_length(obj) == 1 && str[0] == '.') || + sexp_isdigit(str[0]) || + (sexp_lsymbol_length(obj) > 1 && + (((str[0] == '+' || str[0] == '-') + && (sexp_isdigit(str[1]) || str[1] == '.')) || + (str[sexp_lsymbol_length(obj)-1] == '0' && + str[sexp_lsymbol_length(obj)-2] == '.')))) + ? '|' : EOF; for (i=sexp_lsymbol_length(obj)-1; i>=0; i--) if (str[i] <= ' ' || str[i] == '\\' || sexp_is_separator(str[i])) c = '|'; diff --git a/tests/r7rs-tests.scm b/tests/r7rs-tests.scm index 05913cd2..e8d74b8d 100644 --- a/tests/r7rs-tests.scm +++ b/tests/r7rs-tests.scm @@ -2104,6 +2104,12 @@ (test-write-syntax "|\"|" '|\"|) (test-write-syntax "a" '|a|) ;; (test-write-syntax "a.b" '|a.b|) +(test-write-syntax "|2|" '|2|) +(test-write-syntax "|+3|" '|+3|) +(test-write-syntax "|-.4|" '|-.4|) +(test-write-syntax "|+inf.0|" '|+inf.0|) +(test-write-syntax "|-inf.0|" '|-inf.0|) +(test-write-syntax "|+nan.0|" '|+nan.0|) (test-end)