~ chicken-core (chicken-5) 968cd4d33fd80fafd4c833842403335bb31b7870


commit 968cd4d33fd80fafd4c833842403335bb31b7870
Author:     felix <felix@call-with-current-continuation.org>
AuthorDate: Wed May 8 14:28:47 2013 +0200
Commit:     Peter Bex <peter.bex@xs4all.nl>
CommitDate: Thu May 9 15:07:03 2013 +0200

    Allow &rest and &optional in type-declarations.
    
    This is intended to keep code more portable by not having to use
    non-standard reader extensions.
    
    Signed-off-by: Peter Bex <peter.bex@xs4all.nl>

diff --git a/NEWS b/NEWS
index 1e17cd23..0a1c8987 100644
--- a/NEWS
+++ b/NEWS
@@ -17,6 +17,10 @@
   - chicken-install now also accepts full URI syntax for proxy environment
     variables (thanks to Michele La Monaca)
 
+- Syntax
+  - Added the aliases "&optional" and "&rest" as alternatives to "#!optional"
+    and "#!rest" in type-declarations (suggested by Joerg Wittenberger).
+
 - Compiler
   - the "inline" declaration does not force inlining anymore as recursive
     inlining could lead to non-termination of the compiler (thanks to
diff --git a/manual/Types b/manual/Types
index 07235fe8..7e0aa0bf 100644
--- a/manual/Types
+++ b/manual/Types
@@ -201,6 +201,10 @@ Additionally, some aliases are allowed:
 <tr><td>{{void}}</td><td>{{undefined}}</td></tr>
 </table>
 
+For portability the aliases {{&optional}} and {{&rest}} are allowed
+in procedure type declarations as an alternative to {{#!optional}} and
+{{#!rest}}, respectively.
+
 
 ==== Predicates
 
diff --git a/scrutinizer.scm b/scrutinizer.scm
index 696238b0..91a8f69b 100644
--- a/scrutinizer.scm
+++ b/scrutinizer.scm
@@ -102,6 +102,9 @@
 ;            | INTEGER | SYMBOL | STRING
 ;            | (quote CONSTANT)
 ;            | (TEMPLATE . TEMPLATE)
+;
+; As an alternative to the "#!rest" and "#!optional" keywords, "&rest" or "&optional"
+; may be used.
 
 
 (define-constant +fragment-max-length+ 6)
@@ -1956,6 +1959,7 @@
   ;; - converts some typenames to struct types (u32vector, etc.)
   ;; - handles some type aliases
   ;; - drops "#!key ..." args by converting to #!rest
+  ;; - replaces uses of "&rest"/"&optional" with "#!rest"/"#!optional"
   ;; - handles "(T1 -> T2 : T3)" (predicate) 
   ;; - handles "(T1 --> T2 [: T3])" (clean)
   ;; - simplifies result
@@ -1974,10 +1978,12 @@
       (cond ((null? llist) '())
 	    ((symbol? llist) '(#!rest *))
 	    ((not (pair? llist)) #f)
-	    ((eq? '#!optional (car llist))
+	    ((or (eq? '#!optional (car llist))
+		 (eq? '&optional (car llist)))
 	     (let ((l1 (validate-llist (cdr llist))))
 	       (and l1 (cons '#!optional l1))))
-	    ((eq? '#!rest (car llist))
+	    ((or (eq? '#!rest (car llist))
+		 (eq? '&rest (car llist)))
 	     (cond ((null? (cdr llist)) '(#!rest *))
 		   ((not (pair? (cdr llist))) #f)
 		   (else
Trap