From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Rusi Newsgroups: gmane.emacs.help Subject: Re: Possible to conditionally bind variable? Date: Thu, 11 Sep 2014 20:55:46 -0700 (PDT) Message-ID: <4297420c-f2f5-4675-bcc5-58742a253ef1@googlegroups.com> References: <87lhpq8l8y.fsf@gmail.com> <87oaum5oql.fsf@geodiff-mac3.ulb.ac.be> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: ger.gmane.org 1410494428 14372 80.91.229.3 (12 Sep 2014 04:00:28 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 12 Sep 2014 04:00:28 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Sep 12 06:00:23 2014 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XSI22-00087y-TN for geh-help-gnu-emacs@m.gmane.org; Fri, 12 Sep 2014 06:00:23 +0200 Original-Received: from localhost ([::1]:42405 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XSI22-0004d6-Jo for geh-help-gnu-emacs@m.gmane.org; Fri, 12 Sep 2014 00:00:22 -0400 X-Received: by 10.182.213.138 with SMTP id ns10mr2992616obc.45.1410494147400; Thu, 11 Sep 2014 20:55:47 -0700 (PDT) X-Received: by 10.50.119.7 with SMTP id kq7mr104087igb.12.1410494147307; Thu, 11 Sep 2014 20:55:47 -0700 (PDT) Original-Path: usenet.stanford.edu!r10no524382igi.0!news-out.google.com!ef6ni3693igb.0!nntp.google.com!h18no55053igc.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=59.95.9.169; posting-account=mBpa7woAAAAGLEWUUKpmbxm-Quu5D8ui Original-NNTP-Posting-Host: 59.95.9.169 User-Agent: G2/1.0 Injection-Date: Fri, 12 Sep 2014 03:55:47 +0000 Original-Xref: usenet.stanford.edu gnu.emacs.help:207567 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:99842 Archived-At: On Thursday, September 11, 2014 6:04:33 PM UTC+5:30, Stefan Monnier wrote: > > (defun go-or-make-agenda (&optional new-frame) > > (interactive "P") > > (let ((buffer "\*Org Agenda\*") > > (some-other-buffer "*scratch*") > > (my-switch-function (if new-frame ;; is there some way to do this? > > 'switch-to-buffer-other-frame > > 'switch-to-buffer))) > > (if (get-buffer buffer) > > (funcall my-switch-function buffer) > > (funcall my-switch-function some-other-buffer)))) > Aka > (defun go-or-make-agenda (&optional new-frame) > (interactive "P") > (let ((buffer "\*Org Agenda\*") > (some-other-buffer "*scratch*") > (my-switch-function (if new-frame ;; is there some way to do this? > 'switch-to-buffer-other-frame > 'switch-to-buffer))) > (funcall my-switch-function > (if (get-buffer buffer) buffer some-other-buffer)))) > Aka > (defun go-or-make-agenda (&optional new-frame) > (interactive "P") > (let ((buffer "\*Org Agenda\*") > (some-other-buffer "*scratch*")) > (funcall (if new-frame 'switch-to-buffer-other-frame 'switch-to-buffer) > (if (get-buffer buffer) buffer some-other-buffer)))) Seeing this beautiful code, cant help making the remark: This is called functional programming; guys like Stefan do it guys like talk about it. Here is some more talk -- what Stefan has demoed above is one of the many cases outlined there: http://blog.languager.org/2012/10/functional-programming-lost-booty.html