Lisp mentality vs. Python mentality

Ciprian Dorin, Craciun ciprian.craciun at
Sat Apr 25 23:24:39 CEST 2009

On Sat, Apr 25, 2009 at 11:36 PM, Brett Hoerner <bretthoerner at> wrote:
> On Apr 25, 8:11 am, "Ciprian Dorin, Craciun"
> <ciprian.crac... at> wrote:
>>     Well in fact I would have written it like:
>> def validate_commandline(rexes, line) :
>>     if not compare (rexes, line, re.match) :
>>         if len (rexes) != len (line) :
>>             raise ValueError ("mismatch len")
>>         mismatch = find_index (rexes, line, re.match, negate = True)
>>         raise ValueError ("mismatch at %d" % (mismatch))
>>     Assuming, that I would have the function find_index.
>>     Ciprian.
> I think you've hit on the definition of "unpythonic".  (No, I don't
> have a dictionary definition for you, sorry).
> Using a function called "compare" to run a list of regexes against
> another list of regexes to get a boolean?  And then another find_index
> function doing the same where you pass in negate?  What is even going
> on here?
> I, for one, would take Martin's any day of the week.  It reads like
> good pseudocode as much "proper" Python does.
> Brett

    From your comments I understand that the only problem with my code
proposal are the function names... Well instead of compare (which was
kept from the beginning of the post) we could just rename it to
"matches". Does the name "matches" matches what it does? :) (If not we
can keep discussing for a proper name...)

    And about the find_index, we could rename it to
first_matching_index. About the negation optional parameter, we could
eliminate it if we allow either: to have another function
first_missmatching_index, but this leads to namespace bloat, or we
have a function named negate, that takes another function, and negates
it meaning. (Although i don't see anything wrong in the negate
argument... It's just like having order by asc | desc in SQL...)

    Thus the code would have been rewritten as: (we also put the
function on the first argument as its the most important argument)

def validate_commandline(rexes, line) :
    if not matches (re.match, rexes, line) :
        if len (rexes) != len (line) :
            raise ValueError ("mismatch len")
        mismatch = first_matching_index (negate (re.match), rexes, line)
        raise ValueError ("mismatch at %d" % (mismatch))


More information about the Python-list mailing list