Ticket #385: srfi-26-error.patch

File srfi-26-error.patch, 3.3 KB (added by sjamaan, 14 years ago)

New version of error-checking patch

  • chicken-syntax.scm

    diff --git a/chicken-syntax.scm b/chicken-syntax.scm
    index f97c22a..dbf49cc 100644
    a b  
    986986    (let ((%<> (r '<>))
    987987          (%<...> (r '<...>))
    988988          (%apply (r 'apply)))
     989      (when (null? (cdr form))
     990        (syntax-error 'cute "You need to supply at least a procedure" form))
    989991      (let loop ([xs (cdr form)] [vars '()] [vals '()] [rest #f])
    990992        (if (null? xs)
    991993            (let ([rvars (reverse vars)]
     
    9991001            (cond ((c %<> (car xs))
    10001002                   (let ([v (r (gensym))])
    10011003                     (loop (cdr xs) (cons v vars) (cons v vals) #f) ) )
    1002                   ((c %<...> (car xs)) (loop '() vars vals #t))
     1004                  ((c %<...> (car xs))
     1005                   (if (null? (cdr xs))
     1006                       (loop '() vars vals #t)
     1007                       (syntax-error 'cut
     1008                                     "Tail patterns after <...> are not supported"
     1009                                     form)))
    10031010                  (else (loop (cdr xs) vars (cons (car xs) vals) #f)) ) ) ) ) )))
    10041011
    10051012(##sys#extend-macro-environment
     
    10101017    (let ((%apply (r 'apply))
    10111018          (%<> (r '<>))
    10121019          (%<...> (r '<...>)))
     1020      (when (null? (cdr form))
     1021        (syntax-error 'cute "You need to supply at least a procedure" form))
    10131022      (let loop ([xs (cdr form)] [vars '()] [bs '()] [vals '()] [rest #f])
    10141023        (if (null? xs)
    10151024            (let ([rvars (reverse vars)]
     
    10251034            (cond ((c %<> (car xs))
    10261035                   (let ([v (r (gensym))])
    10271036                     (loop (cdr xs) (cons v vars) bs (cons v vals) #f) ) )
    1028                   ((c %<...> (car xs)) (loop '() vars bs vals #t))
     1037                  ((c %<...> (car xs))
     1038                   (if (null? (cdr xs))
     1039                       (loop '() vars bs vals #t)
     1040                       (syntax-error 'cute
     1041                                     "Tail patterns after <...> are not supported"
     1042                                     form)))
    10291043                  (else
    10301044                   (let ([v (r (gensym))])
    10311045                     (loop (cdr xs)
  • tests/syntax-tests.scm

    diff --git a/tests/syntax-tests.scm b/tests/syntax-tests.scm
    index c210165..53f77dc 100644
    a b  
    2222(t 3 3)
    2323
    2424(f abc)
    25 
     25#|
    2626(f (t 3 4))
    2727
    2828;; test syntax-rules
     
    478478
    479479(import (prefix rfoo f:))
    480480(f:rbar 1)
     481|#
     482;;; SRFI-26
     483
     484;; Cut
     485(t '() ((cut list)))
     486(t '() ((cut list <...>)))
     487(t '(1) ((cut list 1)))
     488(t '(1) ((cut list <>) 1))
     489(t '(1) ((cut list <...>) 1))
     490(t '(1 2) ((cut list 1 2)))
     491(t '(1 2) ((cut list 1 <>) 2))
     492(t '(1 2) ((cut list 1 <...>) 2))
     493(t '(1 2 3 4) ((cut list 1 <...>) 2 3 4))
     494(t '(1 2 3 4) ((cut list 1 <> 3 <>) 2 4))
     495(t '(1 2 3 4 5 6) ((cut list 1 <> 3 <...>) 2 4 5 6))
     496(t '(ok) (let* ((x 'wrong)
     497                (y (cut list x)))
     498           (set! x 'ok)
     499           (y)))
     500(t 2 (let ((a 0))
     501       (map (cut + (begin (set! a (+ a 1)) a) <>)
     502            '(1 2))
     503       a))
     504(f (eval '((cut + <...> 1) 1)))
     505
     506;; Cute
     507(t '() ((cute list)))
     508(t '() ((cute list <...>)))
     509(t '(1) ((cute list 1)))
     510(t '(1) ((cute list <>) 1))
     511(t '(1) ((cute list <...>) 1))
     512(t '(1 2) ((cute list 1 2)))
     513(t '(1 2) ((cute list 1 <>) 2))
     514(t '(1 2) ((cute list 1 <...>) 2))
     515(t '(1 2 3 4) ((cute list 1 <...>) 2 3 4))
     516(t '(1 2 3 4) ((cute list 1 <> 3 <>) 2 4))
     517(t '(1 2 3 4 5 6) ((cute list 1 <> 3 <...>) 2 4 5 6))
     518(t 1 (let ((a 0))
     519       (map (cute + (begin (set! a (+ a 1)) a) <>)
     520            '(1 2))
     521       a))
     522(f (eval '((cute + <...> 1) 1)))
     523 No newline at end of file