Re: POSIX and lists question
Re: POSIX and lists question
- Subject: Re: POSIX and lists question
- From: "Mark J. Reed" <email@hidden>
- Date: Fri, 12 Aug 2005 17:10:11 -0400
On 8/12/05, John R. <
email@hidden> wrote:
> One point I am confused about: Are Mark's "map" and "apply" examples
> the right way to do this in AS, or (as HTH seems to imply with his AS
> complaint) are Mark's routines going to yield unexpected results
> sometimes?
Of course they're the right way! I am always right! Trust in what I do!!!
:)
Seriously,
though, I haven't read through has's detailed examples of the problem
yet, but it sounds like passing around handlers is potentially
dangerous, even though it has yet to bite me. You can avoid
that problem and still do things like this:
apply(theFiles, POSIXize)
But POSIXize should be a script object rather than a handler, which is a little more work to create:
script POSIXize
on do(theFile)
return POSIX path of theFile
end
end
and the code for the apply/map/etc. handlers looks different:
on apply(theList, doer)
repeat with i from 1 to count(theList)
set theList's item i to doer's do(theList's item i)
end
end
Aside from a couple extra lines of code, the main difference here
is that the calling code and the apply/map/whatever code have to agree
on the name of the handler within the script object ("do" in this
case). So this version is more like Java's interface-based
callback mechanism than higher-order functional programming. It'd
be nice if there were a logical standard handler name to use here...
you could use run() and then just "run doer" or whatever, but as far as
I can tell there's no way to pass parameters to the run() method when
you run a script object...
--
Mark J. Reed <
email@hidden>
_______________________________________________
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