Re: Please explain this!? More....
Re: Please explain this!? More....
- Subject: Re: Please explain this!? More....
- From: Paul Berkowitz <email@hidden>
- Date: Fri, 23 Nov 2001 11:07:16 -0800
On 11/23/01 10:27 AM, "Harald E Brandt" <email@hidden> wrote:
>
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, which
>
always makes me feel uneasy and uncertain about the correctness of my code.
>
>
As an example:
>
'every file in control panels folder'
>
Now, what class is it? Is it a list or is it not a list?
>
If it is a list, then it can be indexed, also inside tell Finder blocks.
>
>
Now, setting 'class of' in front of it should get me that class (I earlier
>
thought). But AppleScript tries to automagically anticipate what it thinks I
>
want by interpreting the complete expression as if I had inserted (an
>
invisible) higher order function that ordered it to evaluate the class FOR
>
EACH ELEMENT of the list!
>
If, instead, I first set it to a variable and on the next line take the class
>
of it, then it does not try to do that!? Despite staying inside the Finder
>
Tell block!
>
So 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!
As I pointed out, if you use the explicit 'get' for the internal command in
parentheses, then it's going to work the way you expect. But using it
without 'get' allows you to evaluate the class (or any property at all) for
each element, _without using a tedious repeat loop_. Don't you agree that
that's wonderful, once you know about it? Repeat loops can be painfully
slow: here AppleScript allows the application to do all the work much faster
than iterating a repeat loop in AppleScript ever could. Ad this is true 100%
of the time - it's completely reliable.
It's a similar case with 'whose' clauses, when they've been implemented by
an application's developers. (If they have, then the dictionary entry for
that element of the class you're searching should include 'satisfying a
test'). By aware that 'whose' clauses are unfortunately _not_ yet
implemented for AppleScripts lists or records (a long-standing feature
request). Again, you can search just for a particular property. and the
application does the work. This can be incredibly faster than a repeat loop.
So whenever possible, use whose clauses rather than making a list of all
elements which then have to be tediously looped for values of some property.
>
>
I want to be able to point at any piece of an expression and say what its
>
class and value are and then KNOW for 100% sure what the operations on that
>
expression results in! I want to mentally execute the line, token by token.
>
Sometimes it works, sometimes not. That's why I seek help from this list.
Yes, well you can for that case you presented (every file in control panels
folder) once you understand AppleScript's syntax. It is in fact 100%
reliable. For 'whose' clauses, you'll have to check the dictionary and
test, or just forget about them if you don't want to do that. (Repeat loops
are 100% reliable.) But that would be a shame.
--
Paul Berkowitz