From: Frank GOENNINGER
Subject: Macro question ...
Date: 
Message-ID: <m2d4audm6u.fsf@ccde007.de.goenninger.net>
So I want to do some CFFI interfacing ... and have written the following
macro:

(defmacro define-gm-fun! (name (varlist) &body body)
  `(defun! ,name (,varlist)
     (ensure-cello-graphicsmagick-initialized)
     (prog1
       ,@body
       (cello-graphicsmagick-check-error))))

This works as long as I am defining functions that have arguments like

(define-gm-fun! gm-destroy-magick-wand (wand)
  (DestroyMagickWand wand))

However, I do get the following error for functions without arguments:

missing value for argument VARLIST
   [Condition of type SIMPLE-ERROR]

when trying to compile or macroexpand for e.g. this function:

(define-gm-fun! gm-magick-get-copyright ()
  (foreign-string-to-lisp (MagickGetCopyright)))

I can't get the varlist to produce () as a result within the macro ...
Help ! SOS ! ---...--- ;-) 

TIA!

Frank

From: gugamilare
Subject: Re: Macro question ...
Date: 
Message-ID: <0457bf13-9af4-4f37-9db3-0cab0e65b2b0@y34g2000prb.googlegroups.com>
On 30 abr, 15:35, Frank GOENNINGER <······@googlemail.com> wrote:
> So I want to do some CFFI interfacing ... and have written the following
> macro:
>
> (defmacro define-gm-fun! (name (varlist) &body body)
>   `(defun! ,name (,varlist)
>      (ensure-cello-graphicsmagick-initialized)
>      (prog1
>        ,@body
>        (cello-graphicsmagick-check-error))))

This form

(prog1
  ,@body
  ...)

won't  work as expected (if body has two or more forms, then the
result of the first form is returned instead of the result of the
last). Consider this solution:

(prog1
  (progn ,@body)
  ...)

>
> This works as long as I am defining functions that have arguments like
>
> (define-gm-fun! gm-destroy-magick-wand (wand)
>   (DestroyMagickWand wand))
>
> However, I do get the following error for functions without arguments:
>
> missing value for argument VARLIST
>    [Condition of type SIMPLE-ERROR]
>
> when trying to compile or macroexpand for e.g. this function:
>
> (define-gm-fun! gm-magick-get-copyright ()
>   (foreign-string-to-lisp (MagickGetCopyright)))
>
> I can't get the varlist to produce () as a result within the macro ...
> Help ! SOS ! ---...--- ;-)
>
> TIA!
>
> Frank
From: Frank GOENNINGER
Subject: Re: Macro question ...
Date: 
Message-ID: <m24ow6dj45.fsf@ccde007.de.goenninger.net>
gugamilare <··········@gmail.com> writes:

> On 30 abr, 15:35, Frank GOENNINGER <······@googlemail.com> wrote:
>> So I want to do some CFFI interfacing ... and have written the following
>> macro:
>>
>> (defmacro define-gm-fun! (name (varlist) &body body)
>> � `(defun! ,name (,varlist)
>> � � �(ensure-cello-graphicsmagick-initialized)
>> � � �(prog1
>> � � � �,@body
>> � � � �(cello-graphicsmagick-check-error))))
>
> This form
>
> (prog1
>   ,@body
>   ...)
>
> won't  work as expected (if body has two or more forms, then the
> result of the first form is returned instead of the result of the
> last). Consider this solution:
>
> (prog1
>   (progn ,@body)
>   ...)

Yes, thanks! (Figured as much already ;-)

Frank
From: Stanisław Halik
Subject: Re: Macro question ...
Date: 
Message-ID: <gtcs72$2f2p$1@opal.icpnet.pl>
thus spoke Frank GOENNINGER <······@googlemail.com>:

> So I want to do some CFFI interfacing ... and have written the following
> macro:

> (defmacro define-gm-fun! (name (varlist) &body body)

Oops!

Try:

> (defmacro define-gm-fun! (name (&rest varlist) &body body)

or:

> (defmacro define-gm-fun! (name varlist &body body)
From: Thomas A. Russ
Subject: Re: Macro question ...
Date: 
Message-ID: <ymi8wlhrh3u.fsf@blackcat.isi.edu>
Stanis�aw Halik <·······@test123.ltd.pl> writes:

> thus spoke Frank GOENNINGER <······@googlemail.com>:
> 
> > So I want to do some CFFI interfacing ... and have written the following
> > macro:
> 
> > (defmacro define-gm-fun! (name (varlist) &body body)
> 
> Oops!
> 
> Try:
> 
> > (defmacro define-gm-fun! (name (&rest varlist) &body body)
> 
> or:
> 
> > (defmacro define-gm-fun! (name varlist &body body)

This latter one will also mean that the expansion function will need to
use

  (defun ,name ,varlist ...)

instead of 

  (defun ,name (,varlist) ...)

I like the second form a little better.

-- 
Thomas A. Russ,  USC/Information Sciences Institute
From: Barry Margolin
Subject: Re: Macro question ...
Date: 
Message-ID: <barmar-A69A25.19510130042009@mara100-84.onlink.net>
In article <···············@blackcat.isi.edu>,
 ···@sevak.isi.edu (Thomas A. Russ) wrote:

> Stanis,aw Halik <·······@test123.ltd.pl> writes:
> 
> > thus spoke Frank GOENNINGER <······@googlemail.com>:
> > 
> > > So I want to do some CFFI interfacing ... and have written the following
> > > macro:
> > 
> > > (defmacro define-gm-fun! (name (varlist) &body body)
> > 
> > Oops!
> > 
> > Try:
> > 
> > > (defmacro define-gm-fun! (name (&rest varlist) &body body)
> > 
> > or:
> > 
> > > (defmacro define-gm-fun! (name varlist &body body)
> 
> This latter one will also mean that the expansion function will need to
> use
> 
>   (defun ,name ,varlist ...)
> 
> instead of 
> 
>   (defun ,name (,varlist) ...)
> 
> I like the second form a little better.

I like:

(defun ,name (,@varlist) ...)

It maintains the parallelism between the structure of the macro argument 
list and the function argument list.

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
From: Frank GOENNINGER
Subject: Re: Macro question ...
Date: 
Message-ID: <m28wlgocyf.fsf@ccde007.de.goenninger.net>
Barry Margolin <······@alum.mit.edu> writes:

> I like:
>
> (defun ,name (,@varlist) ...)
>
> It maintains the parallelism between the structure of the macro argument 
> list and the function argument list.

Nice one. Thanks.

Cheers
   Frank
From: Frank GOENNINGER
Subject: Re: Macro question ...
Date: 
Message-ID: <m28wlidknx.fsf@ccde007.de.goenninger.net>
Stanisław Halik <·······@test123.ltd.pl> writes:

> thus spoke Frank GOENNINGER <······@googlemail.com>:
>
>> So I want to do some CFFI interfacing ... and have written the following
>> macro:
>
>> (defmacro define-gm-fun! (name (varlist) &body body)
>
> Oops!

Yes, oooops!

>
> Try:
>
>> (defmacro define-gm-fun! (name (&rest varlist) &body body)
>
> or:
>
>> (defmacro define-gm-fun! (name varlist &body body)

Thanks. Works, of course ...

Frank