• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: POSIX and lists question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: POSIX and lists question


  • Subject: Re: POSIX and lists question
  • From: has <email@hidden>
  • Date: Fri, 12 Aug 2005 22:26:40 +0100

John R. 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 [sic] seems to imply with his AS complaint) are Mark's routines going to yield unexpected results sometimes?

The concept is fine, being lifted directly from functional programming, but the original implementation was flawed for the reasons given. Here's a corrected version:

on map(L, evalObj)
    (* Returns a new list containing the results of applying a function, evalObj's eval, to the items of a given list, L.
        L : list -- a list of values to map to a new list
        evalObj : script -- a script object containing a handler named 'eval' that takes a single parameter and returns a result
        Result : list -- a new list of mapped values
    *)
    set newList to {}
    repeat with itemRef in L
        set end of newList to evalObj's eval(itemRef's contents)
    end repeat
    return newList
end map

script POSIXize
    on eval(pathString)
        return POSIX file pathString
    end eval
end script

set thePaths to map(theFiles, POSIXize)


>It seems that Mark's handlers would be very useful models for similar AS handlers: for sorting a list, or for selecting item(s) from a list using custom criteria. Another benefit is to clean up my code by pushing annoying repeat blocks into (a few simple-to-maintain) handlers.

AppleMods' List library <http://applemods.sourceforge.net/mods/Data/List.php> already provides well-optimised mapList, filterList and reduceList commands for functional-style programming, along with a powerSort command for custom sorting lists.

HTH

has
--
http://freespace.virgin.net/hamish.sanderson/
 _______________________________________________
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

  • Prev by Date: Re: Getting source text of a compiled script
  • Next by Date: Re: set offsetGrif to offset of keyword in webText
  • Previous by thread: Re: POSIX and lists question
  • Next by thread: Re: POSIX and lists question
  • Index(es):
    • Date
    • Thread