chicken-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-hackers] [PATCH] &optional and &rest in type-declarations


From: Felix
Subject: [Chicken-hackers] [PATCH] &optional and &rest in type-declarations
Date: Wed, 08 May 2013 14:33:18 +0200 (CEST)

Hello!


As proposed by Joerg Wittenberger, here is a patch for the scrutinizer
to allow "&optional" and "&rest" as alternatives to "#!optional" and
"#!rest" in type declarations.


cheers,
felix
>From 51c37a5ba968aef16a860bd66a88a903c68b0a3b Mon Sep 17 00:00:00 2001
From: felix <address@hidden>
Date: Wed, 8 May 2013 14:28:47 +0200
Subject: [PATCH] Allow &rest and &optional in type-declarations.

This is intended to keep code more portable by not having to use
non-standard reader extensions.
---
 NEWS            |    4 ++++
 manual/Types    |    4 ++++
 scrutinizer.scm |   10 ++++++++--
 3 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/NEWS b/NEWS
index 1e17cd2..0a1c898 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 07235fe..7e0aa0b 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 696238b..91a8f69 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
-- 
1.7.9.5


reply via email to

[Prev in Thread] Current Thread [Next in Thread]