Re: Please explain this!? More....
Re: Please explain this!? More....
- Subject: Re: Please explain this!? More....
- From: Harald E Brandt <email@hidden>
- Date: Fri, 23 Nov 2001 19:27:29 +0100
Thanks a lot to both Paul and Hugh for the education!
Knowledge increased a couple of millimeters...
I now know what to do, but the reason for asking was not just to get a workaround, it was to understand so I don't stumble so often into various things; It's just too much debugging I am doing rather than writing correct from the beginning.
I have now (this year) actually done quite much AppleScripting, and if I may say it myself it's a quite advanced and proffesional package. But it still often happens I stumple over things I don't seem to understand at all. Paul said: "it's not actually English, and that's what confusing you here."
No, that's wrong! I certainly don't expect it to be english! 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, 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!
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.
Another example:
+--> Hugh wrote:
>
+--> I wrote
>
> Quote from AppleScript Language Guide:
>
> "The value of an Every Element reference is a list of the objects in the
>
> container."
>
+-
>
The value, and not the class.
If the returned VALUE of the contruct is a list of objects, must not the class of that returned value be 'list'?
Finders dictionary says 'item' is an element of 'folder', but if I have a list, then I expect an item of the list to be an item of the list, rather than a list of items of each element of the list?
One possible way to understand it might have been:
The tell block changes 'item' semantics, and since 'list' is not a class in Findes dictinary, it will ALWAYS iterate over lists any time a list is inside a Finder tell block!. However, that means that there may NEVER be any Finder commands that would be allowed to take lists as arguments without going into the list and iterate over the elements! But is this really the case? Or does it "depends on..."?
In addition, throwing in just that single 'get' changes everything!
So in reality, I must now think of some form of class/value termination caused by 'get'. A really difficult way of thinking, considering my background from functional programming...
I hope you understand I am not arguing with you. Rather, if there is a strictly logical execution model, I would like to get that into my head! It would decimate debugging time....
Hugh asked "What do you want to do?". Well, the original problem is quite different from the examples I gave, but the problem stems from the same thing. My examples would be too complex to publish here I think, so I thought the toy example of Control Panels and Extensions folder are much easier to understand since they isolate and highlight the semantics better than my real programs.
With the Best Regards,
______heb________________________________________________________________
Harald E Brandt email@hidden PGP/MIME aware
http://heb.bragit.com