help-smalltalk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-smalltalk] What is wrong with my sort: block?


From: Ladislav Marek
Subject: Re: [Help-smalltalk] What is wrong with my sort: block?
Date: Tue, 11 Dec 2012 09:12:50 +0100

You are using non-local return in block, thats not correct (in this
case). ^false will return from your method and sort: will not be
completed. Last expression is the result in block, so correct code is:

myCollection sort: [ :a :b | a value not ].
myCollection inspect.

On Tue, Dec 11, 2012 at 3:28 AM, Rick Flower <address@hidden> wrote:
> Ok.. First time using sort and I'm stumped..
>
> I've got a collection of associations that look
> kinda like this :
>
>     [1]: './foo'->true
>     [2]: './bar'->false
>     [3]: './baz/->false
>
> I want to sort them so the entry in the collection
> with the 'true' association value is at the end --
> so after sorting it should look like :
>
>     [1]: './bar'->false
>     [2]: './baz/->false
>     [3]: './foo'->true
>
> But when I execute something like that shown
> below it always returns the same thing -- namely
> no change..  I even tried hard-coding ^false when
> it was only 2 entries and it made no difference..
> Any ideas?
>
> myCollection sort: [:a :b |
>    a value ifTrue: [^false ].
>    ^true.
> ].
> myCollection inspect
>
>
>
> _______________________________________________
> help-smalltalk mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/help-smalltalk



reply via email to

[Prev in Thread] Current Thread [Next in Thread]