• 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: Passed lists, references, and occasional errors
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Passed lists, references, and occasional errors


  • Subject: Re: Passed lists, references, and occasional errors
  • From: has <email@hidden>
  • Date: Mon, 21 Apr 2008 21:56:40 +0100


On 19 Apr 2008, at 13:40, Nigel Garvey wrote:
This script is contrived to illustrate something I ran into this morning:

 on aHandler(aList)
   script o
     property l : aList
   end script

   item 1 of o's l

 end aHandler

 try
   repeat with i from 1 to 100
     aHandler(characters of "abcdefghijklm")
   end repeat
 on error msg
   display dialog msg & return & "on iteration " & i & "."
 end try

Most times, on both my Jaguar and Tiger machines, it displays a message
to the effect 'Can't get item 1 of characters of "abcdefghijklm". on
iteration 34.'

Reason #397 why implicit gets are made of FAIL.

When the AppleScript evaluates a literal reference, I believe the initial result is a sort of interim reference object which the interpreter may or may not immediately dereference depending on the literal's context. For example, if it appears as an operand to any operator except 'a reference to', the interpreter will apply an implicit get to obtain the referenced value. If it appears as a parameter to a command, it is left as-is and it's up to the command's target to decide what to do. This is so that when the target is another process, the reference value can be passed to the target application to resolve. Without this temporary deferment, the reference would be resolved prematurely by AppleScript.

All very clever, and - as with any sleight of hand - all to ready to blow apart the moment that things don't go precisely the way it expects them to. In this case, it looks like the AS interpreter knows how to evaluate 'get item 1 of <reference to object>' and 'get item 1 of <reference to reference>' without problem, but 'item 1 of <reference to semi-reference>' is going just a little too far for comfort.

It's crap like this that makes me glad of Python/Ruby/ObjC/etc. They might not be as pretty to look at, but they don't go out of their way to mess with your head by trying to be clever.

has
--
Control AppleScriptable applications from Python, Ruby and ObjC:
http://appscript.sourceforge.net

_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden
References: 
 >Passed lists, references, and occasional errors (From: "Nigel Garvey" <email@hidden>)

  • Prev by Date: Re: Setting the compiled script name?
  • Next by Date: Re: Syntax Question
  • Previous by thread: Re: Passed lists, references, and occasional errors
  • Next by thread: Applescript with Mail eat the Apple!…
  • Index(es):
    • Date
    • Thread