two changes I would like to see in AS for X
two changes I would like to see in AS for X
- Subject: two changes I would like to see in AS for X
- From: Timothy Bates <email@hidden>
- Date: Sat, 20 Jan 2001 01:43:26 +1100
I was just thinking "what would my two biggest wishes be for AS under X?
I think my number 1 dream would be if AppleScript arrays could be
associative (in fact if all lists were automatically associative).
All existing behaviour would work and nothing would break. By default
creating an array {"dog","cat"} would fill the names with sequential numeric
indices 1,2,3...
This would have the following benefits
1. unify the list and record concepts: you can simply say
set animal1 to {"type":"dog", "enemy":"cat"}
get "enemy" of animal1
--> "cat"
2. Internet cgi's are completely dependent on associative arrays: that is
why php and perl are so powerful. With one stroke AS leaps up in the 'net
stakes, simplifies several tasks, and remains as easy to use as ever.
3. massive benefit: unlike records, assoc arrays can be built on the fly.
All of a sudden you can create "records" at run time: for instance from
MySQL results and cgi input.
4. it is a nice comp-sci concept, making AS more useful in Comp sci classes
for talking about this kind of thing (which it is already v.nice for IMHO)
5. Hash things become trivial. For instance building a concordance reduces
to just:
set myWords to {}
repeat while not eof
nextWord = read f;
set nextWord of words to (nextWord of words + 1)
--it would be nice here to have the += construct
end repeat
Try doing that in AS now!
6. I am sure you have thought of at least three more than I have ...
**************
Number 2 request: Using variable contents as variable names.
**************
This knocked me out when I discovered it in php.
This concept means that you can use the contents of one variable to specify
another variable. Thus:
set dog to "beau"
set myNamer to "dog"
get myNamer as var
--> "beau"
Why does one need this admittedly hard-to-grasp construct? heaps of reasons
every day, especially if you are programming the web
For instance: Let's say you know you are going to need one variable from
amongst a set of variables at a given point in your program, but you are
not sure ahead of time which one!
A common example is a repeat loop where each time through, you want a
different parameter in the same place, depending on the value of your input.
A worked practical example of how this really pays off big time
-- a list of people's names called <nameList> is passed to you. You have no
way to know the content or even the length of this list ahead of time
--you have available a group of variables where var name = person's name
and content = their age
repeat with aName in nameList
set subjectAge to aName as var"
... do stuff with subject age.
end
thanks for reading this chris n ;-)
tim