[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Function binders in Elisp?
From: |
rgb |
Subject: |
Re: Function binders in Elisp? |
Date: |
18 Apr 2005 09:26:12 -0700 |
User-agent: |
G2/0.2 |
PT wrote:
> For predicates I usually use lambda functions. For example:
>
> (require 'cl)
> (remove-if (lambda (x) (> x 2))
> '(1 2 3 4))
>
> I'm not a lisp guru, therefore I often wonder if there are standard
binder
> functions in emacs lisp like for example bind2nd in C++ STL which
> transforms a binary function into an unary function:
>
> find_if(L.begin(), L.end(), bind2nd(greater<int>(), 2)) // C++
>
> So that I can write something like this:
>
> (remove-if (bind-second '< 2)
> '(1 2 3 4))
So you are looking to do this?
(defmacro bind-second (first &rest others)
`(lambda (x) (,first x ,@others)))
(remove-if (bind-second > 2)
'(1 2 3 4))
I'd think that would make the code a bit more confusing to read.
But maybe it's just me.