Re: POSIX and lists question
Re: POSIX and lists question
- Subject: Re: POSIX and lists question
- From: "Mark J. Reed" <email@hidden>
- Date: Wed, 10 Aug 2005 23:17:47 -0400
> ------------------
>
> set theFiles to {}
> repeat with currPath in thePaths
> set end of theFiles to POSIX file currPath
> end repeat
>
> ------------------
>
> If you have no further use for the original paths after conversion,
> you might even consider converting each item of the list in place,
> thus avoiding the need to build a new list altogether. (Here, let's
> assume that the incoming list is already called 'theFiles', rather
> than 'thePaths'):
>
> ------------------
>
> repeat with n from 1 to count theFiles
> set item n of theFiles to POSIX file (item n of theFiles)
> end repeat
>
> ------------------
>
> ---
> kai
>
There are any number of add-ons that provide sophisticated
list-handling, er, handlers for AppleScript. I use a home-grown
one (the better to learn the language), which lets me do this:
on POSIXize(pathString)
return POSIX file pathString
end POSIXize
set thePaths to map(theFiles, POSIXize)
Or I could use the apply() function to modify the list in place:
apply(theFiles, POSIXize)
Yeah, I know, mixing metaphors with Perl and Lisp, but I don't know how
to write a single handler that will honor changes made within the
passed-in closure. There might be a way with references, but it's
beyond my as-yet meager AppleScript skillz. It'd also be nice if
there were a syntax to create an anonymous closure on the fly so I
wouldn't have to define a named handler like POSIXize . . .
This is the source code to the functions in question . . . . improvements welcome:
on map(L, func)
script mapper
property block: func
on map(L)
set newList to {}
repeat with eachItem in L
set end of newList to block(eachItem)
end repeat
return newList
end map
end script
return mapper's map(L)
end map
on apply(L, func)
script applicator
property block: func
on apply(L)
repeat with i from 1 to count L
set item i of L to block(item i of L)
end repeat
return L
end apply
end script
return applicator's apply(L)
end apply
--
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