Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

RFC: Porting map() and grep() to AppleScript

by mjg (Scribe)
on Nov 22, 2009 at 23:51 UTC ( [id://808691]=perlmeditation: print w/replies, xml ) Need Help??

No real Perl code here, but I thought it would be neat to try to port the map() and grep() functions to AppleScript and see if that much-maligned language could use a little higher-order programming love.

I've also posted a thread on MacScripter, but here's the code in question. Thoughts?

on map over theList given script:theScript set resultList to {} repeat with theItem in theList set resultList to resultList & theScript's lambda(theItem) end repeat return resultList end map on grep over theList given script:theScript set resultList to {} repeat with theItem in theList tell theScript if lambda(theItem) is true then set resultList to resultList & theItem end if end tell end repeat return resultList end grep -- end library script mapScript property HowMany : 0 on lambda(someone) set HowMany to HowMany + 1 return someone & " Gardner " & HowMany end lambda end script map over {"Mark", "Erin", "David"} given script:mapScript script grepScript on lambda(someone) considering case if contents of someone is equal to "David" then return true end if return false end considering end lambda end script grep over {"Mark", "Erin", "David"} given script:grepScript

Replies are listed 'Best First'.
Re: RFC: Porting map() and grep() to AppleScript
by zentara (Archbishop) on Nov 23, 2009 at 17:20 UTC
    Thoughts?

    .... well eventually you must confront the issue that this is a Perl website....not AppleScript


    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku

      It is? I thought this was Facebook... ;-)

      Seriously, that's why I posted on Meditations as an RFC. I wasn't sure if it would be welcome as a real node. Maybe consider it a form of Perl advocacy in the AppleScript world, speaking the native language in order to reach more potential converts.

        ... i thought it was twiiter :-)

        ...seriously.... the conventional way to introduce non-perl scripts here, is to wrap them in an here doc, like:

        #/usr/bin/perl my $scriptSrc = <<"EOF"; <SCRIPT LANGUAGE="APPLESCRIPT"> # all your applescript here EOF print $scriptSrc,"\n";
        ... then everybody is happy

        I'm not really a human, but I play one on earth.
        Old Perl Programmer Haiku

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://808691]
Approved by keszler
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-04-20 00:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found