From: Andreas Davour
Subject: Hot do I access elements of a struct, really?
Date: 
Message-ID: <cs9lk8senzs.fsf@Psilocybe.Update.UU.SE>
Lets say I define a struct like this:
(DEFSTRUCT foo vector start end)

Make an instance:
(MAKE-FOO my-foo :vector (MAKE-ARRAY 10) :start 0 :end 10)

Now I can set a value in the struct:
(setf (foo-start my-foo) 7)

But, how do I access it? If I evalute MY-FOO I get to see the value, but
if I don't want the whole object but just the value of :start, what then?

Yeah, I know I should probably learn CLOS and ignore DEFSTRUCT, but I
want to understand this and I don't think it's wise to go to some other
complex things before I understand this.

/Andreas

-- 
A: Because it fouls the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

From: Pillsy
Subject: Re: Hot do I access elements of a struct, really?
Date: 
Message-ID: <4cfdc221-8fa1-4185-b48b-564b54fc0f4e@a28g2000hsc.googlegroups.com>
On Nov 20, 2:05 pm, Andreas Davour <·······@updateLIKE.uu.HELLse>
wrote:

> But, how do I access it? If I evalute MY-FOO I get to see the value, but
> if I don't want the whole object but just the value of :start, what then?

Um, (FOO-START object) will return the value of the START slot if you
just use it outside of the SETF form.

Cheers,
Pillsy
From: Andreas Davour
Subject: Re: Hot do I access elements of a struct, really?
Date: 
Message-ID: <cs9hcjgemv1.fsf@Psilocybe.Update.UU.SE>
Pillsy <·········@gmail.com> writes:

> On Nov 20, 2:05 pm, Andreas Davour <·······@updateLIKE.uu.HELLse>
> wrote:
>
>> But, how do I access it? If I evalute MY-FOO I get to see the value, but
>> if I don't want the whole object but just the value of :start, what then?
>
> Um, (FOO-START object) will return the value of the START slot if you
> just use it outside of the SETF form.

I swear it didn't work when I first tried that. Damn, I really don't
understand these things, that's obvious.

Thanks.

/Andreas

-- 
A: Because it fouls the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
From: Maciej Katafiasz
Subject: Re: Hot do I access elements of a struct, really?
Date: 
Message-ID: <fhvgeh$m99$2@news.net.uni-c.dk>
Den Tue, 20 Nov 2007 20:05:43 +0100 skrev Andreas Davour:

> Yeah, I know I should probably learn CLOS and ignore DEFSTRUCT, but I
> want to understand this and I don't think it's wise to go to some other
> complex things before I understand this.

Defstruct & co. have absolutely no bearing on understanding CLOS. As far 
as I know, they're there solely for the purpose of providing backwards 
compatibility with some pre-CLOS OO systems, and are generally regarded 
to be in a poor style (by implicitly defining some methods behind your 
back, like, say, the thing you just had problems with :).

Cheers,
Maciej
From: Ken Tilton
Subject: Re: Hot do I access elements of a struct, really?
Date: 
Message-ID: <MVN0j.135$bQ2.102@newsfe08.lga>
Maciej Katafiasz wrote:
> Den Tue, 20 Nov 2007 20:05:43 +0100 skrev Andreas Davour:
> 
> 
>>Yeah, I know I should probably learn CLOS and ignore DEFSTRUCT, but I
>>want to understand this and I don't think it's wise to go to some other
>>complex things before I understand this.
> 
> 
> Defstruct & co. have absolutely no bearing on understanding CLOS. As far 
> as I know,...

When "as far as I know" evaluates to zero....well, I don't want to hurt 
your feelings.

>... they're there solely for the purpose of providing backwards 
> compatibility with some pre-CLOS OO systems,

OK, that does it, STFU! hth.

> and are generally regarded 
> to be in a poor style (by implicitly defining some methods behind your 
> back, like, say, the thing you just had problems with :).

Generally? As in General Custer? <sigh>

defstruct is fine, CLOS (ok, Gabriel and Graham were right, Kenny was 
wrong) and all of OO was a huge, bloated, unjustifiable, government 
cheese. Cells/CLOS is deprecated, watch this space for Cells/Next 
Generation.

kt

-- 
http://www.theoryyalgebra.com/

"In the morning, hear the Way;
  in the evening, die content!"
                     -- Confucius
From: Jason
Subject: Re: Hot do I access elements of a struct, really?
Date: 
Message-ID: <550af769-9c1a-4d11-839c-71044597173c@b15g2000hsa.googlegroups.com>
On Nov 20, 7:49 pm, Ken Tilton <···········@optonline.net> wrote:
> Maciej Katafiasz wrote:
> > Den Tue, 20 Nov 2007 20:05:43 +0100 skrev Andreas Davour:
>
> >>Yeah, I know I should probably learn CLOS and ignore DEFSTRUCT, but I
> >>want to understand this and I don't think it's wise to go to some other
> >>complex things before I understand this.
>
> > Defstruct & co. have absolutely no bearing on understanding CLOS. As far
> > as I know,...
>
> When "as far as I know" evaluates to zero....well, I don't want to hurt
> your feelings.
>
> >... they're there solely for the purpose of providing backwards
> > compatibility with some pre-CLOS OO systems,
>
> OK, that does it, STFU! hth.
>
> > and are generally regarded
> > to be in a poor style (by implicitly defining some methods behind your
> > back, like, say, the thing you just had problems with :).
>
> Generally? As in General Custer? <sigh>
>
> defstruct is fine, CLOS (ok, Gabriel and Graham were right, Kenny was
> wrong) and all of OO was a huge, bloated, unjustifiable, government
> cheese. Cells/CLOS is deprecated, watch this space for Cells/Next
> Generation.
>

