Re: Scripting Style (was: Re: Hiding Slaves)
Re: Scripting Style (was: Re: Hiding Slaves)
- Subject: Re: Scripting Style (was: Re: Hiding Slaves)
- From: Nigel Garvey <email@hidden>
- Date: Sat, 14 Sep 2002 12:19:07 +0100
Ken Scott wrote on Fri, 13 Sep 2002 21:13:52 -0600:
>
on 9/11/02 9:17 AM, John Delacour at email@hidden wrote:
>
>
> set the hidFolder to alias ("" & (path to scripts folder) & ".hid")
>
> -- alias "dx2:Users:jd:Library:Scripts:.hid:"
>
>
>
>
Hi John,
>
>
I have a question about the script snippet that you posted above. Why do you
>
prepend the empty string to the (path to scripts folder)? Does this force an
>
alias to become a string, or something like that? Is this more efficient
>
than saying (path to scripts folder) as string?
Yes and no respectively. Yes: it does force the alias to become a string.
When two items are concatenated together, if the item to the left of the
ampersand is a string and the item on the right can be coerced to one,
then the item on the right is automatically so coerced. Some people - for
reasons of their own - prefer to force an implicit coercion by prepending
an empty string than to use an explicit coercion.
No: it's not more efficient. Although implicit coercions are generally
faster than explicit ones, concatenations plus implicit coercions take
longer than explicit coercions alone. However, given the uncertainty
about how long 'path to' itself is going to take, it doesn't really make
any difference here.
The most efficent method in the current case is to use 'path to's own 'as
string' option - which is not a coercion but a parameter. This causes
'path to' to return the string directly. Notice the slightly different
way it's written:
-- 'as string' as coercion ('path to' returns an alias,
-- which AppleScript then coerces to string)
(path to scripts folder) as string
-- 'as string' as 'path to' parameter ('path to' itself returns the
string)
path to scripts folder as string
So:
set the hidFolder to alias ((path to scripts folder as string) & ".hid")
NG
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.