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)
Afficher les réponses par date
You need to quote the "equal", otherwise you're trying to insert a procedure into the code, not a symbol: (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)))))) Brad
Also gambit's version on member only accepts two arguments. On Sat, Apr 9, 2011 at 1:03 PM, Bradley Lucier <lucier@math.purdue.edu> wrote:
You need to quote the "equal", otherwise you're trying to insert a procedure into the code, not a symbol:
(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))))))
Brad
_______________________________________________ Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
--- On Sat, 4/9/11, Bradley Lucier <lucier@math.purdue.edu> wrote:
From: Bradley Lucier <lucier@math.purdue.edu> Subject: Re: [gambit-list] Possible bug in define-macro To: "William James" <w_a_x_man@yahoo.com> Cc: "Bradley Lucier" <lucier@math.purdue.edu>, gambit-list@iro.umontreal.ca Date: Saturday, April 9, 2011, 3:03 PM You need to quote the "equal", otherwise you're trying to insert a procedure into the code, not a symbol:
That works. Thanks. Now the question is: why did the original macro work correctly under Guile and Bigloo?
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@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
participants (4)
-
Bradley Lucier -
Frederick LeMaster -
Marc Feeley -
William James