Re: MAKE-INSTANCE and STRUCTURE-CLASS
"David McClain (as dbm at refined-audiometrics dot com)" <[email protected]> Mon, 6 Jul 2026 06:29:23 -0700
| Newsgroups | gmane.lisp.lispworks.general,gmane.lisp.cl-pro |
|---|---|
| Message-ID | <[email protected]> |
--Apple-Mail=_B9E86340-28BF-47D1-B681-3BF166F44FB8 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 I guess i=E2=80=99m confused about the purpose of this query=E2=80=A6 I = had thought that, yes, STRUCTS are a problem. But if you want to do = something like Marco asked, here is one way to accomplish that. But now we are getting into the weeds of language lawyering, and I=E2=80=99= m not even sure how to interpret the last comments about bureaucracy. = Either you want to accomplish a goal or you don=E2=80=99t. Not sure how = arguing about arcane corners of language design, =E2=80=9Cas the = founding fahers envifrsioned it=E2=80=9D, helps out? > On Jul 6, 2026, at 01:02, Tim Bradshaw (as tfb at cley dot com) = <[email protected]> wrote: >=20 > =EF=BB=BF > On 6 Jul 2026, at 07:05, Marco Antoniotti <[email protected]> = wrote: >>=20 >> But the question is whether there are major pitfalls doing something = like this: >>=20 >> (defstruct foozzot a s d) >>=20 >> (defmethod make-instance ((fz (eql 'foozzot)) &key &allow-other-keys) >> (make-foozzot)) ; Munge initargs as you wish. >=20 >=20 > I suppose you could do that. I mean, it's horrific, and it would = violate the expectation that make-instance when given a symbol calls = make-instance on the corresponding class. I certainly have code which = assumes it can use find-class to check a class exists and only then = calls make-instance, so it's in control of errors and this would break = that. >=20 >> 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. >=20 > As I said: you can't do that in conforming code: you can't define = methods on standardised GFs which are applicable when all their = arguments are direct instances of standardised classes. There might be = an exception for make-instance but I don't think so. >=20 > I realise it's violating the spirit of CLOS ('make it complicated, = then add bureaucracy' as Chapman would never have said), but my = general-purpose constructor is funcall or apply, and curiously the same = pair of functions are my general-purpose equality predicates. I just = pass in constructor functions &c. >=20 > If I wanted to add bureacracy I'd define >=20 > (defgeneric constructor (class) > (:method ((class symbol)) > (constructor (find-class class))) > (:method ((class standard-class)) > (lambda (&rest kws &key &allow-other-keys) > (apply #'make-instance class kws)))) >=20 > ... methods for constructor now can be defined for any class at all. >=20 >=20 >=20 >=20 >=20 --Apple-Mail=_B9E86340-28BF-47D1-B681-3BF166F44FB8 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 <html aria-label=3D"message body"><head><meta http-equiv=3D"content-type" = content=3D"text/html; charset=3Dutf-8"></head><body = style=3D"overflow-wrap: break-word; -webkit-nbsp-mode: space; = line-break: after-white-space;">I guess i=E2=80=99m confused about the = purpose of this query=E2=80=A6 I had thought that, yes, STRUCTS are a = problem. But if you want to do something like Marco asked, here is one = way to accomplish that.<div><br></div><div>But now we are getting into = the weeds of language lawyering, and I=E2=80=99m not even sure how to = interpret the last comments about bureaucracy. Either you want to = accomplish a goal or you don=E2=80=99t. Not sure how arguing about = arcane corners of language design, =E2=80=9Cas the founding fahers = envifrsioned it=E2=80=9D, helps out?<br = id=3D"lineBreakAtBeginningOfMessage"><div><br><blockquote = type=3D"cite"><div>On Jul 6, 2026, at 01:02, Tim Bradshaw (as tfb at = cley dot com) <[email protected]> wrote:</div><br = class=3D"Apple-interchange-newline"><div><meta http-equiv=3D"content-type"= content=3D"text/html; charset=3Dutf-8"><div dir=3D"auto"><div = dir=3D"ltr">=EF=BB=BF<meta http-equiv=3D"content-type" = content=3D"text/html; charset=3Dutf-8"><div dir=3D"ltr"><div = dir=3D"ltr"></div><div dir=3D"ltr">On 6 Jul 2026, at 07:05, Marco = Antoniotti <[email protected]> wrote:</div><div = dir=3D"ltr"><blockquote type=3D"cite"><br></blockquote></div><blockquote = type=3D"cite"><div dir=3D"ltr"><div>But the question is whether there = are major pitfalls doing something like this:<br><br></div><div><span = style=3D"font-family:monospace">(defstruct foozzot a s = d)<br><br></span></div><div><span = style=3D"font-family:monospace">(defmethod make-instance ((fz (eql = 'foozzot)) &key &allow-other-keys)<br></span></div><div><span = style=3D"font-family:monospace"> (make-foozzot)) <span = style=3D"color:rgb(255,0,0)">; Munge initargs as you = wish.</span></span><br></div></div></blockquote><div><br></div><div><br></= div>I suppose you could do that. I mean, it's horrific, and it = would violate the expectation that make-instance when given a symbol = calls make-instance on the corresponding class. I certainly have = code which assumes it can use find-class to check a class exists and = only then calls make-instance, so it's in control of errors and this = would break that.</div><div dir=3D"ltr"><br><div><div><blockquote = type=3D"cite"><div dir=3D"ltr"><div>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.</div></div></blockquote><br></div></div><div>As I said: you can't do = that in conforming code: you can't define methods on standardised GFs = which are applicable when all their arguments are direct instances of = standardised classes. There might be an exception for = make-instance but I don't think so.</div><div><br></div><div>I realise = it's violating the spirit of CLOS ('make it complicated, then add = bureaucracy' as Chapman would never have said), but my general-purpose = constructor is funcall or apply, and curiously the same pair of = functions are my general-purpose equality predicates. I just pass = in constructor functions &c.</div><div><br></div><div>If I wanted to = add bureacracy I'd define</div><div><br></div><div>(defgeneric = constructor (class)</div><div> (:method ((class = symbol))</div><div> (constructor (find-class = class)))</div><div> (:method ((class = standard-class))</div><div> (lambda (&rest kws &key = &allow-other-keys)</div><div> (apply = #'make-instance class kws))))</div><div><br></div><div>... methods for = constructor now can be defined for any class at = all.</div><div><br></div><div><br></div><div><br></div><div><br></div><div= ><br></div></div></div></div></div></blockquote></div><br></div></body></h= tml>= --Apple-Mail=_B9E86340-28BF-47D1-B681-3BF166F44FB8-- _______________________________________________ Lisp Hug - the mailing list for LispWorks users [email protected] http://www.lispworks.com/support/lisp-hug.html