1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-01 12:20:26 +02:00
guile/module/language/scheme/amatch.scm
Andy Wingo 237f96e7f0 add separate expansion phase, to detwingle things a bit
* module/language/scheme/expand.scm: New module, implements a separate
  expansion phase, not interleaved with compilation.

* module/language/scheme/amatch.scm: Helper for expand.scm, it's pmatch
  with support for annotated source.

* module/ice-9/Makefile.am (SOURCES): Add annotate.scm to build list --
  early on because it will be used in the compiler.

* module/ice-9/annotate.scm: Fix the printer, default to unstripped
  (whatever that is), and add a deannotator.

* module/system/base/compile.scm (call-with-compile-error-catch): Fix for
  new representation of source locations.

* module/Makefile.am (SCHEME_LANG_SOURCES): Add amatch and expand.
2009-03-02 17:27:45 +01:00

37 lines
1.2 KiB
Scheme

(define-module (language scheme amatch)
#:use-module (ice-9 syncase)
#:export (amatch apat))
;; FIXME: shouldn't have to export apat...
;; This is exactly the same as pmatch except that it unpacks annotations
;; as needed.
(define-syntax amatch
(syntax-rules (else guard)
((_ (op arg ...) cs ...)
(let ((v (op arg ...)))
(amatch v cs ...)))
((_ v) (if #f #f))
((_ v (else e0 e ...)) (begin e0 e ...))
((_ v (pat (guard g ...) e0 e ...) cs ...)
(let ((fk (lambda () (amatch v cs ...))))
(apat v pat
(if (and g ...) (begin e0 e ...) (fk))
(fk))))
((_ v (pat e0 e ...) cs ...)
(let ((fk (lambda () (amatch v cs ...))))
(apat v pat (begin e0 e ...) (fk))))))
(define-syntax apat
(syntax-rules (_ quote unquote)
((_ v _ kt kf) kt)
((_ v () kt kf) (if (null? v) kt kf))
((_ v (quote lit) kt kf)
(if (equal? v (quote lit)) kt kf))
((_ v (unquote var) kt kf) (let ((var v)) kt))
((_ v (x . y) kt kf)
(if (apair? v)
(let ((vx (acar v)) (vy (acdr v)))
(apat vx x (apat vy y kt kf) kf))
kf))
((_ v lit kt kf) (if (eq? v (quote lit)) kt kf))))