[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Possible to conditionally bind variable?
From: |
Rusi |
Subject: |
Re: Possible to conditionally bind variable? |
Date: |
Thu, 11 Sep 2014 20:55:46 -0700 (PDT) |
User-agent: |
G2/1.0 |
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