Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Concat var names ?

6 views
Skip to first unread message

Philippe M. Coatmeur

unread,
May 28, 2012, 12:37:29 AM5/28/12
to
Hi ; I have those two functions and I want to make them one :

(defun mail-bug-desktop-notify-one ()
(mapcar
(lambda (x)
(if (not (member x mail-bug-advertised-mails-one))
(progn
(mail-bug-desktop-notification
(format "%s" (first x))
(format "%s \n%s" (second x)
(third x))
"5000" mail-bug-new-mail-icon-one)
(add-to-list 'mail-bug-advertised-mails-one x))))
mail-bug-unseen-mails-one))

But I have to create distinct lists, so I'd really like to be able to
say

(setq suffix "plop")
(setq myvar-plop "value")
(message "%s" (concat "myvar-" suffix))

And get "myvar-value" instead of myvar-plop...

Or even better, to use the same mechanism, a mapcar, but what about
the creation of mail-bug-advertised-mails-SUFFIX ? How do I instruct
my function to tell one list from the other ?

Phil

XeCycle

unread,
May 27, 2012, 11:59:26 PM5/27/12
to help-gn...@gnu.org
Philippe M. Coatmeur <philippe...@gmail.com> writes:

> Hi ; I have those two functions and I want to make them one :
>
> (defun mail-bug-desktop-notify-one ()
> (mapcar
> (lambda (x)
> (if (not (member x mail-bug-advertised-mails-one))
> (progn
> (mail-bug-desktop-notification
> (format "%s" (first x))
> (format "%s \n%s" (second x)
> (third x))
> "5000" mail-bug-new-mail-icon-one)
> (add-to-list 'mail-bug-advertised-mails-one x))))
> mail-bug-unseen-mails-one))
>
> But I have to create distinct lists, so I'd really like to be able to
> say
>
> (setq suffix "plop")
> (setq myvar-plop "value")
> (message "%s" (concat "myvar-" suffix))
>
> And get "myvar-value" instead of myvar-plop...

Check what `intern' does.

> Or even better, to use the same mechanism, a mapcar, but what about
> the creation of mail-bug-advertised-mails-SUFFIX ? How do I instruct
> my function to tell one list from the other ?
>
> Phil
>

--
Carl Lei (XeCycle)
Department of Physics, Shanghai Jiao Tong University
OpenPGP public key: 7795E591
Fingerprint: 1FB6 7F1F D45D F681 C845 27F7 8D71 8EC4 7795 E591

Barry Margolin

unread,
May 28, 2012, 12:26:37 AM5/28/12
to
In article <mailman.1785.13381776...@gnu.org>,
XeCycle <XeC...@Gmail.com> wrote:

> Philippe M. Coatmeur <philippe...@gmail.com> writes:
>
> > Hi ; I have those two functions and I want to make them one :
> >
> > (defun mail-bug-desktop-notify-one ()
> > (mapcar
> > (lambda (x)
> > (if (not (member x mail-bug-advertised-mails-one))
> > (progn
> > (mail-bug-desktop-notification
> > (format "%s" (first x))
> > (format "%s \n%s" (second x)
> > (third x))
> > "5000" mail-bug-new-mail-icon-one)
> > (add-to-list 'mail-bug-advertised-mails-one x))))
> > mail-bug-unseen-mails-one))
> >
> > But I have to create distinct lists, so I'd really like to be able to
> > say
> >
> > (setq suffix "plop")
> > (setq myvar-plop "value")
> > (message "%s" (concat "myvar-" suffix))
> >
> > And get "myvar-value" instead of myvar-plop...
>
> Check what `intern' does.

You also need to use symbol-value to get the value of the variable
instead of just its name:

(message "%s" (symbol-value (intern (concat "myvar-" suffix"))))

--
Barry Margolin, bar...@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

Philippe M. Coatmeur

unread,
May 28, 2012, 3:39:14 AM5/28/12
to
At Mon, 28 May 2012 00:26:37 -0400,
Barry Margolin wrote:
>
> In article <mailman.1785.13381776...@gnu.org>,
> XeCycle <XeC...@Gmail.com> wrote:
>
> > Philippe M. Coatmeur <philippe...@gmail.com> writes:
> >
> > > Hi ; I have those two functions and I want to make them one :
(...)
> > >
> > > But I have to create distinct lists, so I'd really like to be able to
> > > say
> > >
> > > (setq suffix "plop")
> > > (setq myvar-plop "value")
> > > (message "%s" (concat "myvar-" suffix))
> > >
> > > And get "myvar-value" instead of myvar-plop...
> >
> > Check what `intern' does.
>
> You also need to use symbol-value to get the value of the variable
> instead of just its name:
>
> (message "%s" (symbol-value (intern (concat "myvar-" suffix"))))

Guys, thank you very much, it works like a charm, and with
"symbol-value" I can do pretty much whatever I want with the object
returned.

Phil
0 new messages