From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Marco Antoniotti Newsgroups: gmane.emacs.help Subject: Re: Help needed to simplify code for customisation Date: Tue, 10 Mar 2009 09:53:39 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <46c6811e-771a-4162-a0c7-967b788793e1@v35g2000pro.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1236707827 19922 80.91.229.12 (10 Mar 2009 17:57:07 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 10 Mar 2009 17:57:07 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Mar 10 18:58:24 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Lh6De-0005U6-Tu for geh-help-gnu-emacs@m.gmane.org; Tue, 10 Mar 2009 18:58:23 +0100 Original-Received: from localhost ([127.0.0.1]:45382 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Lh6CJ-0004Iz-1h for geh-help-gnu-emacs@m.gmane.org; Tue, 10 Mar 2009 13:56:59 -0400 Original-Path: news.stanford.edu!newsfeed.stanford.edu!postnews.google.com!h5g2000yqh.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help,comp.emacs,comp.lang.lisp Original-Lines: 42 Original-NNTP-Posting-Host: 149.132.179.138 Original-X-Trace: posting.google.com 1236704019 24964 127.0.0.1 (10 Mar 2009 16:53:39 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Tue, 10 Mar 2009 16:53:39 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: h5g2000yqh.googlegroups.com; posting-host=149.132.179.138; posting-account=GS19jgoAAAAoOF0-1XY4y5Kr-ZXxu31k User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_6; en-us) AppleWebKit/525.27.1 (KHTML, like Gecko) Version/3.2.1 Safari/525.27.1, gzip(gfe), gzip(gfe) Original-Xref: news.stanford.edu gnu.emacs.help:167506 comp.emacs:97988 comp.lang.lisp:262590 X-Mailman-Approved-At: Tue, 10 Mar 2009 13:54:34 -0400 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:62816 Archived-At: On Mar 10, 12:42=A0pm, "William James" wrote: > TomSW wrote: > > (require 'cl) > > > (defvar my-accounts-alist > > =A0 '(("richardriley" =A0"root" "richardriley") > > =A0 =A0 ("rileyrgdev" =A0 =A0"rileyrgdev")) > > =A0 "Associate email accounts with sender addresses: an alist each item > > of > > which is a list whose first member is the account name and any > > following > > members are regular expressions to match against a sender address.") > > > (defun my-get-account (from) > > =A0 (car (find-if (lambda (regexps) > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (some (lambda (regexp) > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (string-match regex= p from)) > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 regexps)) > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 from my-accounts-alist > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 :key 'cdr))) > > Clojure: > > (def my-accounts-map > =A0 { "richardriley" =A0[#"root" #"richardriley"], > =A0 =A0 "rileyrgdev" =A0 =A0[#"rileyrgdev"] } ) > > (defn my-get-account [from] > =A0 (ffirst > =A0 =A0 (filter > =A0 =A0 =A0 (fn [[acct re-list]] (some #(re-find % from) re-list)) > =A0 =A0 =A0 my-accounts-map))) Hey. That is not the homework you are supposed to hand in. Cheers -- Marco