|
536 | 536 | (iota (length opt)))
|
537 | 537 | ,(method-def-expr name sparams overall-argl body isstaged))))
|
538 | 538 |
|
| 539 | +(define (remove-empty-parameters argl) |
| 540 | + (if (and (has-parameters? argl) (null? (cdar argl))) |
| 541 | + (cdr argl) |
| 542 | + argl)) |
| 543 | + |
539 | 544 | (define (method-def-expr name sparams argl body isstaged)
|
540 |
| - (if (any kwarg? argl) |
541 |
| - ;; has optional positional args |
542 |
| - (begin |
543 |
| - (let check ((l argl) |
544 |
| - (seen? #f)) |
545 |
| - (if (pair? l) |
546 |
| - (if (kwarg? (car l)) |
547 |
| - (check (cdr l) #t) |
548 |
| - (if (and seen? (not (vararg? (car l)))) |
549 |
| - (error "optional positional arguments must occur at end") |
550 |
| - (check (cdr l) #f))))) |
551 |
| - (receive |
552 |
| - (kws argl) (separate kwarg? argl) |
553 |
| - (let ((opt (map cadr kws)) |
554 |
| - (dfl (map caddr kws))) |
555 |
| - (if (has-parameters? argl) |
556 |
| - ;; both! |
557 |
| - ;; separate into keyword version with all positional args, |
558 |
| - ;; and a series of optional-positional-defs that delegate keywords |
559 |
| - (let ((kw (car argl)) |
560 |
| - (argl (cdr argl))) |
561 |
| - (check-kw-args (cdr kw)) |
| 545 | + (let ((argl (remove-empty-parameters argl))) |
| 546 | + (if (any kwarg? argl) |
| 547 | + ;; has optional positional args |
| 548 | + (begin |
| 549 | + (let check ((l argl) |
| 550 | + (seen? #f)) |
| 551 | + (if (pair? l) |
| 552 | + (if (kwarg? (car l)) |
| 553 | + (check (cdr l) #t) |
| 554 | + (if (and seen? (not (vararg? (car l)))) |
| 555 | + (error "optional positional arguments must occur at end") |
| 556 | + (check (cdr l) #f))))) |
| 557 | + (receive |
| 558 | + (kws argl) (separate kwarg? argl) |
| 559 | + (let ((opt (map cadr kws)) |
| 560 | + (dfl (map caddr kws))) |
| 561 | + (if (has-parameters? argl) |
| 562 | + ;; both! |
| 563 | + ;; separate into keyword version with all positional args, |
| 564 | + ;; and a series of optional-positional-defs that delegate keywords |
| 565 | + (let ((kw (car argl)) |
| 566 | + (argl (cdr argl))) |
| 567 | + (check-kw-args (cdr kw)) |
| 568 | + (receive |
| 569 | + (vararg req) (separate vararg? argl) |
| 570 | + (optional-positional-defs name sparams req opt dfl body isstaged |
| 571 | + (cons kw (append req opt vararg)) |
| 572 | + `(parameters (... ,(gensy)))))) |
| 573 | + ;; optional positional only |
562 | 574 | (receive
|
563 | 575 | (vararg req) (separate vararg? argl)
|
564 | 576 | (optional-positional-defs name sparams req opt dfl body isstaged
|
565 |
| - (cons kw (append req opt vararg)) |
566 |
| - `(parameters (... ,(gensy)))))) |
567 |
| - ;; optional positional only |
568 |
| - (receive |
569 |
| - (vararg req) (separate vararg? argl) |
570 |
| - (optional-positional-defs name sparams req opt dfl body isstaged |
571 |
| - (append req opt vararg))))))) |
572 |
| - (if (has-parameters? argl) |
573 |
| - ;; keywords only |
574 |
| - (begin (check-kw-args (cdar argl)) |
575 |
| - (keywords-method-def-expr name sparams argl body isstaged)) |
576 |
| - ;; neither |
577 |
| - (method-def-expr- name sparams argl body isstaged)))) |
| 577 | + (append req opt vararg))))))) |
| 578 | + (if (has-parameters? argl) |
| 579 | + ;; keywords only |
| 580 | + (begin (check-kw-args (cdar argl)) |
| 581 | + (keywords-method-def-expr name sparams argl body isstaged)) |
| 582 | + ;; neither |
| 583 | + (method-def-expr- name sparams argl body isstaged))))) |
578 | 584 |
|
579 | 585 | ;; remove nested blocks
|
580 | 586 | (define (flatten-blocks e)
|
|
0 commit comments