Relocated cond-expand to scheme/base

This commit is contained in:
Justin Ethier 2015-08-21 01:55:39 -04:00
parent c46e311945
commit fcb25adfc3
2 changed files with 25 additions and 28 deletions

View file

@ -90,6 +90,7 @@
begin
case
cond
cond-expand
when
quasiquote
)
@ -191,6 +192,28 @@
;((pair? exps) `(let (($_ ,(car exps)))
; ,(dummy-bind (cdr exps))))))
(dummy-bind (cdr exp)))))
(define-syntax cond-expand
(er-macro-transformer
;; Based on the cond-expand macro from Chibi scheme
(lambda (expr rename compare)
(define (check x)
(if (pair? x)
(case (car x)
((and) (every check (cdr x)))
((or) (any check (cdr x)))
((not) (not (check (cadr x))))
;((library) (eval `(find-module ',(cadr x)) (%meta-env)))
(else (error "cond-expand: bad feature" x)))
(memq x (features))))
(let expand ((ls (cdr expr)))
(cond ((null? ls)) ; (error "cond-expand: no expansions" expr)
((not (pair? (car ls))) (error "cond-expand: bad clause" (car ls)))
((eq? 'else (caar ls)) ;(identifier->symbol (caar ls)))
(if (pair? (cdr ls))
(error "cond-expand: else in non-final position")
`(,(rename 'begin) ,@(cdar ls))))
((check (caar ls)) `(,(rename 'begin) ,@(cdar ls)))
(else (expand (cdr ls))))))))
(define-syntax cond
(er-macro-transformer
(lambda (expr rename compare)

View file

@ -131,35 +131,9 @@
;; Temporary work-around for pp not being implemented yet
(define pretty-print write)
;; Built-in macros
;; TODO: just a stub, real code would read (define-syntax)
;; from a lib file or such
;; Container for built-in macros
(define (get-macros) *defined-macros*)
(define *defined-macros*
(list
(cons 'cond-expand
;; Based on the cond-expand macro from Chibi scheme
(lambda (expr rename compare)
(define (check x)
(if (pair? x)
(case (car x)
((and) (every check (cdr x)))
((or) (any check (cdr x)))
((not) (not (check (cadr x))))
;((library) (eval `(find-module ',(cadr x)) (%meta-env)))
(else (error "cond-expand: bad feature" x)))
(memq x (features))))
(let expand ((ls (cdr expr)))
(cond ((null? ls)) ; (error "cond-expand: no expansions" expr)
((not (pair? (car ls))) (error "cond-expand: bad clause" (car ls)))
((eq? 'else (caar ls)) ;(identifier->symbol (caar ls)))
(if (pair? (cdr ls))
(error "cond-expand: else in non-final position")
`(,(rename 'begin) ,@(cdar ls))))
((check (caar ls)) `(,(rename 'begin) ,@(cdar ls)))
(else (expand (cdr ls)))))))
))
(define *defined-macros* (list))
(define (built-in-syms)
'(call-with-values call/cc define))