unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Programmatic let
@ 2012-12-05 20:28 Lluís
  2012-12-05 20:37 ` Grégoire Jadi
  2012-12-05 20:39 ` Burton Samograd
  0 siblings, 2 replies; 4+ messages in thread
From: Lluís @ 2012-12-05 20:28 UTC (permalink / raw)
  To: emacs-devel

My elisp foo is quite poor, so this might well be a completely stupid approach
to the problem.

I have a callback that gets automatically called, and uses some orgmode-specific
routines whose behaviour can be tuned through some customizable variables.

The usual approach in orgmode is:

  (let ((org-v1 ...) (org-v2 ...)) (org-func ...))

As my function is automatically called (as a response to the D-Bus message), I'd
like to let the user specify a let-like form to let her temporarily override the
behaviour of the `org-func' that my package invokes:

  (setq my-cb-org-vars '((org-v1 ...) (org-v2 ...)))
  (defun my-cb (...)
    (programmatic-let my-cb-org-vars
      (org-func ...)))

Is it possible to implement `programmatic-let'? And if so, can you throw me a
pointer to the appropriate docs?


Thanks,
  Lluis

-- 
 "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



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Programmatic let
  2012-12-05 20:28 Programmatic let Lluís
@ 2012-12-05 20:37 ` Grégoire Jadi
  2012-12-05 20:48   ` Lluís
  2012-12-05 20:39 ` Burton Samograd
  1 sibling, 1 reply; 4+ messages in thread
From: Grégoire Jadi @ 2012-12-05 20:37 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1640 bytes --]

Lluís <xscript@gmx.net> writes:

> My elisp foo is quite poor, so this might well be a completely stupid approach
> to the problem.
>
> I have a callback that gets automatically called, and uses some orgmode-specific
> routines whose behaviour can be tuned through some customizable variables.
>
> The usual approach in orgmode is:
>
>   (let ((org-v1 ...) (org-v2 ...)) (org-func ...))
>
> As my function is automatically called (as a response to the D-Bus message), I'd
> like to let the user specify a let-like form to let her temporarily override the
> behaviour of the `org-func' that my package invokes:
>
>   (setq my-cb-org-vars '((org-v1 ...) (org-v2 ...)))
>   (defun my-cb (...)
>     (programmatic-let my-cb-org-vars
>       (org-func ...)))
>
> 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)
> 
> 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-time.

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))))
    ....))

[-- Attachment #2: Type: application/pgp-signature, Size: 835 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Programmatic let
  2012-12-05 20:28 Programmatic let Lluís
  2012-12-05 20:37 ` Grégoire Jadi
@ 2012-12-05 20:39 ` Burton Samograd
  1 sibling, 0 replies; 4+ messages in thread
From: Burton Samograd @ 2012-12-05 20:39 UTC (permalink / raw)
  To: emacs-devel

Lluís <xscript@gmx.net> writes:

> My elisp foo is quite poor, so this might well be a completely stupid approach
> to the problem.
>
> I have a callback that gets automatically called, and uses some orgmode-specific
> routines whose behaviour can be tuned through some customizable variables.
>
> The usual approach in orgmode is:
>
>   (let ((org-v1 ...) (org-v2 ...)) (org-func ...))
>
> As my function is automatically called (as a response to the D-Bus message), I'd
> like to let the user specify a let-like form to let her temporarily override the
> behaviour of the `org-func' that my package invokes:
>
>   (setq my-cb-org-vars '((org-v1 ...) (org-v2 ...)))
>   (defun my-cb (...)
>     (programmatic-let my-cb-org-vars
>       (org-func ...)))

This should work:

(defmacro programmatic-let (vars &rest body)
    `(let ,vars
          ,@body))

--
Burton Samograd





^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Programmatic let
  2012-12-05 20:37 ` Grégoire Jadi
@ 2012-12-05 20:48   ` Lluís
  0 siblings, 0 replies; 4+ messages in thread
From: Lluís @ 2012-12-05 20:48 UTC (permalink / raw)
  To: Grégoire Jadi; +Cc: emacs-devel

Grégoire Jadi writes:

> Lluís <xscript@gmx.net> writes:
>> My elisp foo is quite poor, so this might well be a completely stupid approach
>> to the problem.
>> 
>> I have a callback that gets automatically called, and uses some orgmode-specific
>> routines whose behaviour can be tuned through some customizable variables.
>> 
>> The usual approach in orgmode is:
>> 
>> (let ((org-v1 ...) (org-v2 ...)) (org-func ...))
>> 
>> As my function is automatically called (as a response to the D-Bus message), I'd
>> like to let the user specify a let-like form to let her temporarily override the
>> behaviour of the `org-func' that my package invokes:
>> 
>> (setq my-cb-org-vars '((org-v1 ...) (org-v2 ...)))
>> (defun my-cb (...)
>> (programmatic-let my-cb-org-vars
>> (org-func ...)))
>> 
>> 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)
>> 
>> 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-time.

> 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 is not
known a priori.


Lluis

-- 
 "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



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-12-05 20:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-05 20:28 Programmatic let Lluís
2012-12-05 20:37 ` Grégoire Jadi
2012-12-05 20:48   ` Lluís
2012-12-05 20:39 ` Burton Samograd

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).