Thu May 2 17:04:40 JST 2013

Gauche Macro Error: "Bad ellipsis..."

In syntax-rules, we use pattern language. What the pattern language? I want to write (\ x y -> ...) rather than (lambda (x y) ...) also in scheme. So I write the following macro.

(define (split ls)
  (if (eq? (car ls) '->) (values '() (cdr ls))
    (receive (a b) (split (cdr ls)) (values (cons (car ls) a) b))))

(define-macro (^ . ls)
  (receive (args body) (split ls)
  `(lambda ,args ,@body)))

this works.

(define f (^ x y z -> (* (+ x y))))
(f 1 2 3) ; => 9
  1. Cannot I use syntax-rules??
(define-syntax ^
  (syntax-rules (->)
    ((^ x ... -> body ...) (lambda (x ...) body ...))))

Gauche says "Bad ellipsis..."

I cannot beleave that pattern language is turing complete.

追記 (Sun Feb 16 10:53:43 JST 2014)

... というキーワードはリストの一番最後の要素としてしか置けない