[Openmcl-devel] defstruct - generic constructor?

David Reitter reitter at cmu.edu
Wed Apr 29 15:05:31 PDT 2009


On Apr 29, 2009, at 5:53 PM, Robert Goldman wrote:
> "defstruct defines a constructor function that is used to create
> instances of the structure created by defstruct. The default name is
> make-structure-name. A different name can be supplied by giving the  
> name
> as the argument to the constructor option. nil indicates that no
> constructor function will be created."

That is one of the reasons why I'd like to avoid the hack...

> Question:  are all of the structures that you might want to make under
> your control?

I'd have to mandate make-* constructors in my API.  Not ideal.

> As an aside, it seems likely that (intern <name> <package>) will be  
> more
> efficient than read-from-string, and it won't be busted by changes to
> *package* in the surrounding environment.

I tried that first and failed.  I just figured out that I had to use  
upper case "MAKE-..."; with `find-symbol' in this case.
Less of a hack now.  Good.

Dan Weinreb:
> This behavior isn't specific to CCL; it's part of the definition
> of Common Lisp.  If you want to use make-instance, you
> should use defclass instead of defstruct.  (defstruct is an
> earlier, more primitive facility that was added to Lisp
> before object-oriented programming.)

Another good idea; I'll definitely consider doing that, with a macro  
to allow users of my API to define their classes using an interface  
that is as simple as defstruct.

It seems that there are much better facilities for introspection  
available for classes than for structures.

Thanks for your suggestions, everybody!
- David



More information about the Openmcl-devel mailing list