[Newbies] How to doubble sort a collection - DynamicSortBlock.st (0/1)

Louis LaBrunda Lou at Keystone-Software.com
Wed Feb 4 17:27:14 UTC 2015


On Wed, 4 Feb 2015 09:00:13 -0800 (PST), Paul DeBruicker
<pdebruic at gmail.com> wrote:

>Does using the | or & notation have any advantages over and: or or:  or
>ifTrue:ifFalse ?

and: and or: are needed when you don't want to execute the code inside the
block unless it is needed.  They are also used to protect from executing
code that shouldn't be run for example:

x notNil and: [x foo > y foo]

>I always write expressions like the one you've written like:

>a date = b date 
>   ifTrue:[a temps > b temps] 
>   ifFalse:[a date > b date]

I like this but it may be a little tricky for a beginner.  But both or
replay help one to learn.

I have also attached a file out (from VA Smalltalk) of a class that acts
like a sort block but is much easier to use for complex sorts.

Lou

>Louis LaBrunda wrote
>> Hi Raymond,
>> 
>> Try:
>> 
>> ^notes sorted:[:a :b | (a date  > b date) | ((a date = b date) & (a date
>> temps > b date temps))].
>> 
>> Lou
>> 
>> On Wed, 04 Feb 2015 10:34:48 -0500, Raymond Asselin &lt;
>
>> jgr.asselin@
>
>> &gt;
>> wrote:
>> 
>>>I have this kind of sorting on anOrderedCollection
>>>
>>>BlocNotes >>sortedNotes
>>>	^notes sorted:[:a :b | a date  > b date]
>>>
>>>This sort my notes on date but I want them sort by date AND inside a date
>by hours and I don't khow how to do this.
>>>
>>>Some insights?
>>>
>>>aNote = 'med com date temps' instancesVariables what I call hours = temps
>witch is a number like 2123 for 21h23
>>>
>>>Some insights?
>> -----------------------------------------------------------
>> Louis LaBrunda
>> Keystone Software Corp.
>> SkypeMe callto://PhotonDemon
>> mailto:
>
>> Lou@
>
>>  http://www.Keystone-Software.com
>> 
>> _______________________________________________
>> Beginners mailing list
>
>> Beginners at .squeakfoundation
>
>> http://lists.squeakfoundation.org/mailman/listinfo/beginners
-----------------------------------------------------------
Louis LaBrunda
Keystone Software Corp.
SkypeMe callto://PhotonDemon
mailto:Lou at Keystone-Software.com http://www.Keystone-Software.com



More information about the Beginners mailing list