Re: Second-Time conversion
Re: Second-Time conversion
- Subject: Re: Second-Time conversion
- From: Graff <email@hidden>
- Date: Thu, 24 Jun 2004 23:18:28 -0400
On Jun 24, 2004, at 9:11 PM, Nigel Garvey wrote:
Graff wrote on Thu, 24 Jun 2004 12:46:47 -0400:
On Jun 24, 2004, at 11:47 AM, Martin Orpen wrote:
on leadZero(x)
if x is less than 10 then
return "0" & x
else
return x
end if
end leadZero
One thing you might want to change is the second return in the
leadZero
handler. The way it is now you either return a string or a number,
depending on whether or not the number is less than 10. If you change
the second return to this then it will always return a string:
return "" & x
What you have right now works simply because you later coerce the
returned value to a string, so it doesn't matter if it is a string or
a
number. If you put the coercion into the handler in the first place
you cut down the chances of a bug down the road.
Just to point out that the "coercion" here is actually a concatenation
-
which involves the automatic coercion of x to string first, then the
concatenation of the result to "". It's a popular scripting style, but
a
straight "coercion" would properly be:
return x as string
Right. I, of course, was referring to the implicit coercion that
happens when you concatenate. AppleScript always attempts to coerce
the second item of a concatenation into the same class as the first
item. Using a concatenation in order to get a coercion is just a less
cluttered way to go about coercing things.
You say potato I say esculent farinaceous tuber...
:-)
- Ken
_______________________________________________
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.