hey,
I want to use WITH-SLOTS with structs. Is that portable? It was hard
to tell when reading the CLHS. Of course, it works in LW, but I want
to use it only if it's portable.
thanks,
dave
·····@alum.mit.edu (Dave Bakhash) writes:
> hey,
>
> I want to use WITH-SLOTS with structs. Is that portable? It was hard
> to tell when reading the CLHS. Of course, it works in LW, but I want
> to use it only if it's portable.
>
> thanks,
> dave
Nope, it's not. WITH-SLOTS uses SLOT-VALUE, which is unspecified for
objects with metaclass STRUCTURE-CLASS.
--
/|_ .-----------------------.
,' .\ / | No to Imperialist war |
,--' _,' | Wage class war! |
/ / `-----------------------'
( -. |
| ) |
(`-. '--.)
`. )----'
From: Tim Bradshaw
Subject: Re: is using WITH-SLOTS with structs portable?
Date:
Message-ID: <ey3hdw5sfc6.fsf@cley.com>
* Dave Bakhash wrote:
> hey,
> I want to use WITH-SLOTS with structs. Is that portable? It was hard
> to tell when reading the CLHS. Of course, it works in LW, but I want
> to use it only if it's portable.
No, it's not. You can generally get most of the way (`variables'
which are actually accessors) using something based on SYMBOL-MACROLET
though.
--tim
hey,
thanks for the info, guys.
I think I'll use it anyway...I guess at this point I'm (hapily)
married to LW anyway.
dave
From: Alain Picard
Subject: Re: is using WITH-SLOTS with structs portable?
Date:
Message-ID: <87oeqct00j.fsf@memetrics.com>
·····@alum.mit.edu (Dave Bakhash) writes:
> hey,
>
> thanks for the info, guys.
>
> I think I'll use it anyway...I guess at this point I'm (hapily)
> married to LW anyway.
You could write a macro WITH-STRUCTURE-SLOTS which, for LW,
just expands into WITH-SLOTS. That way, on some other implementation,
you could write a groovy macro which expands into the
required symbol-macrolet forms.
At the very least, it shows the reader that this is non-standard code.
Just a thought.
Alain Picard <············@memetrics.com> writes:
> You could write a macro WITH-STRUCTURE-SLOTS which, for LW,
> just expands into WITH-SLOTS. That way, on some other implementation,
> you could write a groovy macro which expands into the
> required symbol-macrolet forms.
Probably a stupid question, but could you just write a new defstruct
in terms of defclass instead?
-Luke (CLOS ignoramus)
Yes. But you would take a performance hit.
(defclass struct ()
((slot1 :accessor slot1 :initarg :slot1)
...))
is roughly the same as defstruct.
On Thu, 01 Apr 2004 13:28:14 +0200, Luke Gorrie <····@bluetail.com> wrote:
> Alain Picard <············@memetrics.com> writes:
>
>> You could write a macro WITH-STRUCTURE-SLOTS which, for LW,
>> just expands into WITH-SLOTS. That way, on some other implementation,
>> you could write a groovy macro which expands into the
>> required symbol-macrolet forms.
>
> Probably a stupid question, but could you just write a new defstruct
> in terms of defclass instead?
>
> -Luke (CLOS ignoramus)
>
--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
From: Alain Picard
Subject: Re: is using WITH-SLOTS with structs portable?
Date:
Message-ID: <878yhdmn1a.fsf@memetrics.com>
Luke Gorrie <····@bluetail.com> writes:
> Alain Picard <············@memetrics.com> writes:
>
>> You could write a macro WITH-STRUCTURE-SLOTS which, for LW,
>> just expands into WITH-SLOTS. That way, on some other implementation,
>> you could write a groovy macro which expands into the
>> required symbol-macrolet forms.
>
> Probably a stupid question, but could you just write a new defstruct
> in terms of defclass instead?
You certainly could, but the OP wanted to use structs, and I
imagine he had his reasons. Since I know the OP, I even imagine
his reasons were probably reasonable. ;-)
Alain Picard wrote:
> You certainly could, but the OP wanted to use structs, and I
> imagine he had his reasons. Since I know the OP, I even imagine
> his reasons were probably reasonable. ;-)
I find the thread that progressed from the original question to be
rather blind to ab obvious issue.
It is true that in most implementations slot-value works on a
structure-object, but aside from back compatiblity, the usual reason
for using structure-class rather than standard-class is considerations
of execution efficiency. As typically implemented, a structure-class
achieves slight slot reference efficiency ove stadnard-class at the
cost of redefinition flexibility (and sometimes debuggability). I
won't here express an opinion about the losers who insist on exploiting
this negligible efficiency without ever having measured its actual
impact, because there remain very occasional circumstances where
structure-objects are warranted over standard-object.
But aside from portability, programmers tempted to use with-slots on
a structure-object shiould consider the efficiency issue. If, as is
likely, with-slots symbol macroexpands insto slot-value, the efficiency
of slot-value on a structure-object must be considered. with-slots
on a structure object (in implementations that support it) might be
quite useful in a high-level introspection tool, but might be
entirely inappropriate in some inner computational loop. with-slots
was designed to be cleverly optimizable, at least inside a specialized
mathod body, so the programmer doesn't need to be concerned too much
about its use. Not so with-slots on a structure-object, which
performance probably hasn't been carefully considered either by the
language designers not the language implementors, and whose performance
might have a very different impedance that regular structure slot
accessors.
·····@alum.mit.edu (Dave Bakhash) writes:
> hey,
>
> thanks for the info, guys.
>
> I think I'll use it anyway...I guess at this point I'm (hapily)
> married to LW anyway.
Not to try to break up your happy marriage, but although it's not
specified by the standard, it's a very common extension. Certainly
CMUCL/SBCL and MCL/OpenMCL let you use WITH-SLOTS on structures.
--
/|_ .-----------------------.
,' .\ / | No to Imperialist war |
,--' _,' | Wage class war! |
/ / `-----------------------'
( -. |
| ) |
(`-. '--.)
`. )----'