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

Help: I can't find a simple CL function/idiom

2 views
Skip to first unread message

Michael Naunton

unread,
Apr 8, 2002, 7:44:27 PM4/8/02
to
I want to write something like

(apply #'or alist)

but of course #'or is a macro. I wound up writing

(some (lambda (e) e) alist)

but that seems a bit strained. I've played "guess the word" in the
HyperSpec, but can't find the idiom I want.

Any help would be appreciated,
Thanks,
Michael Naunton

Dr. Edmund Weitz

unread,
Apr 8, 2002, 7:50:29 PM4/8/02
to
m...@bellatlantic.net (Michael Naunton) writes:

> I want to write something like
>
> (apply #'or alist)
>
> but of course #'or is a macro. I wound up writing
>
> (some (lambda (e) e) alist)
>
> but that seems a bit strained. I've played "guess the word" in the
> HyperSpec, but can't find the idiom I want.

Maybe (find-if-not #'null alist).

--

Dr. Edmund Weitz
Hamburg
Germany

The Common Lisp Cookbook
<http://cl-cookbook.sourceforge.net/>

Erik Naggum

unread,
Apr 8, 2002, 7:59:48 PM4/8/02
to
* Michael Naunton

| I wound up writing
|
| (some (lambda (e) e) alist)
|
| but that seems a bit strained.

The function identity is predefined.

| I've played "guess the word" in the HyperSpec, but can't find the idiom I
| want.

For a single list of arguments, some may or may not be misleading.

(find-if #'identity list)
(find-if-not #'null list)

Note that the name "alist" connotes association lists, for which this
operation makes little sense.

///
--
In a fight against something, the fight has value, victory has none.
In a fight for something, the fight is a loss, victory merely relief.

Post with compassion: http://home.chello.no/~xyzzy/kitten.jpg

Tim Moore

unread,
Apr 8, 2002, 8:05:17 PM4/8/02
to
On Mon, 08 Apr 2002 23:44:27 GMT, Michael Naunton <m...@bellatlantic.net> wrote:
>I want to write something like
>
>(apply #'or alist)
>
>but of course #'or is a macro. I wound up writing
>
>(some (lambda (e) e) alist)
>
>but that seems a bit strained. I've played "guess the word" in the
>HyperSpec, but can't find the idiom I want.

You could do (some #'identity alist).

You should avoid using apply for these kinds of idioms because you can
run into the call arguments limit fairly quickly.

Tim

Joe Marshall

unread,
Apr 8, 2002, 7:56:28 PM4/8/02
to

"Michael Naunton" <m...@bellatlantic.net> wrote in message
news:slrnab4bq...@mmn.bellatlantic.net...

> I want to write something like
>
> (apply #'or alist)
>
> but of course #'or is a macro. I wound up writing
>
> (some (lambda (e) e) alist)
>
> but that seems a bit strained. I've played "guess the word" in the
> HyperSpec, but can't find the idiom I want.

(some #'identity alist)
(find-if #'identity alist)

Still kinda odd looking.


Kent M Pitman

unread,
Apr 8, 2002, 8:16:45 PM4/8/02
to
m...@bellatlantic.net (Michael Naunton) writes:

> I want to write something like
>
> (apply #'or alist)

For all but the most pathological alists (i.e., association lists),
FIRST will usually do the trick here. :-)

Maybe you meant (apply #'or list).

> but of course #'or is a macro. I wound up writing
>
> (some (lambda (e) e) alist)
>
> but that seems a bit strained. I've played "guess the word" in the
> HyperSpec, but can't find the idiom I want.

What's it called in other languages?

Lisp has a half dozen ultra trivial ways of saying this, which for as
often as it seems to come up seems more than adequate.

(loop for x in list thereis x)

(find-if-not #'null x) ;or #'not

(find-if #'identity x)

(some #'identity x)

(eval `(or ,@(mapcar #'(lambda (x) `',x) list)))

...


In the rare situation that I've had a system where this is common, I
have usually written a *OR or *AND function.

It's unfair to take an arbitrary action and complain that you have to
play "guess the word" when the thing you want to do is not even expressable
in most other languages. The reason it's called a programming language
is that sometimes you have to program.

ozan s yigit

unread,
Apr 9, 2002, 3:41:29 PM4/9/02
to
Kent M Pitman:
...

> It's unfair to take an arbitrary action and complain that you have to
> play "guess the word" when the thing you want to do is not even expressable
> in most other languages.

um, don't tempt the perl hackers who may be listening in. if there is some
part of common lisp perl programmers want but don't yet have, it will show
up in a perl6 rfc soon. :) [obhref: http://dev.perl.org/rfc/]

oz
--
you take a banana, you get a lunar landscape. -- j. van wijk

Marco Antoniotti

unread,
Apr 9, 2002, 4:26:45 PM4/9/02
to

ozan s yigit <o...@blue.cs.yorku.ca> writes:

> Kent M Pitman:
> ...
> > It's unfair to take an arbitrary action and complain that you have to
> > play "guess the word" when the thing you want to do is not even expressable
> > in most other languages.
>
> um, don't tempt the perl hackers who may be listening in. if there is some
> part of common lisp perl programmers want but don't yet have, it will show
> up in a perl6 rfc soon. :) [obhref: http://dev.perl.org/rfc/]

As it did in a Scheme SRFI a few years ago :)

Cheers

--
Marco Antoniotti ========================================================
NYU Courant Bioinformatics Group tel. +1 - 212 - 998 3488
719 Broadway 12th Floor fax +1 - 212 - 995 4122
New York, NY 10003, USA http://bioinformatics.cat.nyu.edu
"Hello New York! We'll do what we can!"
Bill Murray in `Ghostbusters'.

Reini Urban

unread,
Apr 9, 2002, 4:37:59 PM4/9/02
to
ozan s yigit wrote:
>Kent M Pitman:

>> It's unfair to take an arbitrary action and complain that you have to
>> play "guess the word" when the thing you want to do is not even expressable
>> in most other languages.
>
>um, don't tempt the perl hackers who may be listening in. if there is some
>part of common lisp perl programmers want but don't yet have, it will show
>up in a perl6 rfc soon. :) [obhref: http://dev.perl.org/rfc/]

yes, but we don't care.
they haven't even got the underlying basics (such as types) but want
catchy idioms. only perl hackers are proud of this post-modern
our-parser-understands-every-shit aeh we-do-it-all thing.

for looking up common lisp idioms and perl programmers there's the
cl-cookbook project: http://cl-cookbook.sf.net/
--
Reini Urban
http://xarch.tu-graz.ac.at/home/rurban/film/

Michael Naunton

unread,
Apr 9, 2002, 8:33:45 PM4/9/02
to
On Tue, 9 Apr 2002 00:16:45 GMT, Kent M Pitman <pit...@world.std.com> wrote:
>m...@bellatlantic.net (Michael Naunton) writes:
>
>> I want to write something like
>>
>> (apply #'or alist)
>
>For all but the most pathological alists (i.e., association lists),
>FIRST will usually do the trick here. :-)
>

Thank you, after reading previous posts on the topic of naming, I will
henceforth call a list a list.

<snip>

>In the rare situation that I've had a system where this is common, I
>have usually written a *OR or *AND function.

>It's unfair to take an arbitrary action and complain that you have to
>play "guess the word" when the thing you want to do is not even expressable
>in most other languages. The reason it's called a programming language
>is that sometimes you have to program.

But, every other arbitrary action I've wanted to take has had a terse or
idiomatic expression in Common Lisp :)

Thanks to all for your help,
-- MMN

Paolo Amoroso

unread,
Apr 10, 2002, 5:28:59 AM4/10/02
to
On 09 Apr 2002 15:41:29 -0400, ozan s yigit <o...@blue.cs.yorku.ca> wrote:

> um, don't tempt the perl hackers who may be listening in. if there is some
> part of common lisp perl programmers want but don't yet have, it will show
> up in a perl6 rfc soon. :) [obhref: http://dev.perl.org/rfc/]

Hmmm... does this imply that Mr. Wall's opinion on Lisp changed in some
way?


Paolo
--
EncyCMUCLopedia * Extensive collection of CMU Common Lisp documentation
http://www.paoloamoroso.it/ency/README
[http://cvs2.cons.org:8000/cmucl/doc/EncyCMUCLopedia/]

Reini Urban

unread,
Apr 10, 2002, 10:29:44 AM4/10/02
to
Paolo Amoroso wrote:
>On 09 Apr 2002 15:41:29 -0400, ozan s yigit <o...@blue.cs.yorku.ca> wrote:
>> um, don't tempt the perl hackers who may be listening in. if there is some
>> part of common lisp perl programmers want but don't yet have, it will show
>> up in a perl6 rfc soon. :) [obhref: http://dev.perl.org/rfc/]
>
>Hmmm... does this imply that Mr. Wall's opinion on Lisp changed in some
>way?

not him, but all the others around him.

Mark Jason Dominus

unread,
Apr 15, 2002, 3:39:59 AM4/15/02
to
In article <jQG0PHyI+3cOl+...@4ax.com>,

Paolo Amoroso <amo...@mclink.it> wrote:
>On 09 Apr 2002 15:41:29 -0400, ozan s yigit <o...@blue.cs.yorku.ca> wrote:
>
>> um, don't tempt the perl hackers who may be listening in. if there is some
>> part of common lisp perl programmers want but don't yet have, it will show
>> up in a perl6 rfc soon. :) [obhref: http://dev.perl.org/rfc/]
>
>Hmmm... does this imply that Mr. Wall's opinion on Lisp changed in some
>way?

I believe Larry's objection to Lisp has always been entirely on
syntactic grounds.


--
Mark Jason Dominus m...@plover.com
Philadelphia Excursions Mailing List: http://www.plover.com/~mjd/excursions/

Dr. Edmund Weitz

unread,
Apr 15, 2002, 4:08:28 AM4/15/02
to
m...@plover.com (Mark Jason Dominus) writes:

> In article <jQG0PHyI+3cOl+...@4ax.com>,
> Paolo Amoroso <amo...@mclink.it> wrote:
> >On 09 Apr 2002 15:41:29 -0400, ozan s yigit <o...@blue.cs.yorku.ca> wrote:
> >
> >> um, don't tempt the perl hackers who may be listening in. if there is some
> >> part of common lisp perl programmers want but don't yet have, it will show
> >> up in a perl6 rfc soon. :) [obhref: http://dev.perl.org/rfc/]
> >
> >Hmmm... does this imply that Mr. Wall's opinion on Lisp changed in some
> >way?
>
> I believe Larry's objection to Lisp has always been entirely on
> syntactic grounds.

Really? What about this one?

"Lispers are among the best grads of the
Sweep-It-Under-Someone-Else's-Carpet School of Simulated
Simplicity. [Was that sufficiently incendiary? :-)]"

This to me looks as if he's had an overdose of Scheme when he was
younger... :)

Cheers,
Edi.

ozan s yigit

unread,
Apr 15, 2002, 10:45:23 AM4/15/02
to
e...@agharta.de (Dr. Edmund Weitz) writes:

> > I believe Larry's objection to Lisp has always been entirely on
> > syntactic grounds.
>
> Really? What about this one?
>
> "Lispers are among the best grads of the
> Sweep-It-Under-Someone-Else's-Carpet School of Simulated
> Simplicity. [Was that sufficiently incendiary? :-)]"
>

that was a 92 post. CL was not quite what it is today. :)

> This to me looks as if he's had an overdose of Scheme when he was
> younger... :)

i think he only paid attention to scheme after he had already designed
and implemented perl. [btw, an important distinction about him is that he
articulates various linguistic aspects of his language, and why he thinks
it works well for programmers, eg. www.wall.org/~larry/natural.html or
state of the onion addresses. maybe his overdose is something else. :-]

oz
--
*double-sigh*cough*cough* -- eli barzilay

Erik Naggum

unread,
Apr 15, 2002, 12:09:30 PM4/15/02
to
* ozan s yigit <o...@blue.cs.yorku.ca>

| that was a 92 post. CL was not quite what it is today. :)

It is still much more descriptive of people's experiences with Scheme.
Even in 1992, Common Lisp was a real programming language suitable for
production use. It is unlikely that anyone would seriously argue against
Common Lisp at that time as being "simulated simplicity". That fake idea
of "elegance" and "simplicity" has always been something to associated
with Scheme and no other Lisp-lookalike.

| i think he only paid attention to scheme after he had already designed
| and implemented perl. [btw, an important distinction about him is that he
| articulates various linguistic aspects of his language, and why he thinks
| it works well for programmers, eg. www.wall.org/~larry/natural.html or
| state of the onion addresses. maybe his overdose is something else. :-]

I think the Common Lisp designers were years ahead of him, there. The
Scheme folks obviously were not, focusing instead on formal semantics.
It is kind of funny how much Perl has "stolen" from Common Lisp (but not
from Scheme). Both Common Lisp and Perl aim to be practical and useful.

Paolo Amoroso

unread,
Apr 15, 2002, 2:05:46 PM4/15/02
to
On 15 Apr 2002 10:45:23 -0400, ozan s yigit <o...@blue.cs.yorku.ca> wrote:

[about Larry Wall]


> and implemented perl. [btw, an important distinction about him is that he
> articulates various linguistic aspects of his language, and why he thinks
> it works well for programmers, eg. www.wall.org/~larry/natural.html or

Anybody can easily create a software system that is a mess, and then
justify it by claiming that he purposely designed it that way in order to
mimic real life, which is well known to be a mess :)

0 new messages