unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Dumb elisp question
@ 2011-09-30  9:15 Eric Abrahamsen
  2011-09-30  9:18 ` Le Wang
  2011-09-30  9:49 ` Jambunathan K
  0 siblings, 2 replies; 5+ messages in thread
From: Eric Abrahamsen @ 2011-09-30  9:15 UTC (permalink / raw)
  To: help-gnu-emacs

I've made a function that takes as arguments an arbitrary format string
and a list of arguments to that string. The list of arguments is of
varying length, and the args need to be mapped through a function before
they're passed to the format string. So in the bowels of the function
there's something like:

(format fmt-str-var (mapcar (lambda (arg) (do-thing-with arg))
list-of-arguments))

Obviously, the problem is that mapcar returns a single list of strings,
not the series of atomic strings that format requires.

I've tried to solve this problem many different ways, including turning
this into a macro and using ",@", and using ",@" even when it's not a
macro, and looking at other mapping functions, and trying to make some
sort of "splice" function of my own, and… and…

Nothing works quite right. This can't be a macro because elsewhere it
needs to pass `commandp'. I can't make any of the other fixes work
properly.

Can anyone provide an elegant solution?

Thanks,
Eric



-- 
GNU Emacs 23.2.1 (i686-pc-linux-gnu, GTK+ Version 2.24.4)
 of 2011-04-04 on rothera, modified by Debian




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

* Re: Dumb elisp question
  2011-09-30  9:15 Dumb elisp question Eric Abrahamsen
@ 2011-09-30  9:18 ` Le Wang
  2011-09-30  9:49 ` Jambunathan K
  1 sibling, 0 replies; 5+ messages in thread
From: Le Wang @ 2011-09-30  9:18 UTC (permalink / raw)
  To: Eric Abrahamsen; +Cc: help-gnu-emacs

On Fri, Sep 30, 2011 at 5:15 PM, Eric Abrahamsen
<eric@ericabrahamsen.net> wrote:
> Can anyone provide an elegant solution?

apply

-- 
Le



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

* Re: Dumb elisp question
  2011-09-30  9:15 Dumb elisp question Eric Abrahamsen
  2011-09-30  9:18 ` Le Wang
@ 2011-09-30  9:49 ` Jambunathan K
  2011-09-30 13:12   ` Eric Abrahamsen
  1 sibling, 1 reply; 5+ messages in thread
From: Jambunathan K @ 2011-09-30  9:49 UTC (permalink / raw)
  To: Eric Abrahamsen; +Cc: help-gnu-emacs


I think you are looking for this:

(apply 'format "%s %s" '("one" "two"))

> I've made a function that takes as arguments an arbitrary format string
> and a list of arguments to that string. The list of arguments is of
> varying length, and the args need to be mapped through a function before
> they're passed to the format string. So in the bowels of the function
> there's something like:
>
> (format fmt-str-var (mapcar (lambda (arg) (do-thing-with arg))
> list-of-arguments))
>
> Obviously, the problem is that mapcar returns a single list of strings,
> not the series of atomic strings that format requires.


> I've tried to solve this problem many different ways, including turning
> this into a macro and using ",@", and using ",@" even when it's not a
> macro, and looking at other mapping functions, and trying to make some
> sort of "splice" function of my own, and… and…
>
> Nothing works quite right. This can't be a macro because elsewhere it
> needs to pass `commandp'. I can't make any of the other fixes work
> properly.
>
> Can anyone provide an elegant solution?
>
> Thanks,
> Eric

-- 



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

* Re: Dumb elisp question
  2011-09-30  9:49 ` Jambunathan K
@ 2011-09-30 13:12   ` Eric Abrahamsen
  2011-10-01 12:11     ` Le Wang
  0 siblings, 1 reply; 5+ messages in thread
From: Eric Abrahamsen @ 2011-09-30 13:12 UTC (permalink / raw)
  To: help-gnu-emacs

On Fri, Sep 30 2011, Jambunathan K wrote:

> I think you are looking for this:
>
> (apply 'format "%s %s" '("one" "two"))

GAH! I've learned this like four times, hopefully this time it will
stick. Thanks to both of you.

E

-- 
GNU Emacs 23.2.1 (i686-pc-linux-gnu, GTK+ Version 2.24.4)
 of 2011-04-04 on rothera, modified by Debian




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

* Re: Dumb elisp question
  2011-09-30 13:12   ` Eric Abrahamsen
@ 2011-10-01 12:11     ` Le Wang
  0 siblings, 0 replies; 5+ messages in thread
From: Le Wang @ 2011-10-01 12:11 UTC (permalink / raw)
  To: Eric Abrahamsen; +Cc: help-gnu-emacs

On Fri, Sep 30, 2011 at 9:12 PM, Eric Abrahamsen
<eric@ericabrahamsen.net> wrote:
> GAH! I've learned this like four times, hopefully this time it will
> stick. Thanks to both of you.

You keep using words like didactic, and we'll keep answering your
elisp questions.  It's a fair trade.


-- 
Le



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

end of thread, other threads:[~2011-10-01 12:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-09-30  9:15 Dumb elisp question Eric Abrahamsen
2011-09-30  9:18 ` Le Wang
2011-09-30  9:49 ` Jambunathan K
2011-09-30 13:12   ` Eric Abrahamsen
2011-10-01 12:11     ` Le Wang

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