Hans Nowak scripsit: > ...and I understand *why* they don't work, but I can't figure out how to > take s and transform it into (foo bar 42). Maybe I'm stupid, but I just > don't see it. Is it possible? Or do I need to do something entirely > different?
As has been pointed out, you can use eval, but you can also use your own quasiquote expander. Attached is a copy of Alan Bawden's, which is used in the syntax-case egg. The interface is just (qq-expand sexpr); the other functions are private helpers. Someone should eggify this, I guess.) Alan's code has an extension over R5RS: if you pass it `(+ (unquote 1 2 3) 4) it will return (+ 1 2 3 4) rather than reporting an error or just throwing away the "2 3" part, as Chicken's native quasiquote expander does. You can see this happen by testing the expression when running csi with and without syntax-case. -- Newbies always ask: John Cowan "Elements or attributes? http://www.ccil.org/~cowan Which will serve me best?" [EMAIL PROTECTED] Those who know roar like lions; Wise hackers smile like tigers. --a tanka, or extended haiku
(define (qq-expand x) (if (and (pair? x) (eq? 'quasiquote (car x))) (qq-expand-to (cadr x) 0) x)) (define (qq-expand-to x depth) (if (pair? x) (case (car x) ((quasiquote) `(cons ',(car x) ,(qq-expand-to (cdr x) (+ depth 1)))) ((unquote unquote-splicing) (cond ((> depth 0) `(cons ',(car x) ,(qq-expand-to (cdr x) (- depth 1)))) ((and (eq? 'unquote (car x)) (not (null? (cdr x))) (null? (cddr x))) (cadr x)) (else (error "Illegal")))) (else `(append ,(qq-expand-list (car x) depth) ,(qq-expand-to (cdr x) depth)))) `',x)))) (define (qq-expand-list x depth) (if (pair? x) (case (car x) ((quasiquote) `(list (cons ',(car x) ,(qq-expand-to (cdr x) (+ depth 1))))) ((unquote unquote-splicing) (cond ((> depth 0) `(list (cons ',(car x) ,(qq-expand-to (cdr x) (- depth 1))))) ((eq? 'unquote (car x)) `(list . ,(cdr x))) (else `(append . ,(cdr x))))) (else `(list (append ,(qq-expand-list (car x) depth) ,(qq-expand-to (cdr x) depth))))) `'(,x)))
_______________________________________________ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users