unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* canonical name  ending "-p"
@ 2011-03-18 17:39 ken
  2011-03-18 18:11 ` Allan Gottlieb
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: ken @ 2011-03-18 17:39 UTC (permalink / raw)
  To: GNU Emacs List

Lots of things in elisp end in "-p"... is there some particular meaning
in this?

-- 
Anything is easy if you know how to do it.



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

* Re: canonical name  ending "-p"
       [not found] <mailman.8.1300470004.7441.help-gnu-emacs@gnu.org>
@ 2011-03-18 17:56 ` Pascal J. Bourguignon
  2011-03-18 20:36 ` Evans Winner
  1 sibling, 0 replies; 10+ messages in thread
From: Pascal J. Bourguignon @ 2011-03-18 17:56 UTC (permalink / raw)
  To: help-gnu-emacs

ken <gebser@mousecar.com> writes:

> Lots of things in elisp end in "-p"... is there some particular meaning
> in this?

They are predicates.  Predicates are functions that usually take a
single argument, and return a boolean attribute of this argument.

In some cases, it may be a generalized boolean, with an interesting
value for true.

For example, (digit-char-p ?9) --> 9 which is true, but more
interesting, since it's also the numeric value of the digit character.


Notice also, as this example shows, that some classical predicates don't
have the p or -p suffix.  For example: atom

   (atom x) == (not (consp x))



A single word predicate would end with p, a multiword one with -p:

   integerp
   upper-case-p 


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
A bad day in () is better than a good day in {}.


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

* Re: canonical name  ending "-p"
  2011-03-18 17:39 canonical name ending "-p" ken
@ 2011-03-18 18:11 ` Allan Gottlieb
  2011-03-18 18:18 ` Perry Smith
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 10+ messages in thread
From: Allan Gottlieb @ 2011-03-18 18:11 UTC (permalink / raw)
  To: gebser; +Cc: GNU Emacs List

From: ken <gebser@mousecar.com>
Date: Friday, March 18, 2011 1:39 pm

> Lots of things in elisp end in "-p"... is there some particular meaning
>  in this?

Yes.  I believe it stands for "predicate".  It is a boolean.  So active-p
would be true if the item in question was "active".

allan
  



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

* Re: canonical name  ending "-p"
  2011-03-18 17:39 canonical name ending "-p" ken
  2011-03-18 18:11 ` Allan Gottlieb
@ 2011-03-18 18:18 ` Perry Smith
  2011-03-18 18:31   ` Drew Adams
  2011-03-18 18:20 ` Tom Rauchenwald
       [not found] ` <mailman.12.1300472466.7441.help-gnu-emacs@gnu.org>
  3 siblings, 1 reply; 10+ messages in thread
From: Perry Smith @ 2011-03-18 18:18 UTC (permalink / raw)
  To: gebser; +Cc: GNU Emacs List


On Mar 18, 2011, at 12:39 PM, ken wrote:

> Lots of things in elisp end in "-p"... is there some particular meaning
> in this?

I was told it means "predicate" long ago by the guy who introduced me to lisp and emacs.  In Ruby, they use a '?' so they have 'blank?' -- but '?' isn't a legal character in a symbol so they append "p" for predicate.

I'm curious if I have this right or not...

pedz





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

* Re: canonical name  ending "-p"
  2011-03-18 17:39 canonical name ending "-p" ken
  2011-03-18 18:11 ` Allan Gottlieb
  2011-03-18 18:18 ` Perry Smith
@ 2011-03-18 18:20 ` Tom Rauchenwald
  2011-03-18 18:31   ` Drew Adams
       [not found] ` <mailman.12.1300472466.7441.help-gnu-emacs@gnu.org>
  3 siblings, 1 reply; 10+ messages in thread
From: Tom Rauchenwald @ 2011-03-18 18:20 UTC (permalink / raw)
  To: help-gnu-emacs

ken <gebser@mousecar.com> writes:

> Lots of things in elisp end in "-p"... is there some particular meaning
> in this?

It means predicate. Functions ending in -p return either t or nil, and
variables ending in -p contain either t or nil.

-tom

-- 
Computers are useless.  They can only give you answers.
                -- Pablo Picasso




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

* RE: canonical name  ending "-p"
  2011-03-18 18:18 ` Perry Smith
@ 2011-03-18 18:31   ` Drew Adams
  0 siblings, 0 replies; 10+ messages in thread
From: Drew Adams @ 2011-03-18 18:31 UTC (permalink / raw)
  To: 'Perry Smith', gebser; +Cc: 'GNU Emacs List'

> > Lots of things in elisp end in "-p"... is there some 
> > particular meaning in this?
> 
> I was told it means "predicate" long ago by the guy who 
> introduced me to lisp and emacs.

Yes.  It is an old Lisp idiom, not just Emacs Lisp.

> In Ruby, they use a '?' so they have 'blank?'
> -- but '?' isn't a legal character in a 
> symbol so they append "p" for predicate.

This part is incorrect.  `?' is perfectly legal in a Lisp symbol.
Put your cursor on a `?' char in Emacs Lisp mode and do `C-u C-x ='.  You will
see this: "syntax: _    which means: symbol".  Then try it:

(defun foo? () (forward-char 1))

