• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Please explain this!? More....
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.


  • Follow-Ups:
    • Re: Please explain this!? More....
      • From: Harald E Brandt <email@hidden>
    • Re: Please explain this!? More....
      • From: Paul Berkowitz <email@hidden>
References: 
 >Re: Please explain this!? More.... (From: Harald E Brandt <email@hidden>)

  • Prev by Date: Re: Number of days since 1/1/0001
  • Next by Date: Re: Number of days since 1/1/0001
  • Previous by thread: Re: Please explain this!? More....
  • Next by thread: Re: Please explain this!? More....
  • Index(es):
    • Date
    • Thread