Amoebas?
From: Ken Tilton
Subject: Re: Hot do I access elements of a struct, really?
Date: 
Message-ID: <fQU0j.1$352.0@newsfe08.lga>
Jason wrote:
> On Nov 20, 7:49 pm, Ken Tilton <···········@optonline.net> wrote:
> 
>>Maciej Katafiasz wrote:
>>
>>>Den Tue, 20 Nov 2007 20:05:43 +0100 skrev Andreas Davour:
>>
>>>>Yeah, I know I should probably learn CLOS and ignore DEFSTRUCT, but I
>>>>want to understand this and I don't think it's wise to go to some other
>>>>complex things before I understand this.
>>
>>>Defstruct & co. have absolutely no bearing on understanding CLOS. As far
>>>as I know,...
>>
>>When "as far as I know" evaluates to zero....well, I don't want to hurt
>>your feelings.
>>
>>
>>>... they're there solely for the purpose of providing backwards
>>>compatibility with some pre-CLOS OO systems,
>>
>>OK, that does it, STFU! hth.
>>
>>
>>>and are generally regarded
>>>to be in a poor style (by implicitly defining some methods behind your
>>>back, like, say, the thing you just had problems with :).
>>
>>Generally? As in General Custer? <sigh>
>>
>>defstruct is fine, CLOS (ok, Gabriel and Graham were right, Kenny was
>>wrong) and all of OO was a huge, bloated, unjustifiable, government
>>cheese. Cells/CLOS is deprecated, watch this space for Cells/Next
>>Generation.
>>
> 
> 
> Amoebas?

Sure! But I was always partial to the paramecium, and let's not forget 
the euglena.

No, this will be TripleCells*, not to be confused with Cells3. Just need 
a fast btree implementation. Throw in Redland and we gots persistence! 
Screw the MOP, big bloated mistake. Hell, the size alone says "Hang on, 
this can't be right."

Set your information (programmers) free!

kzo

* Unless we can come up with a cell that has threeness about it. k

-- 
http://www.theoryyalgebra.com/

"In the morning, hear the Way;
  in the evening, die content!"
                     -- Confucius
From: John Thingstad
Subject: Re: Hot do I access elements of a struct, really?
Date: 
Message-ID: <op.t132h9uout4oq5@pandora.alfanett.no>
P� Tue, 20 Nov 2007 21:35:29 +0100, skrev Maciej Katafiasz  
<········@gmail.com>:

> Den Tue, 20 Nov 2007 20:05:43 +0100 skrev Andreas Davour:
>
>> Yeah, I know I should probably learn CLOS and ignore DEFSTRUCT, but I
>> want to understand this and I don't think it's wise to go to some other
>> complex things before I understand this.
>
> Defstruct & co. have absolutely no bearing on understanding CLOS. As far
> as I know, they're there solely for the purpose of providing backwards
> compatibility with some pre-CLOS OO systems, and are generally regarded
> to be in a poor style (by implicitly defining some methods behind your
> back, like, say, the thing you just had problems with :).
>
> Cheers,
> Maciej
>

Well struct's can do some things that classes can't like destructure lists  
in a readable way.

consider what I wrote some other place today:

(defstruct (clause (:type list)) predicate conclusion)

