[Openmcl-devel] CCL <-> C++ interface generator in alpha, reviewers wanted

Jason E. Aten j.e.aten at gmail.com
Tue Apr 12 13:45:13 PDT 2011


On Mon, Apr 11, 2011 at 9:37 AM, Ron Garret <ron at flownet.com> wrote:

> But because you're dealing with keyword arguments, they are already
> optional.  So you can do your own dispatching:
>
> (cl:defmethod initialize-instance :after ((obj Vlad) &key (a cl:integer) (d
> cl:number))
>   (cond ((and a b)
>              (setf (slot-value obj 'ff-pointer) (new_Vlad__SWIG_0 a d))))
>             ((not (or a b))
>              (setf (slot-value obj 'ff-pointer) (new_Vlad__SWIG_1))))
>             (a (error "A specified but B isn't"))
>             (b (error "B specified but A isn't")))))
>

Thank you Ron. You example code was very helpful, and I'm glad you pointed
out that the type of the arguments was being used to provide default values,
and not to do dispatch.

I have a working implementation for overloaded constructors now.  (Yes!  =)
I followed your suggestion and formed the union of all the names of
arguments to overloaded constructors, and then dispatch to each constructor
based on the keyword arguments provided.  An example of the generated code
is below.

One drawback to this approach is that the person writing to the new Lisp
interface now *must* provide keyword arguments. It would be nice to not
require this when it is redundant.

Q: Would it be possible to dispatch from initailize-instance from the
*arity* and/or *the types* of the arguments alone?


Thanks!
Jason


// current keyword overload way:

// the C++ class with overloaded constructor:
struct FileName
{
  FileName(char *str, int ref);
  FileName(char *path, char *name);
};


; the auto-generated Lisp init-instance code:

(cl:defmethod initialize-instance
     :after ((obj FileName)
             &key
             (name)
             (path)
             (ref)
             (str)
             )
    (cond ((and            ref str ;; <- *required*  keyword param
           (and (not (or   name path ;; <- *forbidden* keyword param
                                                ))))
           (setf (slot-value obj 'ff-pointer)  (new_FileName__SWIG_0  str
ref)))

          ((and            name path ;; <- *required*  keyword param
           (and (not (or   ref str ;; <- *forbidden* keyword param
                                                ))))
           (setf (slot-value obj 'ff-pointer)  (new_FileName__SWIG_1  path
name)))

          (t (error "no C++ constructor for class 'FileName' matched your
combination of keyword parameters"))))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.clozure.com/pipermail/openmcl-devel/attachments/20110412/943fc755/attachment.htm>


More information about the Openmcl-devel mailing list