Re: Please explain this!? More....
Re: Please explain this!? More....
- Subject: Re: Please explain this!? More....
- From: Christopher Nebel <email@hidden>
- Date: Fri, 23 Nov 2001 17:10:13 -0800
On Friday, November 23, 2001, at 10:27 AM, Harald E Brandt wrote:
My background is very much from pure functional programming (Lisp,
Prolog, APL, J, ....) And some aspects in AppleScript would have been
considered a broken compiler/interpreter in any functional language. I
know that AppleScript is object oriented somehow, but I seem to have a
hard time really learning that.....
I think of values, which in "normal" languages mean I could
substitute any valid expression for a variable with the same value.
Hence, breaking an expression into two lines with a variable for the
middle result MUST always give the same result! This obviously does not
hold for AppleScript ... the end result is totally different depending
on whether I do it in one line of two lines!! I find it VERY difficult
to understand the logic behind the interpreter. Normally, that signals
to me a broken interpreter/compiler!
The interpreter isn't broken, it's just very context-sensitive, and it's
context-sensitive in some fairly unusual ways that tend to drive people
used to more (ahem) "normal" languages insane.
AppleScript eliminates the need for an explicit "map" or "apply"
operator by doing it implicitly in "every" constructs. If the innermost
thing in your object specifier is an "every", then the result is a
list. However, if you go on to apply a property or element reference,
then it gets mapped to each element of the list, so the result is
another list. For example:
get every folder of the startup disk --> a list of folders
get the name of every folder of the startup disk --> a list of
strings (names). [1]
This allows you to do some very powerful operations very easily, but it
has the side effect of making simple decomposition impossible.
There are admittedly some hinky bits about this -- AppleScript doesn't
follow this rule consistently for built-in types (i.e., lists, records
and strings), and not all applications do it correctly, either.
(Fortunately, most get it right.) What I've described is the correct
way, however, and we're working on ironing out the wrinkles.
--Chris Nebel
AppleScript Engineering
[1] I'd argue that this is the result an English-speaker would expect
from a sentence like this, while Harald's approach would have produced a
surprising error -- lists don't have names. AppleScript is therefore
being more English-like in this case, not less.