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

predicate?

12 views
Skip to first unread message

Johannes Grødem

unread,
Dec 17, 2001, 12:51:58 PM12/17/01
to
I was wondering if there is some reason that "?" as a postfix for
predicate function-names isn't used more. (I've seen it in some
Graham-books, but not really anywhere else.) Is it simply tradition?
Perhaps you couldn't use "?" in symbols in some ancient dialect, and
then it just stuck?

Also, I'm not quite able to figure out why some function names end in
"-p" and some only "p" (without the hyphen). Is it random, or is it
only me that is unable to see the system?

(Yes, I know these questions aren't particularly interesting, but I'm
still curious.)

--
johs

Michael Hudson

unread,
Dec 17, 2001, 1:08:47 PM12/17/01
to
"Johannes Grødem" <s...@kopkillah.com> writes:

> I was wondering if there is some reason that "?" as a postfix for
> predicate function-names isn't used more. (I've seen it in some
> Graham-books, but not really anywhere else.) Is it simply
> tradition? Perhaps you couldn't use "?" in symbols in some ancient
> dialect, and then it just stuck?

I was under the impression that the ?-suffix was more a scheme thing
than a CL thing.

> Also, I'm not quite able to figure out why some function names end in
> "-p" and some only "p" (without the hyphen). Is it random, or is it
> only me that is unable to see the system?

This one is explained in CLTL2 at the beginning of chapter 6,
"Predicates". It seems you can find this here:

http://www.cs.utsa.edu/research/AI/cltl/clm/node69.html

HTH,
M.

--
31. Simplicity does not precede complexity, but follows it.
-- Alan Perlis, http://www.cs.yale.edu/homes/perlis-alan/quotes.html

Kent M Pitman

unread,
Dec 17, 2001, 2:04:31 PM12/17/01
to
"Johannes =?iso-8859-15?q?Gr=F8dem?=" <s...@kopkillah.com> writes:

> I was wondering if there is some reason that "?" as a postfix for
> predicate function-names isn't used more.

Tradition. And then, as a secondary effect given some traditions are
fixed from the start, consistency is also at play.

And the fact that a lot of people used it for a readmacro character,
especially in pattern matchers. ?FOO and all that. If you have it
as a readmacro, you have to write foo\? or else you have to use the
feature of CL which allows you to have "non-breaking readmacros". But
I sense a lot of people either don't know about "non-breaking readmacros"
or don't really trust them or don't find them conceptually natural, because
the only uses I've ever seen of these is "#", which I think was put in
so the lispm primitive array-#-dimensions wouldn't require \'ing, and even
that has drifted out of vogue. Statistically, for whatever reason, it
seems to me that most people prefer readmacros, if they have them at all,
to cause breaks.

