[comp.sys.mac] HyperCard arrays

sysop@stech.UUCP (Jan Harrington) (10/25/87)

I'm working on a HyperCard stack which will compute statistics for data sets
of up to 30 variables.  While working on the computations for descriptive
statistics, I seem to have run into a snag - in order to compute frequency
distributions (and cummulative frequencies, medians and modes), I need
to use a couple of arrays.  

HyperTalk doesn't directly support arrays.  Is there some way to get the
same effect (by using variables names like VName & k, where k contains
a number that changes?)?  Has anyone come across this yet and found a
good solution?

Any help would be gratefully accepted.


Jan Harrington, sysop
Scholastech Telecommunications
ihnp4!husc6!amcad!stech!sysop or allegra!stech!sysop

********************************************************************************
	Quote for the day:

		"No matter where you go, there you are."
				Buckaroo Banzai
********************************************************************************

chuq%plaid@Sun.COM (Chuq Von Rospach) (10/26/87)

>HyperTalk doesn't directly support arrays.  Is there some way to get the
>same effect (by using variables names like VName & k, where k contains
>a number that changes?)?  Has anyone come across this yet and found a
>good solution?

If each array entry can be stored as a word, it's pretty simple. Define a
field, VName, and store things as words in the field. VName[k] then
becomes "word k of field Vname". To store, you "put foo into word k of field
Vname" and to read you "put word k of field Vname into foo"

By using "before" and "after" you could even create a sorted array without
having to do any physical rearrangment. 

If the values don't fit well into words, you could do the same (with some
slightly greater complexity) using fields or lines in a single field as
well.

chuq

Chuq Von Rospach					chuq@sun.COM
Editor, OtherRealms					Delphi: CHUQ

faulkner@scdpyr.UUCP (Bill Faulkner) (10/26/87)

In article <173@stech.UUCP>, sysop@stech.UUCP (Jan Harrington) writes:

> HyperTalk doesn't directly support arrays.  Is there some way to get the
> same effect (by using variables names like VName & k, where k contains
> a number that changes?)?  Has anyone come across this yet and found a
> good solution?

One thing that would work, but isn't really elegant is to create an
invisable field and use the various lines as elements of the array.
The refernce to this would be similar to:

	add 23 to line k of field "Array"

You could even extend this to two dimensions by using the word of a line,
such as

	put 5 into word i of line j of field "2-D Array"

Does anybody know of a better solution?
-- 
Bill Faulkner * NCAR (Nat'l Center for Atmospheric Research)
PO Box 3000 * Boulder, CO  80307-3000 * 303-497-1259
UUCP:  faulkner@scdpyr.UUCP or  ..!hao!scdpyr!faulkner
INTERNET: faulkner@scdpyr.ucar.edu  ARPA: faulkner%ncar@csnet-relay.arpa

hpoppe@scdpyr.UUCP (Herb Poppe) (10/26/87)

In article <191@scdpyr.UUCP>, faulkner@scdpyr.UUCP (Bill Faulkner) writes:
> In article <173@stech.UUCP>, sysop@stech.UUCP (Jan Harrington) writes:
> 
> > HyperTalk doesn't directly support arrays.  Is there some way to get the
> > same effect (by using variables names like VName & k, where k contains
> > a number that changes?)?  Has anyone come across this yet and found a
> > good solution?
> 
> One thing that would work, but isn't really elegant is to create an
> invisable field and use the various lines as elements of the array.
> The refernce to this would be similar to:
> 
> 	add 23 to line k of field "Array"
> 
> You could even extend this to two dimensions by using the word of a line,
> such as
> 
> 	put 5 into word i of line j of field "2-D Array"
> 
> Does anybody know of a better solution?

Yes, you can use variables in a manner similar to fields to simulate
arrays.  For example, you can say "line 1 of data", where "data" is the
name of a local or global variable. For example:

put 1 into line 1 of data
put 2 into line 2 of data
put 4 into line 3 of data
put (line 1 of data) + (line 2 of data) + (line 3 of data) into message

Of course, you can use variables instead of literals:

put 3 into n
put line n of data into message

Instead of 'lines' you can use 'items':

put "ABC" into item 2 of data

For multiply-dimensioned arrays you can do:

put "ABC" into item 2 of line 3 of data

-- 
Herb Poppe      NCAR                         INTERNET: hpoppe@scdpyr.UCAR.EDU
(303) 497-1296  P.O. Box 3000                   CSNET: hpoppe@ncar.CSNET
		Boulder, CO  80307               UUCP: hpoppe@scdpyr.UUCP

freedman@calgary.UUCP (Dan Freedman) (10/30/87)

In article <173@stech.UUCP>, sysop@stech.UUCP (Jan Harrington) writes:
> HyperTalk doesn't directly support arrays.  Is there some way to get the
> same effect (by using variables names like VName & k, where k contains
> a number that changes?)?

The easiest way is to use HyperTalk's "item" syntax.  You can say, for
instance:

	put 3 into item 9 of theArrayVariable

and, nicely enough, if theArrayVariable has less than n items in it when
you tell it to put something into item n, hypercard will pad out the
variable with the appropriate number of empty items, meaning that you don't
even have to worry about initializing the variable.  Items in hypercard
are things separated in a variable or field by commas, so a variable with
3 as the first item, 8 as the fifth item, and 21 as the ninth item would
look like this:
	3,,,,8,,,,21

To access an item of a field or variable, just say:
	get item 4 of theArrayVariable

Needless to say, the item specifier can be a variable, which makes the
implementation of arrays really easy!

	Dan Freedman
	University of Calgary Computer Science Department