SapphireDensetsu / ypsilon

Automatically exported from code.google.com/p/ypsilon
Other
0 stars 0 forks source link

(x ... . r) should match anything #15

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
See:
http://lists.r6rs.org/pipermail/r6rs-discuss/2008-February/003478.html

I.e., this should work:
> (syntax-case #'foo () 
    [(x ... . r) 
     (syntax->datum #'(x ... . r))])
foo
> 

It seems weird at first, but it's pretty useful and people use it a lot. 
It's especially useful for macros which destructure <formals> and want to
support the full <formals> syntax.  I.e (contrived):

> (define-syntax lambda/show
    (lambda (stx)
      (syntax-case stx ()
        [(_ (a ... . r) . b)
         #`(lambda (a ... . r)
             #,(if (positive? (length #'(a ...)))
                 #'(begin
                     (display "Required arguments:\n")
                     (for-each 
                       (lambda (v)
                         (display (format " ~s\n" v)))
                       (list a ...)))
                 #f)
             #,(if (identifier? #'r)
                 #'(begin
                     (display "Non-required arguments list:\n")
                     (display (format " ~s\n" r)))
                 #f)
             (let () . b))])))
> 
> (define ls (lambda/show args 'done))  ;; Note: `args' matches
> (ls 1 2)
Non-required arguments list:
 (1 2)
done
>

Matching like that is also congruent with the behavior of cons* and append:
> (cons* 1)
1
> (append 1)
1
> (append '(1) 2)
(1 . 2)
> 

Original issue reported on code.google.com by derick.e...@gmail.com on 24 Jun 2008 at 12:49

GoogleCodeExporter commented 8 years ago
Thank you for your bug report.
I understand that it seems weird but very common. :)
I will update the code to handle that pattern.

Original comment by y.fujita...@gmail.com on 24 Jun 2008 at 2:46

GoogleCodeExporter commented 8 years ago
I have fixed the bug and trunk directory is updated. Please try. Thank you!

Original comment by y.fujita...@gmail.com on 26 Jun 2008 at 1:00