subclasses detect

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

subclasses detect

gruntfuttuck
Hello

In the laser game tutorial by Stephan B Wessels I was intrerested by this code:

directionFor: aSymbol
        ^ self subclasses
                detect: [:cls | cls directionSymbol = aSymbol]


The code appears here at the bottom of the page: http://squeak.preeminent.org/tut2007/html/038.html 

What I read this code as doing, in this example is: return an symbol object which is a sublass instance varable, if it is the same as aSymbol.

What would happen if more than one subclass object had a match?

Also how else can subclasses detect: be used? It looks very interesting.

Grunt

 
Reply | Threaded
Open this post in threaded view
|

Re: subclasses detect

Steve Wessels
Its returning the actual matched class object.  Not a symbol.

  - Steve

Sent from my iPhone

On Jul 31, 2007, at 3:14 PM, gruntfuttuck <[hidden email]> wrote:


Hello

In the laser game tutorial by Stephan B Wessels I was intrerested by this
code:

directionFor: aSymbol
   ^ self subclasses
       detect: [:cls | cls directionSymbol = aSymbol]

The code appears here at the bottom of the page:
http://squeak.preeminent.org/tut2007/html/038.html 

What I read this code as doing, in this example is: return an symbol object
which is a sublass instance varable, if it is the same as aSymbol.

What would happen if more than one subclass object had a match?

Also how else can subclasses detect: be used? It looks very interesting.

Grunt


--
View this message in context: http://www.nabble.com/subclasses-detect-tf4196202.html#a11934239
Sent from the Squeak - Beginners mailing list archive at Nabble.com.

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners



       
____________________________________________________________________________________
Take the Internet to Go: Yahoo!Go puts the Internet in your pocket: mail, news, photos & more.
http://mobile.yahoo.com/go?refer=1GNXIC
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: subclasses detect

David Mitchell-10
In reply to this post by gruntfuttuck
The message #subclasses returns a collection of Class objects
The message #detect: returns the first object in that collection that
matches the criteria in the block

Since detect is the last message sent before the return, one class
object will be returned.

If more than one matches, the code will never know, since detect:
returns on the first match. It won't evaluate to find the other match.
That is, it short circuits the iteration.

If you want to return a collection of matches, send the #select:
message instead of #detect:.

Nothing to do with class instance variables (those are rare birds --
misused as often as they are needed).

Also realize that the message isn't "subclasses detect". They are two
separate messages. #detect: works with any collection. #subclasses
returns a collection.




On 7/31/07, gruntfuttuck <[hidden email]> wrote:

>
> Hello
>
> In the laser game tutorial by Stephan B Wessels I was intrerested by this
> code:
>
> directionFor: aSymbol
>         ^ self subclasses
>                 detect: [:cls | cls directionSymbol = aSymbol]
>
> The code appears here at the bottom of the page:
> http://squeak.preeminent.org/tut2007/html/038.html
>
> What I read this code as doing, in this example is: return an symbol object
> which is a sublass instance varable, if it is the same as aSymbol.
>
> What would happen if more than one subclass object had a match?
>
> Also how else can subclasses detect: be used? It looks very interesting.
>
> Grunt
>
>
> --
> View this message in context: http://www.nabble.com/subclasses-detect-tf4196202.html#a11934239
> Sent from the Squeak - Beginners mailing list archive at Nabble.com.
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: subclasses detect

gruntfuttuck
Thank you, that was very clear and helpful :-)

David Mitchell-10 wrote
The message #subclasses returns a collection of Class objects
The message #detect: returns the first object in that collection that
matches the criteria in the block

Since detect is the last message sent before the return, one class
object will be returned.

If more than one matches, the code will never know, since detect:
returns on the first match. It won't evaluate to find the other match.
That is, it short circuits the iteration.

If you want to return a collection of matches, send the #select:
message instead of #detect:.

Nothing to do with class instance variables (those are rare birds --
misused as often as they are needed).

Also realize that the message isn't "subclasses detect". They are two
separate messages. #detect: works with any collection. #subclasses
returns a collection.