(defparameter test '((a b) (b c) (m n))

(defun modus-ponens (clause-1 clause-2)
   (if (equalp (clause-predicate clause-2)
               (clause-conclusion clause-1)
       (make-clause :predicate (clause-predicate clause-1)
                    :conclusion (clause-conclusion clause-2))
       nil))

cl-user: (modus-ponens (first test) (second test))
(a c)
cl-user: (modus-ponens (first test) (third test))
nil

You can change the naming convention if you like.
Werther you find this sort of thing worth while.. Well that is a different  
story.


--------------
John Thingstad
From: Tim Bradshaw
Subject: Re: Hot do I access elements of a struct, really?
Date: 
Message-ID: <97fb8961-9fd7-4683-8fb8-476a4da8106f@y43g2000hsy.googlegroups.com>
On Nov 20, 8:35 pm, Maciej Katafiasz <········@gmail.com> wrote:

> Defstruct & co. have absolutely no bearing on understanding CLOS. As far
> as I know, they're there solely for the purpose of providing backwards
> compatibility with some pre-CLOS OO systems, and are generally regarded
> to be in a poor style (by implicitly defining some methods behind your
> back, like, say, the thing you just had problems with :).

That's wrong in more ways than I have time to say.
From: Ken Tilton
Subject: Re: Hot do I access elements of a struct, really?
Date: 
Message-ID: <XCV0j.8$QY3.6@newsfe10.lga>
Tim Bradshaw wrote:
> On Nov 20, 8:35 pm, Maciej Katafiasz <········@gmail.com> wrote:
> 
> 
>>Defstruct & co. have absolutely no bearing on understanding CLOS. As far
>>as I know, they're there solely for the purpose of providing backwards
>>compatibility with some pre-CLOS OO systems, and are generally regarded
>>to be in a poor style (by implicitly defining some methods behind your
>>back, like, say, the thing you just had problems with :).
> 
> 
> That's wrong in more ways than I have time to say.

Yes, a prize may be in order. But basic teleology suggests this must be 
a hoax; one could not achieve such severity-weighted density of 
misinformation without Intelligent Design.

kzo

-- 
http://www.theoryyalgebra.com/

"In the morning, hear the Way;
  in the evening, die content!"
                     -- Confucius
From: Pascal Costanza
Subject: Re: Hot do I access elements of a struct, really?
Date: 
Message-ID: <5qib1nF103lofU1@mid.individual.net>
Maciej Katafiasz wrote:
> Den Tue, 20 Nov 2007 20:05:43 +0100 skrev Andreas Davour:
> 
>> Yeah, I know I should probably learn CLOS and ignore DEFSTRUCT, but I
>> want to understand this and I don't think it's wise to go to some other
>> complex things before I understand this.
> 
> Defstruct & co. have absolutely no bearing on understanding CLOS. As far 
> as I know, they're there solely for the purpose of providing backwards 
> compatibility with some pre-CLOS OO systems, and are generally regarded 
> to be in a poor style (by implicitly defining some methods behind your 
> back, like, say, the thing you just had problems with :).

You sound like a Schemer. ;)

While it's true that when in doubt, CLOS classes are typically 'better' 
than structs, structs have justified uses. Among other things, they are 
typically more efficient than CLOS objects because they are restricted 
to single inheritance, are not required to support redefinition at 
runtime and do not have a notion of unbound slots.

The fact that they generate a couple of default functions for your makes 
them also very convenient to use in some scenarios.

It would be nice if some features of structs were available in CLOS and 
vice versa, but overall I think the feature sets are pretty well 
distributed among those two.


Pascal

-- 
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/
From: Marco Antoniotti
Subject: Re: Hot do I access elements of a struct, really?
Date: 
Message-ID: <294c397d-1ec9-4cf0-9eb1-59bab9a6304e@y5g2000hsf.googlegroups.com>
On Nov 21, 10:11 am, Pascal Costanza <····@p-cos.net> wrote:
> Maciej Katafiasz wrote:
> > Den Tue, 20 Nov 2007 20:05:43 +0100 skrev Andreas Davour:
>
> >> Yeah, I know I should probably learn CLOS and ignore DEFSTRUCT, but I
> >> want to understand this and I don't think it's wise to go to some other
> >> complex things before I understand this.
>
> > Defstruct & co. have absolutely no bearing on understanding CLOS. As far
> > as I know, they're there solely for the purpose of providing backwards
> > compatibility with some pre-CLOS OO systems, and are generally regarded
> > to be in a poor style (by implicitly defining some methods behind your
> > back, like, say, the thing you just had problems with :).
>
> You sound like a Schemer. ;)
>
> While it's true that when in doubt, CLOS classes are typically 'better'
> than structs, structs have justified uses. Among other things, they are
> typically more efficient than CLOS objects because they are restricted
> to single inheritance, are not required to support redefinition at
> runtime and do not have a notion of unbound slots.
>
> The fact that they generate a couple of default functions for your makes
> them also very convenient to use in some scenarios.
>
> It would be nice if some features of structs were available in CLOS and
> vice versa, but overall I think the feature sets are pretty well
> distributed among those two.
>

Yep.  I find myself pretty much always doing the following

(defclass foo () ())

(defgeneric foop (x)
  (:method ((x foo)) t)
  (:method ((x t)) nil))

It'd be nice to have at least the predicate defined automatically (*)

Apart from that, DEFSTRUCTs are very useful, and they do not prevent
you from using CLOS and methods.  This is a big plus.

Cheers

--
Marco

(*) Yes.  I know it is just a macro away.






> Pascal
>
> --
> My website:http://p-cos.net
> Common Lisp Document Repository:http://cdr.eurolisp.org
> Closer to MOP & ContextL:http://common-lisp.net/project/closer/
From: Vebjorn Ljosa
Subject: Re: Hot do I access elements of a struct, really?
Date: 
Message-ID: <nq5ir3vvcj1.fsf@gm3b6-dd5.broad.mit.edu>
Marco Antoniotti <·······@gmail.com> writes:
>
> Yep.  I find myself pretty much always doing the following
>
> (defclass foo () ())
>
> (defgeneric foop (x)
>   (:method ((x foo)) t)
>   (:method ((x t)) nil))
>
> It'd be nice to have at least the predicate defined automatically
> (*)

Why not use TYPEP?

Vebjorn