On 01/09/2013 12:39 PM, Frank Church wrote:
On 9 January 2013 19:30, Paul DeBruicker <pdebruic@gmail.com <mailto:pdebruic@gmail.com>> wrote:
On 01/09/2013 11:18 AM, Frank Church wrote: > > When I print it returns an empty array #(), but I expect to get subset > of TextMorphForEditView allInstances. > > What is the likely purpose of the notNil? > > -- > Frank Church
The #firstOwnerSuchThat: method either returns the morph that meets the criteria specified in the block sent to it (in this instance that the owner is a SystemWindow and its model is a Workspace) or nil. The #select: block needs the code inside it to return a boolean, so the #notNil converts the response from the #firstOwnerSuchThat: method into a boolean rather than leaving it as either nil or the morph.
If you right click on a method and choose Implementors you can see how each class that implements the method defines it. You can also right click the method and choose Senders to see examples of how the method is used.
Is there some reason why the expression is returning an empty collection?
Isn't the select: meant to return the whole list?
No the #select: returns only those elements for which the select block returns true. The reason why you're getting an empty collection is because the select block for every element returns false. The criteria in the #firstOwnerSuchThat: block needs to be adjusted to be more permissive. Or the starting collection is wrong. In this instance its an issue of the criteria in the #firstOwnerSuchThat: block being wrong. This one you want is this: TextMorphForEditView allInstances select: [ :morph | (morph firstOwnerSuchThat: [ :owner | (owner isKindOf: SystemWindow) and: [ owner model isKindOf: Workspace ] ]) notNil ] (I changed 'owner class isKindOf: SystemWindow' to 'owner isKindOf: SystemWindow') I'm on linux and you can shift-click (it may be option-click or commanc-click on other platforms I have no idea) the title bar of a Workspace and click 'explore' to see that workspace's instance variables. In the bottom pane of the explorer window you can test your select block's criteria to ensure it works for your desired objects. Another way to find a workspace is first close all windows then open a workspace and run Smalltalk garbageCollect then highlight the following, right click it, and choose 'explore' TextMorphForEditView allInstances The only thing in the array in the explorer window is the morph for the workspace. You can then start looking through the owners by clicking the triangle next to the #owner instance variable until you find one who's model is 'a Workspace'. That's the workspace object.