On 7/31/07, gruntfuttuck <gruntfuttuck@gmail.com> wrote:
>
> Hello
>
> In the laser game tutorial by Stephan B Wessels I was intrerested by this
> code:
>
> directionFor: aSymbol
>         ^ self subclasses
>                 detect: [:cls | cls directionSymbol = aSymbol]
>
> The code appears here at the bottom of the page:
> http://squeak.preeminent.org/tut2007/html/038.html
>
> What I read this code as doing, in this example is: return an symbol object
> which is a sublass instance varable, if it is the same as aSymbol.
>
> What would happen if more than one subclass object had a match?
>
> Also how else can subclasses detect: be used? It looks very interesting.
>
> Grunt
>
>
> --
> View this message in context: http://www.nabble.com/subclasses-detect-tf4196202.html#a11934239
> Sent from the Squeak - Beginners mailing list archive at Nabble.com.
>
> _______________________________________________
> Beginners mailing list
> Beginners@lists.squeakfoundation.org
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>
_______________________________________________
Beginners mailing list
Beginners@lists.squeakfoundation.org
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: subclasses detect

Steve Wessels
In reply to this post by gruntfuttuck
David's message is excellent.  The idiom used by this method is useful to understand.  I actually make a point of describing it's role as a substitution for a Case statement in a section just a few pages later in the Tutorial.  Check out page 048A.html

- Steve

Sent from my iPhone

On Jul 31, 2007, at 4:00 PM, gruntfuttuck <[hidden email]> wrote:


Thank you, that was very clear and helpful :-)


David Mitchell-10 wrote:

The message #subclasses returns a collection of Class objects
The message #detect: returns the first object in that collection that
matches the criteria in the block

Since detect is the last message sent before the return, one class
object will be returned.

If more than one matches, the code will never know, since detect:
returns on the first match. It won't evaluate to find the other match.
That is, it short circuits the iteration.

If you want to return a collection of matches, send the #select:
message instead of #detect:.

Nothing to do with class instance variables (those are rare birds --
misused as often as they are needed).

Also realize that the message isn't "subclasses detect". They are two
separate messages. #detect: works with any collection. #subclasses
returns a collection.




On 7/31/07, gruntfuttuck <[hidden email]> wrote:

Hello

In the laser game tutorial by Stephan B Wessels I was intrerested by this
code:

directionFor: aSymbol
       ^ self subclasses
               detect: [:cls | cls directionSymbol = aSymbol]

The code appears here at the bottom of the page:
http://squeak.preeminent.org/tut2007/html/038.html

What I read this code as doing, in this example is: return an symbol
object
which is a sublass instance varable, if it is the same as aSymbol.

What would happen if more than one subclass object had a match?

Also how else can subclasses detect: be used? It looks very interesting.

Grunt


--
View this message in context:
http://www.nabble.com/subclasses-detect-tf4196202.html#a11934239
Sent from the Squeak - Beginners mailing list archive at Nabble.com.

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners



--
View this message in context: http://www.nabble.com/subclasses-detect-tf4196202.html#a11935026
Sent from the Squeak - Beginners mailing list archive at Nabble.com.

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners



       
____________________________________________________________________________________
Boardwalk for $500? In 2007? Ha! Play Monopoly Here and Now (it's updated for today's economy) at Yahoo! Games.
http://get.games.yahoo.com/proddesc?gamekey=monopolyherenow
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: subclasses detect

gruntfuttuck
Thanks Steve, loving the tutorial. I wouldn't have given squeak another try if it wasn't for your fabulous tutorial.

My Girlfriend asked my what I was thinking about, after sex, the other day. I didn't dare tell her, squeak code, so I said, our new home that we are getting together.



Steve Wessels wrote
David's message is excellent.  The idiom used by this method is useful to understand.  I actually make a point of describing it's role as a substitution for a Case statement in a section just a few pages later in the Tutorial.  Check out page 048A.html

- Steve

Sent from my iPhone

On Jul 31, 2007, at 4:00 PM, gruntfuttuck <gruntfuttuck@gmail.com> wrote:


Thank you, that was very clear and helpful :-)


David Mitchell-10 wrote:

The message #subclasses returns a collection of Class objects
The message #detect: returns the first object in that collection that
matches the criteria in the block

Since detect is the last message sent before the return, one class
object will be returned.

