From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Pascal Bourguignon Newsgroups: gmane.emacs.help Subject: Re: Function binders in Elisp? Date: 19 Apr 2005 00:45:57 +0200 Organization: [posted via Easynet Spain] Message-ID: <87mzrv66vu.fsf@thalassa.informatimago.com> References: <1113841572.737369.303390@l41g2000cwc.googlegroups.com> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1113864397 17303 80.91.229.2 (18 Apr 2005 22:46:37 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 18 Apr 2005 22:46:37 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Apr 19 00:46:33 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1DNf0M-0002pQ-Gj for geh-help-gnu-emacs@m.gmane.org; Tue, 19 Apr 2005 00:46:10 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DNf4Y-0003SO-5u for geh-help-gnu-emacs@m.gmane.org; Mon, 18 Apr 2005 18:50:30 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed.icl.net!newsfeed.fjserv.net!diablo.theplanet.net!nntp.theplanet.net!inewsm1.nntp.theplanet.net!easynet-quince!easynet.net!easynet-post2!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 Original-Lines: 52 Original-NNTP-Posting-Host: 62.93.174.79 Original-X-Trace: DXC=YNogRQKUkoEA6KWF91n<^BEY<>`XO4V7M>Uh 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:25799 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:25799 PT writes: > On Mon, 18 Apr 2005 18:26:12 +0200, rgb wrote: > > > > 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. > > In very simple cases it might be simpler than writing those lambda > functions. STL introduced functional programming paradigms in C++, > that's why I thought there is a standard way in Lisp to do it and the > STL developers simply implemented the same function binders in C++. Well, what is clear and recognized by all lisp programmer is: (remove-if (lambda (x) (< 2 x)) '(1 2 3 4)) --> (1 2) Also there's this notion of currying. http://www.cs.oberlin.edu/classes/dragn/labs/combinators/combinators11.html In Common Lisp you'd write: (defun curry (f) (lambda (x) (lambda (y) (funcall f x y)))) (funcall (funcall (curry '+) 2) 3) --> 5 (remove-if (funcall (curry '<) 2) '(1 2 3 4)) --> (1 2) It's nicer in scheme. It doesn't work in emacs lisp. Despite the awkwardness of the notation in Common Lisp, it migh be better recognized than bind-second... > I know I can write my own macros to do that, but a standardized way > would be better, because it would be recognized by other Lisp > programmers too. From your answer it's clear there are no such > standard macros in (e)lisp, so it's not really worth the trouble, > because it would only make my programs harder to read for others. -- __Pascal Bourguignon__ http://www.informatimago.com/ Grace personified, I leap into the window. I meant to do that.