Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"foop": a naming convention? It's a helper recursive function for "foo"; what does the suffix "p" mean?

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

like image 880
imz -- Ivan Zakharyaschev Avatar asked Nov 27 '25 03:11

imz -- Ivan Zakharyaschev


2 Answers

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

like image 181
Gabe Avatar answered Nov 29 '25 23:11

Gabe


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.

like image 25
phooji Avatar answered Nov 30 '25 00:11

phooji



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!