Re: dynamic variables
Re: dynamic variables
- Subject: Re: dynamic variables
- From: email@hidden
- Date: Thu, 24 Jul 2003 21:37:06 -0400
On Date: Thu, 24 Jul 2003 13:07:54 -0400,
"Steven D. Majewski" <email@hidden> suggested,
>
On Thursday, July 24, 2003, at 10:55 AM, jay wrote:
>
>
> I'm not sure if that is what I am looking for. It could be better
>
> described with an example: My program is going to get 100 numbers
>
> while it is running (say from the user). I need to save all 100
>
> numbers. Instead of defining 100 variables outright I want my script
>
> to create a new variable every time it receives a new number. Thus my
>
> program would start with 0 number variables and end with 100 variable
>
> numbers.
>
>
Start with an empty list, and append numbers to it as needed.
>
>
set a to {}
>
repeat with i from 1 to 20
>
set a to a & i
>
end repeat
Its probably at bit more idiomatic (if you are a native speaker of AppleScript)
to write it as,
set the end of a to i
This is also more efficient than 'set a to a & i', which coerces i to a list,
creates a new list by concatenating a and {i}, and then throws the original a
away are replaces it with the new list.
For those readers impaired [ ;-) ] by their Java[Script]/C[++] or Perl
backgrounds, here are the equivalent statements:
AppleScript Java[Script]/C[++] Perl
----------- ------------------ ----
set end of a to i a[a.length] = i; $a[@a] = $i;
set a to a & i a = concat( a, [i]); @a = (@a, i);
--
Scott Norton Phone: +1-703-299-1656
DTI Associates, Inc. Fax: +1-703-706-0476
2920 South Glebe Road Internet: email@hidden
Arlington, VA 22206-2768 or email@hidden
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.