[gambit-list] output of define-syntax

lowly coder lowlycoder at huoyanjinjing.com
Tue Feb 10 09:55:45 EST 2009


Great, I'm going to try to modify it. Where is pp defined? I tried grepping
through the scm files, but I see only calls to pp and not it's definition.

Thanks!

On Tue, Feb 10, 2009 at 5:50 AM, Marc Feeley <feeley at iro.umontreal.ca>wrote:

>
> On 10-Feb-09, at 3:18 AM, lowly coder wrote:
>
>  Session: ---
>>
>> ~/dynamic$ cat t2.scm
>> (define-macro (assert-equal lhs rhs)
>>  (let ((g-lhs (gensym))
>>        (g-rhs (gensym))
>>        (e-lhs (gensym))
>>        (e-rhs (gensym)))
>>    `(let ((,g-lhs ,lhs) (,g-rhs ,rhs)
>>           (,e-lhs ',lhs) (,e-rhs ',rhs))
>>       (if (not (equal? ,g-lhs ,g-rhs))
>>           (pp `(,,e-lhs = ,,g-lhs <> ,,g-rhs = ,,e-rhs))))))
>>
>> (pp (lambda ()
>>      (assert-equal (+ 1 2) (- 3 4))) (current-output-port))
>>
>> ~/dynamic$ gsi t2.scm
>> (lambda ()
>>  (let ((#:g0 (+ 1 2)) (#:g1 (- 3 4)) (#:g2 '(+ 1 2)) (#:g3 '(- 3 4)))
>>    (if (not (equal? #:g0 #:g1))
>>        (pp `(,#:g2
>>              ,@`
>> (,'= ,@`(,#:g0 ,@`(,'<> ,@`(,#:g1 ,@`(,'= ,@`(,#:g3 ,@'())))))))))))
>> ~/dynamic$
>>
>>
>> Question: ---
>>
>> Why do I have:
>>
>>  (pp `(,#:g2
>>              ,@`
>> (,'= ,@`(,#:g0 ,@`(,'<> ,@`(,#:g1 ,@`(,'= ,@`(,#:g3 ,@'())))))))))))
>>
>> ?
>>
>> It seems prettier as:
>>
>> `(,#:g2 '= ,#:g0 '<> ...)
>>
>> the ,@` seems extraneous
>>
>
>
> The interpreter does a very simple form of compilation of the source code
> to an AST (Abstract Syntax Tree).  What pp is showing you is the AST of your
> code.  pp is not being very smart at prettifying the AST of quasiquotes.  It
> shouldn't be too hard to add a rule such that `(X ,@`(Y...)) is turned into
> `(X Y...).
>
> Marc
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.iro.umontreal.ca/pipermail/gambit-list/attachments/20090210/d9df5ada/attachment.htm>


More information about the Gambit-list mailing list