From: Sam Steingold
Subject: package nightmare
Date: 
Message-ID: <uln5196hj.fsf@ksp.com>
I recently tried to use multiple packages, and I have the following
problem:

I have

--------------------
(in-package foo)
(defmacro with-collect ((&rest collectors) &body forms)
  "Evaluate forms, collecting objects into lists.
Within the FORMS, you can use local macros listed among collectors,
they are returned as multiple values.
E.g., (with-collect (c1 c2) (dotimes (i 10) (if (oddp i) (c1 i) (c2 i))))
 ==> (1 3 5 7 9); (0 2 4 6 8) [2 values]
In CLISP, push/nreverse is about 1.25 times as fast as pushing into the
tail, so this macro uses push/nreverse on CLISP and push into the tail
on other lisps (which is 1.5-2 times as fast as push/nreverse there)."
  (let ((ret (mapcar (lambda (cc) (gensym (format nil "~s-RET-" cc)))
                     collectors)))
    `(let (,@ret)
      (declare (list ,@ret))
      (macrolet ,(mapcar (lambda (co re) `(,co (form) `(push ,form ,',re)))
                         collectors ret)
        ,@forms
        (values ,@(mapcar (lambda (re) `(sys::list-nreverse ,re)) ret))))))
(defun some-function ()
 (with-collect (co) .....))

(in-package bar)

(foo::some-function)

error:
*** - funcall: the function foo::co is undefined
---------------------

the foo code is in a separate compiled file.

what's wrong?
how do I fix it?

Thanks.

-- 
Sam Steingold (http://www.podval.org/~sds)
Micros**t is not the answer.  Micros**t is a question, and the answer is Linux,
(http://www.linux.org) the choice of the GNU (http://www.gnu.org) generation.
The only thing worse than X Windows: (X Windows) - X

From: Hidayet Tunc Simsek
Subject: Re: package nightmare
Date: 
Message-ID: <389A19E8.EFDA0AA4@EECS.Berkeley.Edu>
I think the problem is with:

> (defmacro with-collect ((&rest collectors) &body forms)

I don't quite know if you can say that.  But the following should work

(defmacro with-collect (collectors &rest forms)

Good luck,
Tunc


Sam Steingold wrote:
> 
> I recently tried to use multiple packages, and I have the following
> problem:
> 
> I have
> 
> --------------------
> (in-package foo)
> (defmacro with-collect ((&rest collectors) &body forms)
>   "Evaluate forms, collecting objects into lists.
> Within the FORMS, you can use local macros listed among collectors,
> they are returned as multiple values.
> E.g., (with-collect (c1 c2) (dotimes (i 10) (if (oddp i) (c1 i) (c2 i))))
>  ==> (1 3 5 7 9); (0 2 4 6 8) [2 values]
> In CLISP, push/nreverse is about 1.25 times as fast as pushing into the
> tail, so this macro uses push/nreverse on CLISP and push into the tail
> on other lisps (which is 1.5-2 times as fast as push/nreverse there)."
>   (let ((ret (mapcar (lambda (cc) (gensym (format nil "~s-RET-" cc)))
>                      collectors)))
>     `(let (,@ret)
>       (declare (list ,@ret))
>       (macrolet ,(mapcar (lambda (co re) `(,co (form) `(push ,form ,',re)))
>                          collectors ret)
>         ,@forms
>         (values ,@(mapcar (lambda (re) `(sys::list-nreverse ,re)) ret))))))
> (defun some-function ()
>  (with-collect (co) .....))
> 
> (in-package bar)
> 
> (foo::some-function)
> 
> error:
> *** - funcall: the function foo::co is undefined
> ---------------------
> 
> the foo code is in a separate compiled file.
> 
> what's wrong?
> how do I fix it?
> 
> Thanks.
> 
> --
> Sam Steingold (http://www.podval.org/~sds)
> Micros**t is not the answer.  Micros**t is a question, and the answer is Linux,
> (http://www.linux.org) the choice of the GNU (http://www.gnu.org) generation.
> The only thing worse than X Windows: (X Windows) - X
From: Barry Margolin
Subject: Re: package nightmare
Date: 
Message-ID: <CApm4.46$mn5.486@burlma1-snr2>
In article <·················@EECS.Berkeley.Edu>,
Hidayet Tunc Simsek  <······@EECS.Berkeley.Edu> wrote:
>I think the problem is with:
>
>> (defmacro with-collect ((&rest collectors) &body forms)
>
>I don't quite know if you can say that.  But the following should work
>
>(defmacro with-collect (collectors &rest forms)

No, I don't think that's the problem.  Sam's &rest was valid.  By using
that, DEFMACRO will ensure that the first subform of WITH-COLLECT is a
list, whereas yours would allow:

(with-collect co ...)

DEFMACRO destructuring allows most &-keywords at any level (&ENVIRONMENT
is the only exception, I think).

-- 
Barry Margolin, ······@bbnplanet.com
GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
From: Rainer Joswig
Subject: Re: package nightmare
Date: 
Message-ID: <rainer.joswig-7E624F.08104404022000@news.is-europe.net>
In article <·············@ksp.com>, ···@gnu.org wrote:

> (defun some-function ()
>  (with-collect (co) .....))
> 
> (in-package bar)
> 
> (foo::some-function)
> 
> error:
> *** - funcall: the function foo::co is undefined
> ---------------------
> 
> the foo code is in a separate compiled file.
> 
> what's wrong?

Looks like the compiler (?) did not know the WITH-COLLECT macro,
while compiling SOME-FUNCTION.
So it tries to run it as a function, evaluating the arguments
first and it runs into (CO), which it also sees as a function
call.

From what package you call FOO::SOME-FUNCTION should not
make a difference.

> how do I fix it?

Check for compiler messages when compiling the file of
SOME-FUNCTION.

Rainer Joswig, ISION Internet AG, Harburger Schlossstra�e 1, 
21079 Hamburg, Germany, Tel: +49 40 77175 226
Email: ·············@ision.de , WWW: http://www.ision.de/