Re: MAKE-INSTANCE and STRUCTURE-CLASS
"Marco Antoniotti (as marco dot antoniotti at unimib dot it)" <[email protected]> Mon, 6 Jul 2026 08:03:01 +0200
| Newsgroups | gmane.lisp.lispworks.general,gmane.lisp.cl-pro |
|---|---|
| Message-ID | <CAG0Nw2nodKpbRwt3V1Bo1R=x1HytmWT923AOoFako+DMtoj7dQ@mail.gmail.com> |
--000000000000eb4e8e0655eb07ec Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi thanks. I know about the standard. And I know how to make workarounds (cf., https://new-op.common-lisp.dev/ and gitlab.common-lisp.net/new-op/new-op); David's code is in the same spirit as mine. But the question is whether there are major pitfalls doing something like this: (defstruct foozzot a s d) (defmethod make-instance ((fz (eql 'foozzot)) &key &allow-other-keys) (make-foozzot)) ; Munge initargs as you wish. Of course it zound be nicer to handle STRUCTURE-CLASS and STRUCTURE-OBJECT; again, what are the contraindications? After all, it seems to me that this is simply something the standard crafters punted on. Thanks All the best Marco PS NEW-OP would benefit from this, however, I asked because of an unrelated little project of mine. On Sun, Jul 5, 2026 at 8:02=E2=80=AFPM Tim Bradshaw <[email protected]> wrote: > On 5 Jul 2026, at 18:45, Tim Bradshaw (as tfb at cley dot com) < > [email protected]> wrote: > > > > If you care about portable code then you don't. > > Just to be clear: make-instance has two methods defined by the standard: > one for standard-class and one for symbols, which just calls find-class o= n > its first argument and recurses. > > There is no method for structure-class. You can't write such a method > portably. > > If an implementation has such a method (which I think it is allowed to > have, probably), then presumably it also implements initialize-instance &= c > in something like the usual way although it would have to talk about how = & > whether slots get initialized especially if you have defined a BOA > constructor &c. > > --tim --=20 Marco Antoniotti, Professor, Director tel. +39 - 02 64 48 79 01 DISCo, University of Milan-Bicocca U14 2043 http://dcb.disco.unimib.it Viale Sarca 336 I-20126 Milan (MI) ITALY REGAINS: https://regains.disco.unimib.it/ --000000000000eb4e8e0655eb07ec Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div>Hi</div><div><br></div><div>thanks.=C2=A0 I know abou= t the standard.=C2=A0 And I know how to make workarounds (cf.,=C2=A0<a href= =3D"https://new-op.common-lisp.dev/">https://new-op.common-lisp.dev/</a> an= d=C2=A0<a href=3D"http://gitlab.common-lisp.net/new-op/new-op">gitlab.commo= n-lisp.net/new-op/new-op</a>); David's code is in the same spirit as mi= ne.</div><div><br></div><div>But the question is whether there are major pi= tfalls doing something like this:<br><br></div><div><span style=3D"font-fam= ily:monospace">(defstruct foozzot a s d)<br><br></span></div><div><span sty= le=3D"font-family:monospace">(defmethod make-instance ((fz (eql 'foozzo= t)) &key &allow-other-keys)<br></span></div><div><span style=3D"fon= t-family:monospace">=C2=A0 =C2=A0(make-foozzot)) <span style=3D"color:rgb(2= 55,0,0)">; Munge initargs as you wish.</span></span><br><br></div><div>Of c= ourse it zound be nicer to handle STRUCTURE-CLASS and STRUCTURE-OBJECT; aga= in, what are the contraindications?=C2=A0 After all, it seems to me that th= is is simply something the standard crafters punted on.</div><div><br></div= ><div>Thanks</div><div><br></div><div>All the best</div><div><br></div><div= >Marco</div><div><br></div><div>PS NEW-OP would benefit from this, however,= I asked because of an unrelated little project of mine.</div></div><br><di= v class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Sun, Jul 5= , 2026 at 8:02=E2=80=AFPM Tim Bradshaw <<a href=3D"mailto:[email protected]" = target=3D"_blank">[email protected]</a>> wrote:<br></div><blockquote class=3D= "gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(2= 04,204,204);padding-left:1ex">On 5 Jul 2026, at 18:45, Tim Bradshaw (as tfb= at cley dot com) <<a href=3D"mailto:[email protected]" target=3D"_= blank">[email protected]</a>> wrote:<br> > <br> > If you care about portable code then you don't.<br> <br> Just to be clear: make-instance has two methods defined by the standard: on= e for standard-class and one for symbols, which just calls find-class on it= s first argument and recurses.<br> <br> There is no method for structure-class.=C2=A0 You can't write such a me= thod portably.<br> <br> If an implementation has such a method (which I think it is allowed to have= , probably), then presumably it also implements initialize-instance &c = in something like the usual way although it would have to talk about how &a= mp; whether slots get initialized especially if you have defined a BOA cons= tructor &c.<br> <br> --tim</blockquote></div><div><br clear=3D"all"></div><br><span class=3D"gma= il_signature_prefix">-- </span><br><div dir=3D"ltr" class=3D"gmail_signatur= e"><div dir=3D"ltr"><div><span style=3D"font-family:monospace">Marco Antoni= otti, Professor, Director =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 tel. += 39 - 02 64 48 79 01<br>DISCo, University of Milan-Bicocca U14 2043=C2=A0=C2= =A0 <a href=3D"http://dcb.disco.unimib.it" target=3D"_blank">http://dcb.dis= co.unimib.it</a><br>Viale Sarca 336<br>I-20126 Milan (MI) ITALY<br><br></sp= an></div><span style=3D"font-family:monospace">REGAINS: <a href=3D"https://= regains.disco.unimib.it/" target=3D"_blank">https://regains.disco.unimib.it= /</a><br></span></div></div> --000000000000eb4e8e0655eb07ec-- _______________________________________________ Lisp Hug - the mailing list for LispWorks users [email protected] http://www.lispworks.com/support/lisp-hug.html