Re: handler failure [oops! correction]
Re: handler failure [oops! correction]
- Subject: Re: handler failure [oops! correction]
- From: has <email@hidden>
- Date: Thu, 14 Nov 2002 16:28:19 +0000
Hi,
>
Here is an exploit of this "feature" which demonstrates that it might
>
actually be useful:
[snip code]
My problem's not with the ability to assign handlers to different slots,
but that the behaviour is buggy. It's important to be clear on the
distinction, lest the thread go all wonky and off-track.
Re. your example, you can easily get the functionality you want with more
conventional techniques - eg:
======================================================================
script langBase
on GetMonthName(inMonth)
if inMonth = 1 then
return my _Jan
else if inMonth = 2 then
return my _Feb
else if inMonth = 3 then
return my _Mar
else if inMonth = 4 then
return my _Apr
else if inMonth = 5 then
return my _May
else if inMonth = 6 then
return my _Jun
else if inMonth = 7 then
return my _Jul
else if inMonth = 8 then
return my _Aug
else if inMonth = 9 then
return my _Sep
else if inMonth = 10 then
return my _Oct
else if inMonth = 11 then
return my _Nov
else
return my _Dec
end if
end GetMonthName
end script
--
script langEnglish
property parent : langBase
--
property _Jan : "January"
property _Feb : "Febuary"
property _Mar : "March"
property _Apr : "April"
property _May : "May"
property _Jun : "June"
property _Jul : "July"
property _Aug : "August"
property _Sep : "September"
property _Oct : "October"
property _Nov : "November"
property _Dec : "December"
end script
script langGerman
property parent : langBase
--
property _Jan : "Januar"
property _Feb : "Februar"
property _Mar : "Marz"
property _Apr : "April"
property _May : "Mai"
property _Jun : "Juni"
property _Jul : "Juli"
property _Aug : "August"
property _Sep : "September"
property _Oct : "Oktober"
property _Nov : "November"
property _Dec : "Dezember"
end script
on run
set s to "#" & tab & "English" & tab & "German" & return
[NO-BREAK][CONTINUE]
& "--" & tab & "---------" & tab & "---------"
repeat with i from 1 to 12
set s to s & return [CONTINUE]
& (i as string) & tab [CONTINUE]
& (langEnglish's GetMonthName(i)) & tab [CONTINUE]
& (langGerman's GetMonthName(i))
end repeat
end run
======================================================================
>
Now if somone can tell me the trick of addressing properties by index
>
the GetMonthName handler could be even more elegant...
<cough>Incredibly Hackish</cough> If you want an ordered structure, use
one. The whole point of an unordered structure is that position is
irrelevant. [1]
>
(And please don't tell me I could use an array. That'd be beside the
>
point.)
Not at all. Use the right structure for the right job.
>
It does kind of remind me of obscure pointer arithmetic in C though ;-)
Urk. Reason enough to shoot the idea in the back of the head and bury it in
an unmarked grave, post-haste.
>
Now I wonder if this is actually a feature of AS that we can rely on or
>
something of an implementation dependent side effect?
Not sure which behaviour you're referring to...
- That a handler object can change context, and adopt the new context as
its own? That's a characteristic of the language, but one that's
undocumented and buggy. Until/unless those issues are remedied, use a
documented and reliable alternative instead.
- Or accessing a script object's slots by index? <clik-klatch><BAMMM!!!>
Now, where's the damn shovel...
has
[1] Note: what an object does in _private_ is its own business. If it uses
slot positions internally to boost performance, that's up to it. What's
important is that nobody else should know - or need to know - anything
about this.
--
http://www.barple.pwp.blueyonder.co.uk -- The Little Page of AppleScripts
_______________________________________________
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.