3

I've come across the following code snippet (a function definition):

choose (x:xs) = choosep x xs
 where choosep x [] = x
 choosep x (_:_) = x
 choosep _ (x:xs) = choosep x xs

in Curry programming language in a "standard library"--/usr/lib/curry-0.9.11/Success.curry from Muenster Curry Compiler. Here:

choose :: [a] -> a

and

choosep :: a -> [a] -> a -- BTW, not a _p_redicate

Is the "p" suffix for the helper recursive function choosep a known naming convention? Perhaps it comes from functional programming tradition (Haskell) or logical programming (Prolog?). What does it mean then?

(This function was considered in Why is the non-deterministic choice function in Curry's std lib not defined straightforwardly but rather with a helper 2-argument function?.)

Martijn Pieters
1.1m325 gold badges4.2k silver badges3.4k bronze badges
asked Mar 11, 2011 at 22:59

4 Answers 4

2

In this case, I believe p stands for "prime". Rather than calling the helper choose' or chooseprime, they use choosep.

answered Mar 11, 2011 at 23:05
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, this seems to be plausible. ' would be clearer than p ;)
2

I think it stands for 'prime' -- in OCaml, which allows ' in identifiers, helper functions are frequently named foo'. At a high level, I think this (and the use of 'where' for a post-hoc helper definition) stems from the desire to allow functional programs to resemble their equivalent definitions in pure math.

answered Mar 11, 2011 at 23:08

5 Comments

As far as I can tell, the Muenster Curry compiler also allows ' in identifiers.
Yes, it's a very nice thing about names in these languages--that they allow to write primes at the end, so that it looks like math. I was glad when I saw it the first time when learning Haskell. And well, Curry also allows the more real prime symbols (') in names, and there are primes in variable names in other "standard" modules' implementations. (Out of curiosity, I'll perhaps look whether there are occurences of ' in function names.) So, the way to this "p" is somewhat strange: write out a ' as prime, then abbreviate it to p... ;)
@Gabe: Path dependence then :)
@imz: Perhaps the only way to be sure is to email this guy: informatik.uni-kiel.de/~mh ?
True. Ok, if it's not a well-known naming convention, then I'll probably not bother.
1

In this context, as others have noted, it probably doesn't apply, but there is a popular Lisp convention of using a final 'p' to denote a predicate. See jargon p-convention.

I personally prefer the Ruby convention of ending a predicate with a '?'.

answered Mar 11, 2011 at 23:15

2 Comments

Thanks for the comment! That's why it looked kinda misleading: a p sticked not to a predicate...
Ending predicate names with ? is a convention in many Lisps (and some relatives like Scheme and Logo) as well. Common Lisp, unfortunately, does not follow.
0

P stands for 'predicate'. A thing that returns 'true' or 'false'.

answered Mar 11, 2011 at 23:04

3 Comments

That's what I thought at first, but in this case the function isn't a predicate.
Yes, choose's type is [a] -> a, not a predicate. And choosep :: a -> [a] -> a.
Well, this is very interesting. There's a longstanding tradition of 'foop' as foo-predicate all over other areas, these haskellers are just odd.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.