If more than one matches, the code will never know, since detect:
returns on the first match. It won't evaluate to find the other match.
That is, it short circuits the iteration.

If you want to return a collection of matches, send the #select:
message instead of #detect:.

Nothing to do with class instance variables (those are rare birds --
misused as often as they are needed).

Also realize that the message isn't "subclasses detect". They are two
separate messages. #detect: works with any collection. #subclasses
returns a collection.




On 7/31/07, gruntfuttuck <gruntfuttuck@gmail.com> wrote:

Hello

In the laser game tutorial by Stephan B Wessels I was intrerested by this
code:

directionFor: aSymbol
       ^ self subclasses
               detect: [:cls | cls directionSymbol = aSymbol]

The code appears here at the bottom of the page:
http://squeak.preeminent.org/tut2007/html/038.html

What I read this code as doing, in this example is: return an symbol
object
which is a sublass instance varable, if it is the same as aSymbol.

What would happen if more than one subclass object had a match?

Also how else can subclasses detect: be used? It looks very interesting.

Grunt


--
View this message in context:
http://www.nabble.com/subclasses-detect-tf4196202.html#a11934239
Sent from the Squeak - Beginners mailing list archive at Nabble.com.

_______________________________________________
Beginners mailing list
Beginners@lists.squeakfoundation.org
http://lists.squeakfoundation.org/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
Beginners@lists.squeakfoundation.org
http://lists.squeakfoundation.org/mailman/listinfo/beginners



--
View this message in context: http://www.nabble.com/subclasses-detect-tf4196202.html#a11935026
Sent from the Squeak - Beginners mailing list archive at Nabble.com.

_______________________________________________
Beginners mailing list
Beginners@lists.squeakfoundation.org
http://lists.squeakfoundation.org/mailman/listinfo/beginners



       
____________________________________________________________________________________
Boardwalk for $500? In 2007? Ha! Play Monopoly Here and Now (it's updated for today's economy) at Yahoo! Games.
http://get.games.yahoo.com/proddesc?gamekey=monopolyherenow
_______________________________________________
Beginners mailing list
Beginners@lists.squeakfoundation.org
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: subclasses detect

Steve Wessels
In reply to this post by gruntfuttuck
My God, that's funny.  

Thank you for your kind words.  

Squeak has a special place in my "heart" too.

- Steve

Sent from my iPhone

On Jul 31, 2007, at 5:33 PM, gruntfuttuck <[hidden email]> wrote:


Thanks Steve, loving the tutorial. I wouldn't have given squeak another try
if it wasn't for your fabulous tutorial.

My Girlfriend asked my what I was thinking about, after sex, the other day.
I didn't dare tell her, squeak code, so I said, our new home that we are
getting together.




Steve Wessels wrote:

David's message is excellent.  The idiom used by this method is useful to
understand.  I actually make a point of describing it's role as a
substitution for a Case statement in a section just a few pages later in
the Tutorial.  Check out page 048A.html

- Steve

Sent from my iPhone

On Jul 31, 2007, at 4:00 PM, gruntfuttuck <[hidden email]> wrote:


Thank you, that was very clear and helpful :-)


David Mitchell-10 wrote:

The message #subclasses returns a collection of Class objects
The message #detect: returns the first object in that collection that
matches the criteria in the block

Since detect is the last message sent before the return, one class
object will be returned.

If more than one matches, the code will never know, since detect:
returns on the first match. It won't evaluate to find the other match.
That is, it short circuits the iteration.

If you want to return a collection of matches, send the #select:
message instead of #detect:.

Nothing to do with class instance variables (those are rare birds --
misused as often as they are needed).

Also realize that the message isn't "subclasses detect". They are two
separate messages. #detect: works with any collection. #subclasses
returns a collection.




On 7/31/07, gruntfuttuck <[hidden email]> wrote:

Hello

In the laser game tutorial by Stephan B Wessels I was intrerested by this
code:

directionFor: aSymbol
      ^ self subclasses
              detect: [:cls | cls directionSymbol = aSymbol]

The code appears here at the bottom of the page:
http://squeak.preeminent.org/tut2007/html/038.html

