• 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: robust handling of return values
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: robust handling of return values


  • Subject: Re: robust handling of return values
  • From: Richard Morton <email@hidden>
  • Date: Sat, 12 Nov 2005 14:18:51 +1100

On 12 Nov 2005, at 1:21 AM, patrick machielse wrote:
...to add files to an iTunes playlist you use the 'add' command:

add list of alias : the file(s) to add
    [to location reference] : the location of the added file(s)
        → track : reference to added track(s)

Just like the dictionary _doesn't_ say, depending on how many files were added, the command returns either:

- 'nothing'
- a file track
- a list of file tracks

[...]

should I use:
    set addedTracks to add {list of tracks}
    try
        get addedTracks
        if ( "class of addedTracks is list" )
            -- it is a list
        else
            -- it is a file track
        end if
    onerror
        -- nothing returned
    end try

This seems a bit unelegant, using exceptions for flow control. There must be a better way around this.

A related question: why wouldn't the 'add' command just return an empty list if no tracks were added? Why make it difficult?

Indeed. I think it should always return a list. One could still ask why you are passing empty lists to the 'add' command though. AppleEvents are costly - avoid them if you can reasonably do so.


	if trackList is not {} then
		set addedTracks to (add trackList) as list
	else
		set addedTracks to {}
	end if

This means that 'addedTracks' will always be a list and it will be faster than calling 'add' for no reason if 'trackList' is empty. You may also want to look at why your code is getting to here if there is nothing to add. Is the flow control prior to this point doing its job correctly?

Cheers,

A Dios-Omega
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >robust handling of return values (From: patrick machielse <email@hidden>)

  • Prev by Date: 10.4.3 changed what?
  • Next by Date: Quit Classic
  • Previous by thread: robust handling of return values
  • Next by thread: Re: robust handling of return values
  • Index(es):
    • Date
    • Thread