Tuesday, January 31, 2006

Why write Python ?

When you can write your own language?

Watch out for punchline in the script that follows. In particular I like the fact that the programmer wrote Python, but the program wrote "Pythonn", and the program runs in Pythonn

This could be fun ! ... "Mython", "Highthon", "yThon" , ....

An example for Pythonistas is below

myths.pluralise() only adds attributes to a blank class, but there's no "punches" in the source, "punches" is grammar thingy, which the Python language does not have. (And it was just a first try anyway. I know nothing that would prevent making more radical changes to the language, and I know a few things that would help.)

myths.pluralise() is actually written in Python, but there's no reason why it should be so restrictive, it could just as easily by written in Pythonn, or Pythonnnn, as long as the concepts in Pythonn can be described in Pythonn-1

So, we could have a new set of languages for every programming problem, and such languages will tend to increase in expressiveness, with an extra tendency towards becoming mythical.

So that the people who are about to stop reading here, would be more likely to keep reading, because what follows would be a lot closer to English. (Or C++, Deutsch, lisp, ...)

Here's the example:
=====================================================
from myths import pluralise

class joke:
def __init__(self,value):
self.punch = value
self.name = 'joke'

def hello(self):
print 'And then the man says: \n%s' % self.punch

class Comedian(joke):
def __init__(self):
joke.__init__(self,value='BOOM BOOM')
self.name = 'comedian'

class Python(joke):
def __init__(self):
joke.__init__(self,value='Ni')
self.name = 'python'

def hello(self):
print '\t%s' % self.punch

class Toon(Python): # for purpose of demo only
def __init__(self):
Python.__init__(self)
def hello(self):
print 'And then the duck says : %s' % self.punch

def example():

ericIdle = Python()
michaelPalin = Python()
johnCleese = Python()
terryGilliam = Python()
terryJones = Python()
grahamChapman = Python()

ericIdle.punch = 'Ahh, I see you have a machine that goes PING!'
terryJones.punch = 'ping'

flyingCircus = [ grahamChapman, terryJones, terryGilliam, ericIdle, michaelPalin, johnCleese ]
pythons = pluralise(flyingCircus)

print 'How many Pythons use the various punchlines ?'
for punch in pythons.punches:
print punch,
print ": %d" % len(pythons.punches[punch])

daffyDuck = Toon()

basilBrush = Comedian()
ronnieBarker = Comedian()
denisOLeary = Comedian()


funnyGuys = flyingCircus + [ basilBrush, ronnieBarker,denisOLeary, daffyDuck ]
cast = pluralise(funnyGuys)

print 'How many Comedians ?'
for punch in cast.punches:
print punch,
print ": %d" % len(cast.punches[punch])

johnCleese.punch = 'I did mention it once, but I think I got away with it'
print 'The Dead Duck Sketch'
for x in cast.names['python']:
x.hello()

============================================================
How many Pythons use the various punchlines ?
'Ni': 4
'ping': 1
'Ahh, I see you have a machine that goes PING!': 1

How many Comedians ?
'Ni': 4
'BOOM BOOM': 3
'ping': 1
'Ahh, I see you have a machine that goes PING!': 1

The Dead Duck Sketch:

Ni
ping
Ni
Ahh, I see you have a machine that goes PING!
Ni
I did mention it once, but I think I got away with it
And then the duck says : Ni


# =================================================
# The code is prettied up - no guarantees it compiles.
# And you can just, like, totally forget about
# merchantibility for any particular purpose.


0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home