What I read this code as doing, in this example is: return an symbol
object
which is a sublass instance varable, if it is the same as aSymbol.

What would happen if more than one subclass object had a match?

Also how else can subclasses detect: be used? It looks very interesting.

Grunt


--
View this message in context:
http://www.nabble.com/subclasses-detect-tf4196202.html#a11934239
Sent from the Squeak - Beginners mailing list archive at Nabble.com.

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners



--
View this message in context:
http://www.nabble.com/subclasses-detect-tf4196202.html#a11935026
Sent from the Squeak - Beginners mailing list archive at Nabble.com.

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners




____________________________________________________________________________________
Boardwalk for $500? In 2007? Ha! Play Monopoly Here and Now (it's updated
for today's economy) at Yahoo! Games.
http://get.games.yahoo.com/proddesc?gamekey=monopolyherenow
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners



--
View this message in context: http://www.nabble.com/subclasses-detect-tf4196202.html#a11936372
Sent from the Squeak - Beginners mailing list archive at Nabble.com.

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners



       
____________________________________________________________________________________
Pinpoint customers who are looking for what you sell.
http://searchmarketing.yahoo.com/
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: subclasses detect

Offray Vladimir Luna Cárdenas
Hi Steve,

I think that this tutorial is great. I would like to make a translation
to Spanish for my students later this year. Have you consider releasing
it under a Creative Commons license (or something similar) to make
derivated works of it (like translations)?

Cheers and thanks for your tutorial,

Offray

Steve Wessels escribió:

> My God, that's funny.  
>
> Thank you for your kind words.  
>
> Squeak has a special place in my "heart" too.
>
> - Steve
>
> Sent from my iPhone
>
> On Jul 31, 2007, at 5:33 PM, gruntfuttuck <[hidden email]> wrote:
>
>
> Thanks Steve, loving the tutorial. I wouldn't have given squeak another try
> if it wasn't for your fabulous tutorial.
>
> My Girlfriend asked my what I was thinking about, after sex, the other day.
> I didn't dare tell her, squeak code, so I said, our new home that we are
> getting together.
>
>
>
>
> Steve Wessels wrote:
>
> David's message is excellent.  The idiom used by this method is useful to
> understand.  I actually make a point of describing it's role as a
> substitution for a Case statement in a section just a few pages later in
> the Tutorial.  Check out page 048A.html
>
> - Steve
>
> Sent from my iPhone
>
> On Jul 31, 2007, at 4:00 PM, gruntfuttuck <[hidden email]> wrote:
>
>
> Thank you, that was very clear and helpful :-)
>
>
> David Mitchell-10 wrote:
>
> The message #subclasses returns a collection of Class objects
> The message #detect: returns the first object in that collection that
> matches the criteria in the block
>
> Since detect is the last message sent before the return, one class
> object will be returned.
>
> If more than one matches, the code will never know, since detect:
> returns on the first match. It won't evaluate to find the other match.
> That is, it short circuits the iteration.
>
> If you want to return a collection of matches, send the #select:
> message instead of #detect:.
>
> Nothing to do with class instance variables (those are rare birds --
> misused as often as they are needed).
>
> Also realize that the message isn't "subclasses detect". They are two
> separate messages. #detect: works with any collection. #subclasses
> returns a collection.
>
>
>
>
> On 7/31/07, gruntfuttuck <[hidden email]> wrote:
>
> Hello
>
> In the laser game tutorial by Stephan B Wessels I was intrerested by this
> code:
>
> directionFor: aSymbol
>       ^ self subclasses
>               detect: [:cls | cls directionSymbol = aSymbol]
>
> The code appears here at the bottom of the page:
> http://squeak.preeminent.org/tut2007/html/038.html
>
> What I read this code as doing, in this example is: return an symbol
> object
> which is a sublass instance varable, if it is the same as aSymbol.
>
> What would happen if more than one subclass object had a match?
>
> Also how else can subclasses detect: be used? It looks very interesting.
>
> Grunt
>
>
> --
> View this message in context:
> http://www.nabble.com/subclasses-detect-tf4196202.html#a11934239
> Sent from the Squeak - Beginners mailing list archive at Nabble.com.
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>
>
>
>  
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners