Fun with primality testing

Lloyd Zusman ljz at asfast.com
Fri May 12 21:28:44 EDT 2000


neelk at brick.cswv.com (Neel Krishnaswami) writes:

> François Pinard <pinard at iro.umontreal.ca> wrote:
> > 
> > [ ... ]
> > 
> > import re
> > for n in range(2, 1000):
> >     if not re.match('(11+)\\1+$', '1'*n):
> >         print n
> 
> That's EVIL!
> 
> Regexps are clearly evolving towards becoming the mutant offspring
> of Prolog and TECO -- [ ... ]

Don't forget APL, as well.


> [ ... ] obviously we will know the apocalypse is at hand when Perl
> adds a cut operator to its pattern language.

Well, better start divesting yourself of your worldly attachments and
keeping your eyes peeled for seven-headed ten-horned beasts[*],
because Perl regexps already have had for some time a few things that
taken together are pretty damned close to various forms of the cut
operator:

<praying voluminously and making the sign of the cross as I type>

  zero-width positive look-ahead assertion

  zero-width negative look-ahead assertion

  zero-width positive look-behind assertion

  zero-width negative look-behind assertion

And to further multiply the evil, the Perl folks already have added
experimental versions of ...

  zero-width embedded Perl code evaluation

  zero-width postponed embedded Perl code evaluation

  conditional expression (can be used in conjunction with
  the assertions above)

<shuddering>

I'm now convinced that when physicists finally come up with the
definitive T.O.E. (Theory of Everything), it will actually be a single
Perl regular expression.

> Neel

[*] Or is it ten-headed seven-horned beasts?

-- 
 Lloyd Zusman
 ljz at asfast.com



More information about the Python-list mailing list