Maybe this is also because they, like me, sometimes omit spaces in
interactive cases they would never do in filed code. I write things like
(print'foo)
and expect the break. I'd be really irritated if this was treated as
(print\'foo)
and not as
(print 'foo).

> (I've seen it in some
> Graham-books, but not really anywhere else.) Is it simply tradition?
> Perhaps you couldn't use "?" in symbols in some ancient dialect, and
> then it just stuck?

All of the above said, I personally use ? a lot, perhaps because I don't
like ? as a readmacro character. I encourage people to pronounce it "pee"
so that "foo?" is pronounced "foo-pee" just like "foop", both for audio
compatibility with older conventions, and because the slight raise in tonal
quality in English for questions is just too subtle to carry it.

> Also, I'm not quite able to figure out why some function names end in
> "-p" and some only "p" (without the hyphen). Is it random, or is it
> only me that is unable to see the system?

"p" when the concept you want is not hyphenated, I think. fixnum isn't
hyphenated, so fixnump isn't. alpha-char is hyphenated, so alpha-char-p.
If you did alpha-charp, you'd be asking for something with the morphemic
structure "alpha" + ( "char" + "p" ) not "alpha-char" + "p".

But I vaguely recall that defstruct violates all of this, making the
convention useless. Just do what seems reasonable and don't obsess.
(Kind of reminds me of the rule for rotaries (the UK calls these "roundabouts")
on the road that i was taught by a friend when learning to drive. the
actual rules are well-defined but commonly ignored, at least in the US, so
one learns the "don't hit anyone rule" to paper over the fact that theory
never seems to match practice...)

Or use "?"

> (Yes, I know these questions aren't particularly interesting, but I'm
> still curious.)

I think these are very important questions because I think it's a
critical artifact of langauge that we be able to pronounce it. Much
important debugging is done over the phone and over dinner. whether you
do "foo-bar" or "FooBar" for naming, it's critical you just say "foo bar"
out loud and not "foo hyphen bar" nor "cap foo cap bar". Likewise it's
critical you have a clear convention for saying predicates outloud that
doesn't force you to spell them.

I don't think it matters that these things be standard, because it
could lead to a potentially endless debate you are probably alluding
to. but within a local community or a large module of code, internal
consistency helps a great deal.

Johannes Grødem

unread,
Dec 17, 2001, 3:50:13 PM12/17/01
to
* Michael Hudson <m...@python.net>:

> I was under the impression that the ?-suffix was more a scheme thing
> than a CL thing.

Well, yes, that is my impression as well, but I don't consider it a
good reason to avoid it.

> This one is explained in CLTL2 at the beginning of chapter 6,
> "Predicates". It seems you can find this here:

Ah, thanks a lot.

--
johs

Johannes Grødem

unread,
Dec 17, 2001, 4:04:09 PM12/17/01
to
* Kent M Pitman <pit...@world.std.com>:

> But I vaguely recall that defstruct violates all of this, making the
> convention useless. Just do what seems reasonable and don't obsess.

Yeah, I'll give it a try. (Although it feels really good to have this
explained. :)

> (Kind of reminds me of the rule for rotaries (the UK calls these
> "roundabouts") on the road that i was taught by a friend when
> learning to drive. the actual rules are well-defined but commonly
> ignored, at least in the US, so one learns the "don't hit anyone
> rule" to paper over the fact that theory never seems to match
> practice...)

It's the same in Norway. The rules are well-defined, but noone
understands them (especially people from Bergen, or so I'm told),
or haven't bothered to learn them, so they just go by the
avoid-hitting-people-rule here as well.

--
johs

Matt Curtin

unread,
Dec 17, 2001, 4:35:56 PM12/17/01
to
>>>>> "Johs" == Johannes Grødem <s...@kopkillah.com> writes:

Johs> I was wondering if there is some reason that "?" as a postfix
Johs> for predicate function-names isn't used more.

Basically, it's just a question of convention. We use the -P
convention. Switching to a ? isn't really a win, and it does come
with some cost: code consistency, so there really isn't any point.

Johs> Also, I'm not quite able to figure out why some function names
Johs> end in "-p" and some only "p" (without the hyphen). Is it
Johs> random, or is it only me that is unable to see the system?

Well, if you are looking for a general rule of thumb, the best one
would probably be that if you're dealing with a symbol of a single
word, the addition of "p" would be all that's needed for the
predicate, but that if you're dealing with a symbole with hyphens in
them, "-p" would be used.

Thus, we have STRINGP and SIMPLE-STRING-P.

There are exceptions, of course. The rule of thumb I've offered is
based on simple observation: which we seem to choose when making new
functions, rather than on some agreed-upon convention that dictates
when to use one or the other.

--
Matt Curtin, Founder Interhack Corporation http://web.interhack.com/
My new book, "Developing Trust: Online Privacy and Security," is now
available. See site for details. research | development | consulting

Steve Long

unread,
Dec 17, 2001, 8:35:03 PM12/17/01
to
A tradition based on filenaming conventions also applies. In the
one-thing-per-file mode, one typically names the file after the thing.
Since you can't give a file a name containing "?" in Unix, a predicate
function substitutes "p" or "-p" for "?".

Kaz Kylheku

unread,
Dec 17, 2001, 9:36:44 PM12/17/01
to
In article <3C1E9D46...@isomedia.com>, Steve Long wrote:
>A tradition based on filenaming conventions also applies. In the
>one-thing-per-file mode, one typically names the file after the thing.
>Since you can't give a file a name containing "?" in Unix, a predicate
>function substitutes "p" or "-p" for "?".

That is false; the only two characters you cannot have are / and the
null character. One is treated by the kernel as a path separator, the
other as a string terminator.

It's only the shell that treats ? as a metacharacter, meaning that you
have to quote or escape it when specifying the filename in that language.

Paul Foley

unread,
Dec 17, 2001, 9:51:25 PM12/17/01
to
On Mon, 17 Dec 2001 17:35:03 -0800, Steve Long wrote:

> A tradition based on filenaming conventions also applies. In the
> one-thing-per-file mode, one typically names the file after the thing.
> Since you can't give a file a name containing "?" in Unix, a predicate
> function substitutes "p" or "-p" for "?".

You certainly can give a file a name containing "?" in Unix. Unix
filenames can contain any character except "/" and NUL. But the "P"
convention predates and has nothing to do with Unix (or any other OS's
filenames...why would you want to name files after predicates anyway?)

[I find `?'s in predicate names very disconcerting...]

--
Cogito ergo I'm right and you're wrong. -- Blair Houghton

(setq reply-to
(concatenate 'string "Paul Foley " "<mycroft" '(#\@) "actrix.gen.nz>"))

Christopher Stacy

unread,
Dec 18, 2001, 1:39:12 AM12/18/01
to
>>>>> On Mon, 17 Dec 2001 17:35:03 -0800, Steve Long ("Steve") writes:
Steve> A tradition based on filenaming conventions also applies.

The Lisp "P" convention predates those file systems by decades, though.

Thomas F. Burdick

unread,
Dec 18, 2001, 2:27:04 AM12/18/01
to
Kent M Pitman <pit...@world.std.com> writes:

> All of the above said, I personally use ? a lot, perhaps because I don't
> like ? as a readmacro character. I encourage people to pronounce it "pee"
> so that "foo?" is pronounced "foo-pee" just like "foop", both for audio
> compatibility with older conventions, and because the slight raise in tonal
> quality in English for questions is just too subtle to carry it.

I tend to use the ? suffix (with random aesthetic exceptions), and
although I read it either as a raised tone, or as "pee", when I say it
aloud, I'll also pronounce it "kwuh" so that other people will get the
right symbol. I suppose this wouldn't be necessary if I were fully
consistent with it, but oh well.

I also like the ! suffix for destructive operators, because if I type
"foo<TAB>", I'll see foo and foo!, but not nfoo. Luckily, I can
pronounce it "bang".

> (Kind of reminds me of the rule for rotaries (the UK calls these
> "roundabouts") on the road that i was taught by a friend when
> learning to drive. the actual rules are well-defined but commonly
> ignored, at least in the US, so one learns the "don't hit anyone
> rule" to paper over the fact that theory never seems to match
> practice...)

Hmm, where I live in Northern California, we call the roundabouts and
no one seems to follow any rules, least of all "don't hit anyone". Or
at least at the one a block away from where I live.

--
/|_ .-----------------------.
,' .\ / | No to Imperialist war |
,--' _,' | Wage class war! |
/ / `-----------------------'
( -. |
| ) |
(`-. '--.)
`. )----'

Steve Long

unread,
Dec 20, 2001, 2:47:55 AM12/20/01
to

Kaz Kylheku wrote:

> It's only the shell that treats ? as a metacharacter, meaning that you
> have to quote or escape it when specifying the filename in that language.

Then that makes ? a pretty silly char to use in a filename, doesn't it?

Raymond Wiker

unread,
Dec 20, 2001, 2:45:56 AM12/20/01
to
Steve Long <ac...@isomedia.com> writes:

Only as long as you need to refer the file in a shell. For
that matter, the (Unix) shells do not work too well with whitespace
characters either, but that doesn't seem to stop people from using
them in file and directory names.

--
Raymond Wiker Mail: Raymon...@fast.no
Senior Software Engineer Web: http://www.fast.no/
Fast Search & Transfer ASA Phone: +47 23 01 11 60
P.O. Box 1677 Vika Fax: +47 35 54 87 99
NO-0120 Oslo, NORWAY Mob: +47 48 01 11 60

Try FAST Search: http://alltheweb.com/

Thomas F. Burdick

unread,
Dec 20, 2001, 3:39:07 AM12/20/01
to
Raymond Wiker <Raymon...@fast.no> writes:

> Steve Long <ac...@isomedia.com> writes:
>
> > Kaz Kylheku wrote:
> >
> > > It's only the shell that treats ? as a metacharacter, meaning that you
> > > have to quote or escape it when specifying the filename in that language.
> >
> > Then that makes ? a pretty silly char to use in a filename, doesn't it?
>
> Only as long as you need to refer the file in a shell. For
> that matter, the (Unix) shells do not work too well with whitespace
> characters either, but that doesn't seem to stop people from using
> them in file and directory names.

Bah, all you need is a shell with good tab completion, and you never
have to escape things yourself.

Raymond Wiker

unread,
Dec 20, 2001, 4:24:34 AM12/20/01
to
t...@conquest.OCF.Berkeley.EDU (Thomas F. Burdick) writes:

> Raymond Wiker <Raymon...@fast.no> writes:
>
> > Steve Long <ac...@isomedia.com> writes:
> >
> > > Kaz Kylheku wrote:
> > >
> > > > It's only the shell that treats ? as a metacharacter, meaning that you
> > > > have to quote or escape it when specifying the filename in that language.
> > >
> > > Then that makes ? a pretty silly char to use in a filename, doesn't it?
> >
> > Only as long as you need to refer the file in a shell. For
> > that matter, the (Unix) shells do not work too well with whitespace
> > characters either, but that doesn't seem to stop people from using
> > them in file and directory names.
>
> Bah, all you need is a shell with good tab completion, and you never
> have to escape things yourself.

Doesn't help much for shell scripts...

Erik Naggum

unread,
Dec 20, 2001, 8:49:12 AM12/20/01
to
* Raymond Wiker <Raymon...@fast.no>

| Doesn't help much for shell scripts...

Shell scripts that do not quote the arguments they received from the
parent shell to protect themselves against all kinds of bogus noise in
them, have much bigger problems than not finding files with whitespace in
them. Unfortunately, incompetence at the Microsoft level is rampant
among people who think it is possible to prove that a script "works" by
testing it once under benign conditions.

There is absolutely _no_ need to use the arguments in a shell script in
a way that causes them to be re-processed by the filename expansion,
variable interpolation, etc, etc. A reasonably intelligent shell would
turn these things off in shell scripts and only allow them in interactive
shells or in special function calls that return _lists_ of filenames.

///
--
The past is not more important than the future, despite what your culture
has taught you. Your future observations, conclusions, and beliefs are
more important to you than those in your past ever will be. The world is
changing so fast the balance between the past and the future has shifted.

Kaz Kylheku

unread,
Dec 20, 2001, 1:39:54 PM12/20/01
to
In article <868zbyk...@raw.grenland.fast.no>, Raymond Wiker wrote:
>t...@conquest.OCF.Berkeley.EDU (Thomas F. Burdick) writes:
>
>> Raymond Wiker <Raymon...@fast.no> writes:
>>
>> > Steve Long <ac...@isomedia.com> writes:
>> >
>> > > Kaz Kylheku wrote:
>> > >
>> > > > It's only the shell that treats ? as a metacharacter, meaning that you
>> > > > have to quote or escape it when specifying the filename in that language.
>> > >
>> > > Then that makes ? a pretty silly char to use in a filename, doesn't it?
>> >
>> > Only as long as you need to refer the file in a shell. For
>> > that matter, the (Unix) shells do not work too well with whitespace
>> > characters either, but that doesn't seem to stop people from using
>> > them in file and directory names.
>>
>> Bah, all you need is a shell with good tab completion, and you never
>> have to escape things yourself.
>
> Doesn't help much for shell scripts...

Shell scripts should be written robustly, so that they can deal with
any filename that the operating system deems correct.

The foo? name is unlikely to appear as a literal token in a shell script.
If it does, it will have to be properly quoted.

More likely, foo? will come into the shell script as a command line
argument, or as a result of regular expression expansion within that
script.

These sources of input must be properly handled, unless you are writing
a throwaway script for your personal use. For example:

# loop over arguments
for x in "$@" ; do someting with "$x"; done

rather than

for x in $* ; do something with $x ; done

Special care has to be taken that a name resembling a command
line switch doesn't get misinterpreted as one:

mv -- "$file1" "$file2"

When you are writing a script, your personal opinion about what
constitutes a canonical filename no longer applies! You are on the
accepting side of the fence, rather than the generating side.

Incidentally, one time I dared report to the comp.unix.shell newsgroup
that the examples in its FAQ were not robust against filenames containing
spaces and metacharacters. I was flamed by people saying what kind of
idiot would name the files that way? I couldn't believe the attitude.

0 new messages