From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: =?utf-8?Q?Llu=C3=ADs?= Newsgroups: gmane.emacs.devel Subject: Re: Programmatic let Date: Wed, 05 Dec 2012 21:48:03 +0100 Message-ID: <87mwxsql8c.fsf@fimbulvetr.bsc.es> References: <87sj7kqm59.fsf@fimbulvetr.bsc.es> <87r4n4uteg.fsf@casa.home> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1354744206 18381 80.91.229.3 (5 Dec 2012 21:50:06 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 5 Dec 2012 21:50:06 +0000 (UTC) Cc: emacs-devel@gnu.org To: daimrod@gmail.com (=?utf-8?Q?Gr=C3=A9goire?= Jadi) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Dec 05 22:50:18 2012 Return-path: Envelope-to: ged-emacs-devel@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 1TgMr5-0000od-LX for ged-emacs-devel@m.gmane.org; Wed, 05 Dec 2012 22:50:11 +0100 Original-Received: from localhost ([::1]:57587 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TgLtd-0006Yc-KS for ged-emacs-devel@m.gmane.org; Wed, 05 Dec 2012 15:48:45 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:53852) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TgLt2-0005ti-3C for emacs-devel@gnu.org; Wed, 05 Dec 2012 15:48:09 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TgLt0-0002PF-RT for emacs-devel@gnu.org; Wed, 05 Dec 2012 15:48:07 -0500 Original-Received: from mailout-de.gmx.net ([213.165.64.22]:50631) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1TgLt0-0002PA-Ik for emacs-devel@gnu.org; Wed, 05 Dec 2012 15:48:06 -0500 Original-Received: (qmail invoked by alias); 05 Dec 2012 20:48:05 -0000 Original-Received: from unknown (EHLO localhost) [84.88.51.85] by mail.gmx.net (mp024) with SMTP; 05 Dec 2012 21:48:05 +0100 X-Authenticated: #12333383 X-Provags-ID: V01U2FsdGVkX192X41QaGZ2b5Voso0qfD9LYV3tCL2LT3GbIF5ZLY JwPS/OX7a+1GTe Mail-Followup-To: daimrod@gmail.com (=?utf-8?Q?Gr=C3=A9goire?= Jadi), emacs-devel@gnu.org In-Reply-To: <87r4n4uteg.fsf@casa.home> (=?utf-8?Q?=22Gr=C3=A9goire?= Jadi"'s message of "Wed, 05 Dec 2012 21:37:59 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) X-Y-GMX-Trusted: 0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 213.165.64.22 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:155313 Archived-At: Gr=C3=A9goire Jadi writes: > Llu=C3=ADs writes: >> My elisp foo is quite poor, so this might well be a completely stupid ap= proach >> to the problem. >>=20 >> I have a callback that gets automatically called, and uses some orgmode-= specific >> routines whose behaviour can be tuned through some customizable variable= s. >>=20 >> The usual approach in orgmode is: >>=20 >> (let ((org-v1 ...) (org-v2 ...)) (org-func ...)) >>=20 >> As my function is automatically called (as a response to the D-Bus messa= ge), I'd >> like to let the user specify a let-like form to let her temporarily over= ride the >> behaviour of the `org-func' that my package invokes: >>=20 >> (setq my-cb-org-vars '((org-v1 ...) (org-v2 ...))) >> (defun my-cb (...) >> (programmatic-let my-cb-org-vars >> (org-func ...))) >>=20 >> Is it possible to implement `programmatic-let'? And if so, can you throw= me a >> pointer to the appropriate docs? > You could use progv: >> (progv SYMBOLS VALUES &rest BODY) >>=20 >> Bind SYMBOLS to VALUES dynamically in BODY. >> The forms SYMBOLS and VALUES are evaluated, and must evaluate to lists. >> Each symbol in the first list is bound to the corresponding value in the >> second list (or to nil if VALUES is shorter than SYMBOLS); then the >> BODY forms are executed and their result is returned. This is much like >> a `let' form, except that the list of symbols can be computed at run-tim= e. > However, given a defined set of variables, you could parse > my-cb-org-vars yourself: > (defvar my-cb-org-vars '((x ...) (y ...))) > (defun my-cb (...) > (let ((x (cdr (assoc 'x my-cb-org-vars))) > (y (cdr (assoc 'y my-cb-org-vars)))) > ....)) Thanks a lot, `progv' is exactly what I want, given that the list of vars i= s not known a priori. Lluis --=20 "And it's much the same thing with knowledge, for whenever you learn something new, the whole world becomes that much richer." -- The Princess of Pure Reason, as told by Norton Juster in The Phantom Tollbooth