[Edu-sig] Articles of possible interest
Ka-Ping Yee
ping@lfw.org
Wed, 3 May 2000 03:12:34 -0700 (PDT)
On Thu, 27 Apr 2000, Dorothea Salo wrote:
>
> Part of the problem. But I said that. :) You have more women in
> your audience than you probably realize, and you'll have more (and more
> vocal) women if you make them feel welcome.
I agree heartily.
> My point is more that kids might find text processing *immediately
> useful* in a way that robots aren't.
Text processing can be way fun. I think a great elementary
pedagogical example could be a simple random-sentence generator
(hey, what do you know, you just used recursion!) -- and a
Markov-chain gibberish generator is very easy to write in Python
and *tremendously* entertaining!
Pattern-matching can be fun too. (I recently played around
trying to figure out how difficult it would be to swap the
genders of all the pronouns in a piece of text, or replace them
all with gender-neutral pronouns. If i ever get that figured
out, i plan to create a new gender-neutral view on the Web,
in the same way the http://www.lfw.org/jminc/ creates an insane
view on the whole Web.)
> Playing with strings can actually be a lot of fun. The "aha moment"
> that brought me to Python was learning about regular expressions. Most
> programmers, I think, find regexes as boring and difficult as I find
> computational math games. Me, I *love* constructing regexes, do it all the
> time and have done really pretty amazing things with them -- and I think
> there are LOTS of people who would catch onto them quickly and find them as
> fascinating as I do.
Have you seen my "rxb" module? It sounds like you might enjoy
it. It's too slow at constructing regular expressions if you
need performance, but i think it's a good attempt at making the
process of constructing regular expressions friendlier and more
lucid: http://www.lfw.org/python/
>>> import rxb
>>> rxb.welcome()
>>> letter
<Pattern [A-Za-z]>
>>> either(some(digits), some(letters) + 3*digit)
<Pattern [A-Za-z]+[0-9][0-9][0-9]>
>>> "spam[" + some(digits) + "]"
<Pattern spam\\[[0-9]+\\]>
Turning patterns into objects lets you build complex patterns
out of small reusable components:
>>> ident = some(letters)
>>> number = some(digits)
>>> pat = label.name(ident) + "[" + label.index(number) + "]"
>>> pat
<Pattern (?P<name>[A-Za-z]+)\\[(?P<index>[0-9]+)\\]>
>>> pat.search("spam and eggs[42] with ham")
<Match 'eggs[42]'>
>>> _.name, _.index
('eggs', '42')
-- ?!ng
"To be human is to continually change. Your desire to remain as you are
is what ultimately limits you."
-- The Puppet Master, Ghost in the Shell