* Re: shorter form of frequently-seen lisp idiom?
[not found] <mailman.680.1108839059.32256.help-gnu-emacs@gnu.org>
@ 2005-02-19 18:43 ` David Kastrup
2005-02-19 23:31 ` August
[not found] ` <mailman.714.1108857188.32256.help-gnu-emacs@gnu.org>
2005-02-22 14:44 ` Stefan Monnier
1 sibling, 2 replies; 15+ messages in thread
From: David Kastrup @ 2005-02-19 18:43 UTC (permalink / raw)
Joe Corneli <jcorneli@math.utexas.edu> writes:
> Is there a shorter way to concatenate a list of strings
> than this?
>
> (eval (append (list 'concat) list-of-strings))
>
> Or more generally,
>
> (eval (append (list 'function-that-acts-on-foos) list-of-foos))
(apply #'concat list-of-strings)
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: shorter form of frequently-seen lisp idiom?
2005-02-19 18:43 ` shorter form of frequently-seen lisp idiom? David Kastrup
@ 2005-02-19 23:31 ` August
[not found] ` <mailman.714.1108857188.32256.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 15+ messages in thread
From: August @ 2005-02-19 23:31 UTC (permalink / raw)
On lör, 2005-02-19 at 19:43 +0100, David Kastrup wrote:
> Joe Corneli <jcorneli@math.utexas.edu> writes:
>
> > Is there a shorter way to concatenate a list of strings
> > than this?
> >
> > (eval (append (list 'concat) list-of-strings))
> >
> > Or more generally,
> >
> > (eval (append (list 'function-that-acts-on-foos) list-of-foos))
>
> (apply #'concat list-of-strings)
>
>
What's the purpose of the hash sign? `(apply 'concat list-of-strings)'
works too.
--
August
^ permalink raw reply [flat|nested] 15+ messages in thread
[parent not found: <mailman.714.1108857188.32256.help-gnu-emacs@gnu.org>]
* Re: shorter form of frequently-seen lisp idiom?
[not found] ` <mailman.714.1108857188.32256.help-gnu-emacs@gnu.org>
@ 2005-02-19 23:55 ` David Kastrup
2005-02-21 0:07 ` Denis Bueno
[not found] ` <mailman.835.1108945397.32256.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 15+ messages in thread
From: David Kastrup @ 2005-02-19 23:55 UTC (permalink / raw)
August <fusionfive@comhem.se> writes:
> On lör, 2005-02-19 at 19:43 +0100, David Kastrup wrote:
>> Joe Corneli <jcorneli@math.utexas.edu> writes:
>>
>> > Is there a shorter way to concatenate a list of strings
>> > than this?
>> >
>> > (eval (append (list 'concat) list-of-strings))
>> >
>> > Or more generally,
>> >
>> > (eval (append (list 'function-that-acts-on-foos) list-of-foos))
>>
>> (apply #'concat list-of-strings)
>>
>
> What's the purpose of the hash sign? `(apply 'concat
> list-of-strings)' works too.
'concat is short for (quote concat), #'concat is short for
(function concat).
It tells the byte compiler that it is ok to compile the function. For
example,
'(lambda nil (if))
is a perfectly valid list and if used in function context even in
compiled Elisp files, will be evaled the slow way at run time.
#'(lambda nil (if)) in contrast gets byte-compiled (and the byte
compiler will probably barf).
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: shorter form of frequently-seen lisp idiom?
2005-02-19 23:55 ` David Kastrup
@ 2005-02-21 0:07 ` Denis Bueno
2005-02-21 0:17 ` Denis Bueno
[not found] ` <mailman.835.1108945397.32256.help-gnu-emacs@gnu.org>
1 sibling, 1 reply; 15+ messages in thread
From: Denis Bueno @ 2005-02-21 0:07 UTC (permalink / raw)
On Sun, 20 Feb 2005 00:55:53 +0100, David Kastrup <dak@gnu.org> wrote:
> August <fusionfive@comhem.se> writes:
>
> > On lör, 2005-02-19 at 19:43 +0100, David Kastrup wrote:
> >> Joe Corneli <jcorneli@math.utexas.edu> writes:
> >>
> >> > Is there a shorter way to concatenate a list of strings
> >> > than this?
> >> >
> >> > (eval (append (list 'concat) list-of-strings))
> >> >
> >> > Or more generally,
> >> >
> >> > (eval (append (list 'function-that-acts-on-foos) list-of-foos))
Or even:
(reduce #'function-that-acts-on-2-foos list-of-foos)
Like:
(reduce #'concat '("aoeu" "1234" "htns")) =>
"aoeu1234htns"
--
Denis Bueno
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: shorter form of frequently-seen lisp idiom?
2005-02-21 0:07 ` Denis Bueno
@ 2005-02-21 0:17 ` Denis Bueno
0 siblings, 0 replies; 15+ messages in thread
From: Denis Bueno @ 2005-02-21 0:17 UTC (permalink / raw)
You might need to (require 'cl) first.
On Sun, 20 Feb 2005 19:07:11 -0500, Denis Bueno <dbueno@gmail.com> wrote:
> On Sun, 20 Feb 2005 00:55:53 +0100, David Kastrup <dak@gnu.org> wrote:
> > August <fusionfive@comhem.se> writes:
> >
> > > On lör, 2005-02-19 at 19:43 +0100, David Kastrup wrote:
> > >> Joe Corneli <jcorneli@math.utexas.edu> writes:
> > >>
> > >> > Is there a shorter way to concatenate a list of strings
> > >> > than this?
> > >> >
> > >> > (eval (append (list 'concat) list-of-strings))
> > >> >
> > >> > Or more generally,
> > >> >
> > >> > (eval (append (list 'function-that-acts-on-foos) list-of-foos))
>
> Or even:
>
> (reduce #'function-that-acts-on-2-foos list-of-foos)
>
> Like:
>
> (reduce #'concat '("aoeu" "1234" "htns")) =>
> "aoeu1234htns"
>
> --
> Denis Bueno
>
--
Denis Bueno
^ permalink raw reply [flat|nested] 15+ messages in thread
[parent not found: <mailman.835.1108945397.32256.help-gnu-emacs@gnu.org>]
* Re: shorter form of frequently-seen lisp idiom?
[not found] ` <mailman.835.1108945397.32256.help-gnu-emacs@gnu.org>
@ 2005-02-21 0:28 ` David Kastrup
0 siblings, 0 replies; 15+ messages in thread
From: David Kastrup @ 2005-02-21 0:28 UTC (permalink / raw)
Denis Bueno <dbueno@gmail.com> writes:
> On Sun, 20 Feb 2005 00:55:53 +0100, David Kastrup <dak@gnu.org> wrote:
>> August <fusionfive@comhem.se> writes:
>>
>> > On lör, 2005-02-19 at 19:43 +0100, David Kastrup wrote:
>> >> Joe Corneli <jcorneli@math.utexas.edu> writes:
>> >>
>> >> > Is there a shorter way to concatenate a list of strings
>> >> > than this?
>> >> >
>> >> > (eval (append (list 'concat) list-of-strings))
>> >> >
>> >> > Or more generally,
>> >> >
>> >> > (eval (append (list 'function-that-acts-on-foos) list-of-foos))
>
> Or even:
>
> (reduce #'function-that-acts-on-2-foos list-of-foos)
>
> Like:
>
> (reduce #'concat '("aoeu" "1234" "htns")) =>
> "aoeu1234htns"
Why should one do that? Quite less efficient than using "apply", and
only available if cl has been loaded.
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: shorter form of frequently-seen lisp idiom?
[not found] <mailman.680.1108839059.32256.help-gnu-emacs@gnu.org>
2005-02-19 18:43 ` shorter form of frequently-seen lisp idiom? David Kastrup
@ 2005-02-22 14:44 ` Stefan Monnier
2005-02-22 18:29 ` rgb
1 sibling, 1 reply; 15+ messages in thread
From: Stefan Monnier @ 2005-02-22 14:44 UTC (permalink / raw)
> Is there a shorter way to concatenate a list of strings than this?
> (eval (append (list 'concat) list-of-strings))
Rule of thumb: if your solution uses `eval' it's either buggy or clunky.
Other than the best solution using `apply', you may also want to use
`mapconcat', depending on the specific circumstance.
Stefan
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: shorter form of frequently-seen lisp idiom?
2005-02-22 14:44 ` Stefan Monnier
@ 2005-02-22 18:29 ` rgb
2005-02-22 18:51 ` Thien-Thi Nguyen
2005-02-22 21:20 ` Oliver Scholz
0 siblings, 2 replies; 15+ messages in thread
From: rgb @ 2005-02-22 18:29 UTC (permalink / raw)
> Rule of thumb: if your solution uses `eval' it's either buggy or
clunky.
Interesting, I've never heard this.
My elisp isn't all that great yet so I looked for instances where
I use it.
(defun tacl-eldoc-function ()
"Returns a documentation string for context near point or nil"
(let ((word (thing-at-point 'symbol)))
(if word
(eval (intern-soft (upcase word) tacl-eldoc-obarray)))))
tacl-eldoc-obarray is populated like this.
(set (intern "FOO" tacl-eldoc-obarray) "FOO help text here")
(set (intern "BAR" tacl-eldoc-obarray) "BAR help text")
...
I thought this might be an exception to your rule because apply
doesn't apply. But then it occured to me that symbol-value is
probably what I should have coded.
Is there a collection of more such tips someplace?
Thanks
Rick
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: shorter form of frequently-seen lisp idiom?
2005-02-22 18:29 ` rgb
@ 2005-02-22 18:51 ` Thien-Thi Nguyen
2005-02-23 16:29 ` rgb
2005-02-22 21:20 ` Oliver Scholz
1 sibling, 1 reply; 15+ messages in thread
From: Thien-Thi Nguyen @ 2005-02-22 18:51 UTC (permalink / raw)
"rgb" <rbielaws@i1.net> writes:
> [code]
> symbol-value is
> probably what I should have coded.
instead of obarray + set + eval,
why not use hash table + puthash + gethash?
thi
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: shorter form of frequently-seen lisp idiom?
2005-02-22 18:51 ` Thien-Thi Nguyen
@ 2005-02-23 16:29 ` rgb
2005-02-23 18:03 ` Thien-Thi Nguyen
0 siblings, 1 reply; 15+ messages in thread
From: rgb @ 2005-02-23 16:29 UTC (permalink / raw)
Thien-Thi Nguyen wrote:
> "rgb" <rbielaws@i1.net> writes:
>
> > [code]
> > symbol-value is
> > probably what I should have coded.
>
> instead of obarray + set + eval,
> why not use hash table + puthash + gethash?
>
Using obarray let me copy exactly what the lisp modes
were doing to get eldoc working.
I've never used the hash functions. Being unfamiliar, I
didn't realize they might be useful to this situation.
Now that I look at them, I see what you mean.
Thanks for the suggestion.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: shorter form of frequently-seen lisp idiom?
2005-02-23 16:29 ` rgb
@ 2005-02-23 18:03 ` Thien-Thi Nguyen
0 siblings, 0 replies; 15+ messages in thread
From: Thien-Thi Nguyen @ 2005-02-23 18:03 UTC (permalink / raw)
"rgb" <rbielaws@i1.net> writes:
> Using obarray let me copy exactly what the lisp modes
> were doing to get eldoc working.
it's probably a good idea to retain that congruence,
at least if you wish the code to be usable on old emacsen;
builtin hash tables aren't yet widely available.
i see that eldoc.el implements a hash table anyway.
perhaps it will be revised One of These Days...
thi
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: shorter form of frequently-seen lisp idiom?
2005-02-22 18:29 ` rgb
2005-02-22 18:51 ` Thien-Thi Nguyen
@ 2005-02-22 21:20 ` Oliver Scholz
2005-02-22 22:16 ` Drew Adams
[not found] ` <mailman.1159.1109113137.32256.help-gnu-emacs@gnu.org>
1 sibling, 2 replies; 15+ messages in thread
From: Oliver Scholz @ 2005-02-22 21:20 UTC (permalink / raw)
"rgb" <rbielaws@i1.net> writes:
>> Rule of thumb: if your solution uses `eval' it's either buggy or
> clunky.
>
> Interesting, I've never heard this.
> My elisp isn't all that great yet so I looked for instances where
> I use it.
I use `eval' only when not using it would be tantamount to
implementing a metacircular lisp interpreter.
>
> Is there a collection of more such tips someplace?
ISTR that some tips like that (i.e. using `funcall' or `apply' instead
of `eval') are in the (old?) FAQ for comp.lang.lisp. But it's rather
for common lisp.
Oliver
--
4 Ventôse an 213 de la Révolution
Liberté, Egalité, Fraternité!
^ permalink raw reply [flat|nested] 15+ messages in thread
* shorter form of frequently-seen lisp idiom?
@ 2005-02-19 18:33 Joe Corneli
0 siblings, 0 replies; 15+ messages in thread
From: Joe Corneli @ 2005-02-19 18:33 UTC (permalink / raw)
Is there a shorter way to concatenate a list of strings
than this?
(eval (append (list 'concat) list-of-strings))
Or more generally,
(eval (append (list 'function-that-acts-on-foos) list-of-foos))
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2005-02-23 18:48 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <mailman.680.1108839059.32256.help-gnu-emacs@gnu.org>
2005-02-19 18:43 ` shorter form of frequently-seen lisp idiom? David Kastrup
2005-02-19 23:31 ` August
[not found] ` <mailman.714.1108857188.32256.help-gnu-emacs@gnu.org>
2005-02-19 23:55 ` David Kastrup
2005-02-21 0:07 ` Denis Bueno
2005-02-21 0:17 ` Denis Bueno
[not found] ` <mailman.835.1108945397.32256.help-gnu-emacs@gnu.org>
2005-02-21 0:28 ` David Kastrup
2005-02-22 14:44 ` Stefan Monnier
2005-02-22 18:29 ` rgb
2005-02-22 18:51 ` Thien-Thi Nguyen
2005-02-23 16:29 ` rgb
2005-02-23 18:03 ` Thien-Thi Nguyen
2005-02-22 21:20 ` Oliver Scholz
2005-02-22 22:16 ` Drew Adams
[not found] ` <mailman.1159.1109113137.32256.help-gnu-emacs@gnu.org>
2005-02-23 18:48 ` rgb
2005-02-19 18:33 Joe Corneli
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.