Quantcast

Easy question about syntax.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Easy question about syntax.

sergio ruiz
I have a simple one, but i need to understand what is going on..

i have something like

Tree

with a class method

trees
^ trees ifNil: [OrderedCollection new]

i initially ran into trouble with it locking my image up because i wrote it as:

trees
^ self trees ifNil: [OrderedCollection new]

what is the semantic difference between these two calls?

THanks!

 

----
peace,
sergio
photographer, journalist, visionary

Public Key: http://bit.ly/29z9fG0
#BitMessage BM-NBaswViL21xqgg9STRJjaJaUoyiNe2dV
http://www.Village-Buzz.com
http://www.ThoseOptimizeGuys.com
http://www.coffee-black.com
http://www.painlessfrugality.com
http://www.twitter.com/sergio_101
http://www.facebook.com/sergio101

signature.asc (852 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Easy question about syntax.

vonbecmann
i think that in the first case you access an instance variable trees while in the second case you send a message trees to self that cause an infinite recursion.
am i right?


On Sat, Mar 11, 2017 at 12:57 AM, sergio ruiz <[hidden email]> wrote:
I have a simple one, but i need to understand what is going on..

i have something like

Tree

with a class method

trees
^ trees ifNil: [OrderedCollection new]

i initially ran into trouble with it locking my image up because i wrote it as:

trees
^ self trees ifNil: [OrderedCollection new]

what is the semantic difference between these two calls?

THanks!

 




--
Bernardo E.C.

Sent from a cheap desktop computer in South America.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Easy question about syntax.

JupiterJones
Also, you’re not setting the instance variable - just returning an OrderedCollection - is that what you want to do?

e.g. setting the trees instance variable:

trees
^ trees ifNil: [ trees := OrderedCollection new ]

like Bernardo said, when you call #trees from within the #trees method (with self trees) - like in your first example, you created an infinite loop.

On 11 Mar 2017, at 3:36 pm, Bernardo Ezequiel Contreras <[hidden email]> wrote:

i think that in the first case you access an instance variable trees while in the second case you send a message trees to self that cause an infinite recursion.
am i right?


On Sat, Mar 11, 2017 at 12:57 AM, sergio ruiz <[hidden email]> wrote:
I have a simple one, but i need to understand what is going on..

i have something like

Tree

with a class method

trees
^ trees ifNil: [OrderedCollection new]

i initially ran into trouble with it locking my image up because i wrote it as:

trees
^ self trees ifNil: [OrderedCollection new]

what is the semantic difference between these two calls?

THanks!

 




--
Bernardo E.C.

Sent from a cheap desktop computer in South America.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Easy question about syntax.

NorbertHartl
In reply to this post by sergio ruiz


Am 11.03.2017 um 04:57 schrieb sergio ruiz <[hidden email]>:

I have a simple one, but i need to understand what is going on..

i have something like

Tree

with a class method

trees
^ trees ifNil: [OrderedCollection new]

i initially ran into trouble with it locking my image up because i wrote it as:

trees
^ self trees ifNil: [OrderedCollection new]

what is the semantic difference between these two calls?

The first one accesses the instance variable. The second one calls the method tress (same method) which results in an endless loop.

Norbert
Loading...