Anyone who's used Lisp knows that only Scheme heathen put question marks in predicates. Lisp (and Common Lisp) use the -P convention to mark predicates.
You could to the same in Perl (use a -<samp>p</samp> or -<samp>_p</samp> suffix on predicates). is_female would become femalep, and Lisp hackers would feel right at home. Perl hackers might be somewhat less pleased, though.
The reason you can do this sort of thing (use question marks in names) in Scheme (and could do it in Common Lisp, even though it isn't done) is that Lisps have a very simple lexical texture. In contrast, Perl has a horribly complex lexical texture to it, using every symbol on my keyboard (and overloading most of them). But any language using the C "ternary operator" ?: (and not promoting whitespace as a required separator) will not be able to have question marks in symbols.
| [reply] [d/l] [select] |
I'm always amused by something that says "end of story" at the beginning of the third paragraph from the end... :-) I'm also curious about some of your sweeping statements, here, because they don't make instant sense to me, and you didn't give me much to work with in figuring them out.
To begin with, I haven't ever "used" Lisp, though I'm somewhat familiar with it, but from Lisp's general reputation, I'm assuming that when you say "faster" you don't mean "faster in execution time", since if you were worrying about execution time you'd be using something... er, faster. :-) So do please correct me if I'm wrong on that (since I'm going to ignore that consideration henceforth).
That said, where is the advantage to the division of function names you propose? I can imagine some cases where it would be advantageous to have your test function return an object rather than a simple "to thine own self be true", certainly (though I would guess fewer in Perl than Lisp), but in that case, why have a second function which does the same amount of work and returns something else? Since the you can return any old Perl object and have it test True in boolean context, what's the need to have two functions for it?
"Subroutines that evaluate to true or false should be distinguished from ones that return a value."
Generally speaking, I agree--but I don't think functions that ask true-false questions should return much other than true or false, personally. Assuming that you do (for reasons hypothecated above) want to do so, why not do it all the time?
None of this, of course, goes to show that your points are wrong, but merely that I do not understand quite what you're getting at--might I be enlightened?
If God had meant us to fly, he would *never* have given us the railroads. --Michael Flanders
| [reply] [d/l] |
| [reply] |
Im a little confused. While I'm well aware of the convention of using the _p -p p suffix for predicate I really dont see how it or a question mark makes the functions following the is_XXXX covention (ie is_female()) more readable.
Its very clear (at least to me) that an is_XXXXX function returns a boolean (well, perls closest equivelent). What benefit do you derive from the extra marker? I can see how a function _not_ named is_XXXXX might need it, but then again we have a convention for that: is_XXXXXX.
(partly serious, partly not)
Yves / DeMerphq
---
Writing a good benchmark isnt as easy as it might look. | [reply] [d/l] |
| [reply] |
2) I see it as an analog of "Hungarian notation"
You mean woefully painful and innappropriate to a language like perl?
;-)
Yves / DeMerphq
---
Writing a good benchmark isnt as easy as it might look.
| [reply] |
To be more precise, in Scheme it seems to be traditional to end this type of function with a '?'. In Common Lisp, depending on whether or not the rest of the function's name has a '-' in it or not, one ends it with -p or p (e.g one would have simple-string-p and stringp). (I think there may be an exception to this, but it escapes me at the moment. And I don't think this is followed strictly for certain functions which get automatically defined when using defstruct - which may even be the exceptions I'm thinking of.) I do not know about other Lisp dialects.
| [reply] |