[Unfortunately, vanilla Emacs completion treats `?' specially, so you'll need to
quote it using `C-q ?' if you want to use `C-h f' to get help on `foo?': `C-h
foo C-q ?']

> I'm curious if I have this right or not...

Yes, except for `?'.




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

* RE: canonical name  ending "-p"
  2011-03-18 18:20 ` Tom Rauchenwald
@ 2011-03-18 18:31   ` Drew Adams
  0 siblings, 0 replies; 10+ messages in thread
From: Drew Adams @ 2011-03-18 18:31 UTC (permalink / raw)
  To: 'Tom Rauchenwald', help-gnu-emacs

> It means predicate. Functions ending in -p return either t
> or nil, and variables ending in -p contain either t or nil.

Actually, either non-nil (true) or nil (false).

"Boolean" in Lisp can mean this or it can mean strictly `t' or `nil'.
Generally, any non-nil value is taken to mean true, but for `defcustom' the
:type `boolean' limits the value to t or nil.

Also, most people do _not_ use `-p' when naming a boolean variable.  I use it
that way quite often, but some Emacs developers frown on this use.

For user options, some people (including me) use the suffix `-flag' for a
boolean option.  I tend to use `-p' for internal variables (non-options).




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

* Re: canonical name  ending "-p"
       [not found] <mailman.8.1300470004.7441.help-gnu-emacs@gnu.org>
  2011-03-18 17:56 ` Pascal J. Bourguignon
@ 2011-03-18 20:36 ` Evans Winner
  2011-03-19  4:32   ` rusi
  1 sibling, 1 reply; 10+ messages in thread
From: Evans Winner @ 2011-03-18 20:36 UTC (permalink / raw)
  To: help-gnu-emacs

,------ ken wrote ------
|    Lots of things in elisp end in "-p"... is there some
|    particular meaning in this?

On a related note (since Pascal already explained it) I have
wondered why the rather odd use of the term "predicate" was
chosen.

When I hear the term "predicate" I usually think of its
meaning in grammar and logic.  But there is also the use in
which one says that if one thing (A) depends on another
thing (B) that A is "predicated on B."  I suspect it is
because one might verbally reason that in:

   (if (atom t) t nil)

the answer to whether Lisp will return t or nil is
predicated on the results of (atom t), therefore by
extension we call the function itself a predicate.  It's a
little confusing because it is not one of the common uses of
the noun "predicate."  I would be interested to hear from
someone who knows if this is indeed the sense on which the
term was chosen.


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

* Re: canonical name  ending "-p"
       [not found] ` <mailman.12.1300472466.7441.help-gnu-emacs@gnu.org>
@ 2011-03-19  1:52   ` Stefan Monnier
  0 siblings, 0 replies; 10+ messages in thread
From: Stefan Monnier @ 2011-03-19  1:52 UTC (permalink / raw)
  To: help-gnu-emacs

> It means predicate. Functions ending in -p return either t or nil, and
> variables ending in -p contain either t or nil.

Actually the use for variables is discouraged.  Among other things these
aren't "predicates" in the mathematical logic sense.


        Stefan "Who'd be happy to use ? instead, like in Scheme"


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

* Re: canonical name ending "-p"
  2011-03-18 20:36 ` Evans Winner
@ 2011-03-19  4:32   ` rusi
  0 siblings, 0 replies; 10+ messages in thread
From: rusi @ 2011-03-19  4:32 UTC (permalink / raw)
  To: help-gnu-emacs

On Mar 19, 1:36 am, Evans Winner <ego...@gmail.com> wrote:
> ,------ ken wrote ------
> |    Lots of things in elisp end in "-p"... is there some
> |    particular meaning in this?
>
> On a related note (since Pascal already explained it) I have
> wondered why the rather odd use of the term "predicate" was
> chosen.
>
> When I hear the term "predicate" I usually think of its
> meaning in grammar and logic.  But there is also the use in
> which one says that if one thing (A) depends on another
> thing (B) that A is "predicated on B."  I suspect it is
> because one might verbally reason that in:
>
>    (if (atom t) t nil)
>
> the answer to whether Lisp will return t or nil is
> predicated on the results of (atom t), therefore by
> extension we call the function itself a predicate.  It's a
> little confusing because it is not one of the common uses of
> the noun "predicate."  I would be interested to hear from
> someone who knows if this is indeed the sense on which the
> term was chosen.

Maybe you are assuming the grammar use and not the logic use?
See disambiguating wikipedia page http://en.wikipedia.org/wiki/Predicate


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

end of thread, other threads:[~2011-03-19  4:32 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-18 17:39 canonical name ending "-p" ken
2011-03-18 18:11 ` Allan Gottlieb
2011-03-18 18:18 ` Perry Smith
2011-03-18 18:31   ` Drew Adams
2011-03-18 18:20 ` Tom Rauchenwald
2011-03-18 18:31   ` Drew Adams
     [not found] ` <mailman.12.1300472466.7441.help-gnu-emacs@gnu.org>
2011-03-19  1:52   ` Stefan Monnier
     [not found] <mailman.8.1300470004.7441.help-gnu-emacs@gnu.org>
2011-03-18 17:56 ` Pascal J. Bourguignon
2011-03-18 20:36 ` Evans Winner
2011-03-19  4:32   ` rusi

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