The question I posed was If it's possible to use srfi-72 in guile or racket. It is indeed a wish<br>of mine that it's implemented because it will most certainly help me write beutiful code because <br>that srfi cater to the coding style Ichoose to have. Without it one most certainly need to use with-syntax to introduce the bindings in order to be safe and avoid a multiple of possible syntactic loopholes as can see if you read André van Tonder's<br>
<br><a href="http://srfi.schemers.org/srfi-72/srfi-72.html">http://srfi.schemers.org/srfi-72/srfi-72.html</a><br><br>Anyway one does not need to change psyntax in order to come close to that system. A more hacky<br>way is to use code like the one at the end of this document. It's a reiteration and improvement on a<br>
previous version. So with this hack I can write,<br><br>-------------<br>(use-modules (syntax unquote++))<br>(define (f x y) #`(let ((x 1)) (+ #,x #,y)))<br>(define (h y) ##`(let ((x 2)) #.((x) (f x y))))<br>(define-syntax g (lambda (x) (syntax-case x () ((_ y) ##`(let ((x y)) #.((x) (h x)))))))<br>
scheme@(guile-user)> (g 3)<br>$2 = 5<br><br>--------------<br>In racket, <br>(define-for-syntax (f x y) #`(let ((x 1)) (+ #,x #,y)))<br>(define-for-syntax (h y) #`(let ((x 2)) #,(f #'x y))<br>(define-syntax (g stx) (syntax-case stx () ((_ y) #`(let ((x y)) #,(h #'x)))))<br>
> (g 3)<br>4<br>--------------<br><br>This shows that it was just luck previously when racket produced the correct (for my intention) answer.<br>with srfi-72 a correct answer would have been produced. Without srfi-72 I will then move over to use <br>
##` and #. in my code because it will be easy to transfer later on if when srfi-72 is available in some form.<br><br>/Stefan<br><br>(define-module (syntax unquote++)<br> #:export (quasisyntax++ insyntax))<br><br>(define *s* (make-fluid '()))<br>
(define *t* (make-fluid '()))<br><br>(define table (make-weak-key-hash-table))<br>(define (add-lambda lam)<br> (let* ((id (gensym "id"))<br> (x (datum->syntax #'table id)))<br> (hashq-set! table id lam)<br>
x))<br>(define (plexer x . l)<br> (let ((lam (hashq-ref table x)))<br> (apply lam l)))<br><br>(define (parse stx x)<br> (syntax-case x (unsyntax insyntax unsyntax-splicing)<br> ((unsyntax . _) x)<br> ((unsyntax-splicing . _) x)<br>
((insyntax ((p ...) c ...))<br> (with-syntax ((g (datum->syntax stx (gensym "g")))<br> (i (datum->syntax stx (gensym "i"))))<br> (fluid-set! *s* (cons #'(g (lambda (x) <br>
(syntax-case x () <br> ((_ p ...) (plexer 'i #'p ...)))))<br> (fluid-ref *s*)))<br> (fluid-set! *t* (cons #'(i (add-lambda <br>
(lambda (p ...) (begin c ...))))<br> (fluid-ref *t*)))<br> #'(g p ...)))<br> ((x . l)<br> (cons (parse stx #'x) (parse stx #'l)))<br>
(x #'x)))<br><br>(define-syntax quasisyntax++<br> (lambda (x)<br> (syntax-case x ()<br> ((_ y)<br> (begin<br> (fluid-set! *s* '())<br> (fluid-set! *t* '())<br> (with-syntax ((statement (parse x #'y))<br>
(lets (fluid-ref *s*))<br> (withs (fluid-ref *t*)))<br> #'(with-syntax withs<br> #`(let-syntax lets statement))))))))<br> <br>
(define (rg ch stream)<br> (let ((x (read-char stream)))<br> (cond<br> ((eqv? x #\`)<br> `(quasisyntax++ ,(read stream)))<br> (#t<br> (error "Wrong format of # reader extension")))))<br><br>
(define (rg. ch stream) `(insyntax ,(read stream)))<br><br>(read-hash-extend #\# rg)<br>(read-hash-extend #\. rg.)<br><br>