help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help needed to simplify code for customisation


From: William James
Subject: Re: Help needed to simplify code for customisation
Date: 10 Mar 2009 11:42:24 GMT
User-agent: XanaNews/1.18.1.6

TomSW wrote:

> (require 'cl)
> 
> (defvar my-accounts-alist
>   '(("richardriley"  "root" "richardriley")
>     ("rileyrgdev"    "rileyrgdev"))
>   "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)
>   (car (find-if (lambda (regexps)
>                   (some (lambda (regexp)
>                           (string-match regexp from))
>                         regexps))
>                 from my-accounts-alist
>                 :key 'cdr)))

Clojure:

(def my-accounts-map
  { "richardriley"  [#"root" #"richardriley"],
    "rileyrgdev"    [#"rileyrgdev"] } )

(defn my-get-account [from]
  (ffirst
    (filter
      (fn [[acct re-list]] (some #(re-find % from) re-list))
      my-accounts-map)))




reply via email to

[Prev in Thread] Current Thread [Next in Thread]