Syntax for symbols is more permissive than R6RS

2009-04-24 Thread Mike Gran
Hi,

I was poking around the reader while working on the Unicode stuff, and I
found that there aren't checks for a lot of symbol names that R6RS
considers to be invalid.

The following line has 11 dodgy but not invalid variable names:

+  -  ...  00A  @  [  \  ]  {  |  } 

They can be strung together to make fun code like this:
(define - 1)
(define [ 2)
(define ] 3)
(+ 1 [ - 2 3 ])
== 12

Which of these are useful extensions and which of these are bugs?

Thanks,

Mike Gran





Re: Syntax for symbols is more permissive than R6RS

2009-04-24 Thread Ludovic Courtès
Hi!

Mike Gran spk...@yahoo.com writes:

 I was poking around the reader while working on the Unicode stuff, and I
 found that there aren't checks for a lot of symbol names that R6RS
 considers to be invalid.

It's actually more permissive than R5RS as well.  For instance, `1+' and
`1-' are not valid R5RS identifiers IIRC.

I would be inclined to not change the reader's default behavior, i.e.,
to remain at least as permissive as in 1.8, so as to not cause
gratuitous incompatibility (we could even add unit tests to make sure we
don't remove them inadvertently.)

However, it may be a good idea to have a reader option asking for
strict(er) conformance.

Thanks,
Ludo'.





syncase in boot-9

2009-04-24 Thread Andy Wingo
Hello all,

A brief note. I have syncase in boot-9, with define-macro implemented in
terms of syntax-case. This work can be found on the syncase-in-boot-9
branch.

It's not quite ready yet, as there are some Scheme bits that still don't
compile. I had to add docstring support to psyntax -- surprising to
learn that other Schemes don't do docstrings. But the current linguistic
sticking point are idioms like this:

(if (something) (define foo bar))

or

(if (defined? foo)
(redefine foo)
(define foo))

The latter is used in define-class for class redefinition. The former
could be replaced with:

(define bar (if (something) new-bar bar))

And the latter cases could probably be reimplemented using syntax-case
instead of defmacro, but it's still really a shame that definitions and
expressions are different things.

Anyway, if you want to give it a try, checkout the syncase-in-boot-9
branch, and make -k, to step over the noncompiling scheme files. It's a
work in progress, but I will not be rebasing it.

Cheers,

Andy
-- 
http://wingolog.org/




[PATCH] Symbols and keywords longer than 128 chars cause exception

2009-04-24 Thread Mike Gran
In master

* test-suite/tests/reader.test (read-options): Add test
for long postfix keywords.

* libguile/read.c (scm_read_mixed_case_symbol): Fix
exception on symbols are greater than 128 chars.  Also,
colons are not stripped from long postfix keywords.
---
 libguile/read.c  |   15 ---
 test-suite/tests/reader.test |5 +
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/libguile/read.c b/libguile/read.c
index 47b8004..61806f2 100644
--- a/libguile/read.c
+++ b/libguile/read.c
@@ -552,12 +552,21 @@ scm_read_mixed_case_symbol (int chr, SCM port)
 
   if (scm_is_pair (str))
 {
+  size_t len;
+
   str = scm_string_concatenate (scm_reverse_x (str, SCM_EOL));
-  result = scm_string_to_symbol (str);
+  len = scm_c_string_length (str);
 
   /* Per SRFI-88, `:' alone is an identifier, not a keyword.  */
-  if (postfix  ends_with_colon  (scm_c_string_length (result)  1))
-   result = scm_symbol_to_keyword (result);
+  if (postfix  ends_with_colon  (len  1))
+   {
+ /* Strip off colon.  */
+ str = scm_c_substring (str, 0, len-1);
+ result = scm_string_to_symbol (str);
+ result = scm_symbol_to_keyword (result);
+   }
+  else
+   result = scm_string_to_symbol (str);
 }
   else
 {
diff --git a/test-suite/tests/reader.test b/test-suite/tests/reader.test
index b068c71..0b6f9a4 100644
--- a/test-suite/tests/reader.test
+++ b/test-suite/tests/reader.test
@@ -165,6 +165,11 @@
  (with-read-options '(keywords postfix)
(lambda ()
  (read-string keyword:)
+  (pass-if long postfix keywords
+(eq? 
#:keyword0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
+ (with-read-options '(keywords postfix)
+   (lambda ()
+ (read-string 
keyword0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789:)
   (pass-if `:' is not a postfix keyword (per SRFI-88)
 (eq? ':
  (with-read-options '(keywords postfix)
-- 
1.6.0.6