Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!europa.chnt.gtegsc.com!news.mathworks.com!hookup!usc!howland.reston.ans.net!tank.news.pipex.net!pipex!in2.uu.net!tellab5!jialei
From: jialei@news-server.engin.umich.edu (Jialei Jin)
Subject: An array of Associations?
X-Nntp-Posting-Host: sunl65
Message-ID: <1995Aug14.142901.27970@tellab5.tellabs.com>
Sender: news@tellab5.tellabs.com (News)
Organization: Tellabs Operations, Inc., USA
X-Newsreader: TIN [version 1.2 PL2]
Date: Mon, 14 Aug 1995 14:29:01 GMT
Lines: 49

Hi, 

I'm new to SmallTalk and I have a question. I wonder how you can create an
array of Associations. I tried something like:

	# ( (Association key: x value: 1)
	    (Association key: y value: 2))

However, SmallTalk treated it as an array of two arrays, the first one of which
is composed of symbols #Association, #key:, #x, #value: and #1. I was trying 
to send the message key:value: to the class Association to create an instance
of Association, but apprentely it didn't work out. Is it possible to do this 
at all?

Then, I tried some else. I newed an instance of Array first and tried to add
an instance of Association to it:

	| temp |
	temp := Array new.
	temp add: (Association key: x value: 1).

But, I got some error like 'Can't not add to the array'. 

I did try one another thing which was to use the method with:with: to create
the array I wanted:

	| temp |
	temp := Array with: (Association key: x value: 1)
		      with: (Association key: y value: 2).

And this worked as expected. I got an array with two instances of Associations in
it. But the problem with this is the max number of array elements you can create
with the method with:with:... is 4 (the method with:with:with:with:). What if I
want to have more than 4 instances of Associations in the array? What should
I do then?

By the way, I'm using VisualAge v2.0 for OS/2 from IBM.

Thanks in advance for any replies.


--Charlie

-----------------------------
Tellabs Operations, Inc.
Tel. #  (708)512-8048
Email: jialei@tellabs.com  or 
       universe@umich.edu
-----------------------------
