Problems with OrderedCollections

VA Smalltalk is a "100% VisualAge compatible" IDE that includes the original VisualAge technology and the popular VA Assist and WidgetKit add-ons.

Moderators: Eric Clayberg, wembley, tc, Diane Engles, solveig

Problems with OrderedCollections

Postby danilomarcondes » Wed Oct 22, 2008 3:03 am

Hi.
I'm using an OrderedCollection that has 1720 items, which are classes with 4 attributes.

On my method, I add all the items and then I search for some items with the 'findFirst:' method.

On VA60, it works, but on VA75, when I go on 'display' or 'inspect', it returns me errors like 'UndefinedObject does not understand "-"'. There isn't any '-' on my method.

Here is a sample:

| word |

word := OrderedCollection new.

word
add: (((((Class new) code: '00988') val1: '005') val2: '854') val3: '002);
add: (((((Class new) code: '00988') val1: '006') val2: '547') val3: '887');
add: (((((Class new) code: '09783') val1: '007') val2: '554') val3: '547');
yourself.

^(word at: (word findFirst: [ :wvar | (wvar val1 = '005')] )) val2.
Danilo Marcondes
danilomarcondes
 
Posts: 8
Joined: Wed Sep 24, 2008 10:33 am

Re: Problems with OrderedCollections

Postby tc » Wed Oct 22, 2008 9:44 am

Hello,

I created a class with the following definition:
Code: Select all
Object subclass: #TestClass1
    instanceVariableNames: 'code val1 val2 val3 '
    classVariableNames: ''
    poolDictionaries: ''

. . . and ran your workspace code:
Code: Select all
| word index |

word := OrderedCollection new.

word
   add: (TestClass1 new
      code: '00988';
      val1: '005';
      val2: '854';
      val3: '002';
      yourself);
   add: (TestClass1 new
      code: '00988';
      val1: '006';
      val2: '547';
      val3: '887';
      yourself);
   add: (TestClass1 new
      code: '09783';
      val1: '007';
      val2: '554';
      val3: '547';
      yourself).

index := word findFirst: [ :wvar | (wvar val1 = '007') ].

^index > 0
   ifTrue: [ (word at: index) val2 ]
   ifFalse: [ nil ]


. . . and it seems to work fine. Can you create a test case which shows the error?

Thanks.

--tc
tc
Moderator
 
Posts: 304
Joined: Tue Oct 17, 2006 7:40 am
Location: Raleigh, NC

Re: Problems with OrderedCollections

Postby marten » Wed Oct 22, 2008 10:46 am

Well, you should not ask yourself, where the "-" is located in your code. Ask yourself where the "UndefinedObject" comes from !!!

Perhaps you should rewrite the last line of your code to (mainly because the methods you mentioned may break):

foundOrNil := word detect: [ :wvar | (wvar val1 = '005')] ifNone: [ nil ].
^foundOrNil isNil ifTrue:[ nil ] ifFalse:[ foundOrNil val2 ]

Don't you get a stack trace when getting the error you mentioned ?????


Marten

danilomarcondes wrote:Hi.
I'm using an OrderedCollection that has 1720 items, which are classes with 4 attributes.

On my method, I add all the items and then I search for some items with the 'findFirst:' method.

On VA60, it works, but on VA75, when I go on 'display' or 'inspect', it returns me errors like 'UndefinedObject does not understand "-"'. There isn't any '-' on my method.

Here is a sample:

| word |

word := OrderedCollection new.

word
add: (((((Class new) code: '00988') val1: '005') val2: '854') val3: '002);
add: (((((Class new) code: '00988') val1: '006') val2: '547') val3: '887');
add: (((((Class new) code: '09783') val1: '007') val2: '554') val3: '547');
yourself.

^(word at: (word findFirst: [ :wvar | (wvar val1 = '005')] )) val2.
Marten Feldtmann, Principal Smalltalk User, Private
SkypeMe callto://marten.feldtmann
marten
[|]
 
Posts: 641
Joined: Sat Oct 14, 2006 7:10 am
Location: Hamburg - Germany

Re: Problems with OrderedCollections

Postby Michael Keppler » Wed Dec 10, 2008 5:27 am

findFirst: expects a two argument block, but your block takes only one argument. Therefore the (expected) index is undefined.

But I'm still curious why you are using findFirst: at all. I would just use detect: instead as it makes no sense to find the element, return its index and to grab the element at the index (which is exactly the one which was already found).
Michael Keppler
 
Posts: 28
Joined: Wed Feb 27, 2008 4:33 am


Return to VA Smalltalk 7.0, 7.5 & 8.0

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest