* until-found
@ 2009-12-10 12:50 Andreas Roehler
2009-12-10 13:58 ` until-found tomas
0 siblings, 1 reply; 5+ messages in thread
From: Andreas Roehler @ 2009-12-10 12:50 UTC (permalink / raw)
To: help-gnu-emacs
Hi,
given a list or a list of lists:
list shall be returned, if it contains a certain member.
I'm pretty sure a general form exists, but ignore it.
Function `dired-compress-file' in dired-aux.el does it that way:
(let (...
(suffixes dired-compress-file-suffixes))
;; See if any suffix rule matches this file name.
(while suffixes
(let (case-fold-search)
(if (string-match (car (car suffixes)) file)
(setq suffix (car suffixes) suffixes nil))
(setq suffixes (cdr suffixes))))
And here my implementation so far:
(defun until-found (search-string liste)
(let ((liste liste) element)
(while liste
(if (member search-string (car liste))
(setq element (car liste) liste nil))
(setq liste (cdr liste)))
element))
However, would prefer making use of some existing...
Any comments welcome
Andreas
--
https://code.launchpad.net/s-x-emacs-werkstatt/
http://bazaar.launchpad.net/~a-roehler/python-mode/python-mode.el/
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: until-found
2009-12-10 12:50 until-found Andreas Roehler
@ 2009-12-10 13:58 ` tomas
2009-12-11 10:33 ` until-found Andreas Röhler
0 siblings, 1 reply; 5+ messages in thread
From: tomas @ 2009-12-10 13:58 UTC (permalink / raw)
To: Andreas Roehler; +Cc: help-gnu-emacs
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Thu, Dec 10, 2009 at 01:50:01PM +0100, Andreas Roehler wrote:
>
> Hi,
>
> given a list or a list of lists:
> list shall be returned, if it contains a certain member.
>
> I'm pretty sure a general form exists, but ignore it.
[...]
> (defun until-found (search-string liste)
> (let ((liste liste) element)
> (while liste
> (if (member search-string (car liste))
> (setq element (car liste) liste nil))
> (setq liste (cdr liste)))
> element))
>
Have a look at assoc -- it might be what you are looking for.
If you need more flexibility, cl's assoc* (where you can specify, among
other things, the comparison function) might fit your bill.
Regards
- -- tomás
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFLIP5rBcgs9XrR2kYRAjsjAJwNovO3/6lB59xeqk6ueXZ+JfA4zQCfX0Xm
4UhpD99BTnp9HIZcVqDb97s=
=+rTv
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: until-found
2009-12-10 13:58 ` until-found tomas
@ 2009-12-11 10:33 ` Andreas Röhler
0 siblings, 0 replies; 5+ messages in thread
From: Andreas Röhler @ 2009-12-11 10:33 UTC (permalink / raw)
To: tomas; +Cc: help-gnu-emacs
tomas@tuxteam.de wrote:
> On Thu, Dec 10, 2009 at 01:50:01PM +0100, Andreas Roehler wrote:
>> Hi,
>
>> given a list or a list of lists:
>> list shall be returned, if it contains a certain member.
>
>> I'm pretty sure a general form exists, but ignore it.
>
> [...]
>
>> (defun until-found (search-string liste)
>> (let ((liste liste) element)
>> (while liste
>> (if (member search-string (car liste))
>> (setq element (car liste) liste nil))
>> (setq liste (cdr liste)))
>> element))
>
>
> Have a look at assoc -- it might be what you are looking for.
>
> If you need more flexibility, cl's assoc* (where you can specify, among
> other things, the comparison function) might fit your bill.
>
> Regards
> -- tomás
Hi Tomas,
assoc tells, it compares some key and the car of a list:
"Return non-nil if KEY is `equal' to the car of an element of LIST."
Its related, but slightly different IMO.
The form I'm looking for returns list, if an element is member of - equality
of whole list returned by car is not at stake.
Thanks anyway
Andreas
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: until-found
[not found] <mailman.12661.1260449426.2239.help-gnu-emacs@gnu.org>
@ 2009-12-11 16:10 ` Helmut Eller
2009-12-11 17:35 ` until-found Andreas Röhler
0 siblings, 1 reply; 5+ messages in thread
From: Helmut Eller @ 2009-12-11 16:10 UTC (permalink / raw)
To: help-gnu-emacs
* Andreas Roehler [2009-12-10 13:50+0100] writes:
> And here my implementation so far:
>
> (defun until-found (search-string liste)
> (let ((liste liste) element)
> (while liste
> (if (member search-string (car liste))
> (setq element (car liste) liste nil))
> (setq liste (cdr liste)))
> element))
This seems to be the same as:
(car (member (lambda (element) (member search-string element)) liste))
or
(find-if (lambda (element) (member search-string element)) liste)
or
(find search-string liste :test #'member)
or
(loop for e in liste if (member search-string e) return e)
Helmut
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: until-found
2009-12-11 16:10 ` until-found Helmut Eller
@ 2009-12-11 17:35 ` Andreas Röhler
0 siblings, 0 replies; 5+ messages in thread
From: Andreas Röhler @ 2009-12-11 17:35 UTC (permalink / raw)
To: Helmut Eller; +Cc: help-gnu-emacs
Helmut Eller wrote:
> * Andreas Roehler [2009-12-10 13:50+0100] writes:
>
>> And here my implementation so far:
>>
>> (defun until-found (search-string liste)
>> (let ((liste liste) element)
>> (while liste
>> (if (member search-string (car liste))
>> (setq element (car liste) liste nil))
>> (setq liste (cdr liste)))
>> element))
>
> This seems to be the same as:
>
> (car (member (lambda (element) (member search-string element)) liste))
>
> or
>
> (find-if (lambda (element) (member search-string element)) liste)
>
> or
>
> (find search-string liste :test #'member)
>
> or
>
> (loop for e in liste if (member search-string e) return e)
>
> Helmut
>
Ah, fine stuff, thanks a lot!
Andreas
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-12-11 17:35 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-10 12:50 until-found Andreas Roehler
2009-12-10 13:58 ` until-found tomas
2009-12-11 10:33 ` until-found Andreas Röhler
[not found] <mailman.12661.1260449426.2239.help-gnu-emacs@gnu.org>
2009-12-11 16:10 ` until-found Helmut Eller
2009-12-11 17:35 ` until-found Andreas Röhler
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).