[gambit-list] Possible bug in define-macro

Marc Feeley feeley at iro.umontreal.ca
Sun Apr 10 07:35:00 EDT 2011


Adding a trace inside your macro definition makes the problem obvious:

> (define-macro (pushnew item lst . test)
    (let ((result
           (let ((== (gensym)))
             `(let ((,==  ,(if (null? test) equal? (car test))))
                (if (not (member ,item ,lst ,==))
                    (set! ,lst (cons ,item ,lst)))))))
      (pp result)
      result))
> (pushnew 5 flist)
(let ((#:g1 #<procedure #2 equal?>))
  (if (not (member 5 flist #:g1)) (set! flist (cons 5 flist))))
*** ERROR IN (console)@15.1 -- Ill-formed expression
> (define-macro (pushnew item lst . test)
    (let ((result
           (let ((== (gensym)))
             `(let ((,==  ,(if (null? test) 'equal? (car test))))
                (if (not (member ,item ,lst ,==))
                    (set! ,lst (cons ,item ,lst)))))))
      (pp result)
      result))
> (pushnew 5 flist)
(let ((#:g2 equal?))
  (if (not (member 5 flist #:g2)) (set! flist (cons 5 flist))))

Marc

On 2011-04-09, at 3:30 PM, William James wrote:

> Gambit v4.6.1
> 
>> (include "~/srfi-1-reference.scm")
>> (member 2 (iota 5) =)
> (2 3 4)
>> (define-macro (pushnew item lst . test)
>  (let ((== (gensym)))
>    `(let ((,==  ,(if (null? test) equal? (car test))))
>      (if (not (member ,item ,lst ,==))
>        (set! ,lst (cons ,item ,lst))))))
>> 
> (define flist '(2 3 5))
>> 
> (pushnew 5 flist)
> *** ERROR IN (console)@21.1 -- Ill-formed expression
>> 
> 
> 
> This macro works properly in Guile (and Bigloo):
> 
> guile> (load "test-pushnew.scm")
> (2.0 8 2 3 5)
> 
> where test-pushnew.scm is
> 
> (define-macro (pushnew item lst . test)
>  (let ((== (gensym)))
>    `(let ((,==  ,(if (null? test) equal? (car test))))
>      (if (not (member ,item ,lst ,==))
>        (set! ,lst (cons ,item ,lst))))))
> 
> (define flist '(2 3 5))
> 
> (pushnew 5 flist)
> 
> (pushnew 8 flist)
> 
> (pushnew 2.0 flist)
> 
> (pushnew 3.0 flist =)
> 
> (write flist) (newline)
> 
> _______________________________________________
> Gambit-list mailing list
> Gambit-list at iro.umontreal.ca
> https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list




More information about the Gambit-list mailing list