[Tutor] Applications/examples of some advanced Py features, p
lease !
alan.gauld@bt.com
alan.gauld@bt.com
Tue Jan 7 16:11:22 2003
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
------_=_NextPart_001_01C2B588.41E56D3E
Content-Type: text/plain;
charset="iso-8859-1"
> Can anyone please give some examples / applications of the use of the
following advanced
> (advanced to me, at least :-) features of Python :
1. lambda
I cover lambdas in my Functional Programming topic on my online tutor...
2. nested functions - a little info was given by Danny in reply to my
earlier post on local-static
variables, but I would like more.
Its just a function defined inside another function, it can either be a
helper function for the "parent"
one or it can be a function that is returned by the parent in a similar way
to the lambda construct
(see above). This latter style of programming is powerful in a few areas and
replaces lambdas
in many cases.
3. Thoughts on implementing Interfaces in Py - a la Java interfaces.
You can do it since an interface is just a class with empty method
definitions.
What Python won't do is force you to provide definitions though.
However there is little or no need for interfaces in Python since it support
full multiple
inheritance and its dynamic nature makes the use of interfaces redundant in
most cases anyway.
Python effectively checks the interface of any object when it uses it.
> I am planning to write a game-playing program in Py which will have
features somewhat AI - ish.
Thats fine, but you shlouldn't need interfaces. THe other features may be
useful.
> - in what way their use makes code simpler, or maybe makes code possible
> that could not be written otherwise ('possible' in practical terms - I'm
- vaguely - aware
> of the fact that all languages are supposed to be theoretically
'Turing-equivalent' or
> some such term - but what I mean is that if something is going to take a
huge
> amount more code in some other language, or jumping through hoops, then
> I don't call it practically equivalent).
Languages are practically equivalent if they can do the same jobs. There may
be good
reasons to write reams more code - like performance! But for most purposes
each
language has some things it is better at. Python is not the best AI language
but its
better than, say, C++ or Java.
IMHO of course! :-)
Alan g.
Author of the Learn to Program website
http://www.freenetpages.co.uk/hp/alan.gauld/
<http://www.freenetpages.co.uk/hp/alan.gauld/>
------_=_NextPart_001_01C2B588.41E56D3E
Content-Type: text/html;
charset="iso-8859-1"
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META content="MSHTML 5.50.4807.2300" name=GENERATOR></HEAD>
<BODY>
<DIV><SPAN class=261372013-06012003><FONT face=Arial color=#0000ff size=2>>
</FONT></SPAN>Can anyone please give some examples / applications of
the use of the following advanced <SPAN class=261372013-06012003><FONT
face=Arial color=#0000ff size=2> </FONT></SPAN></DIV>
<DIV><SPAN class=261372013-06012003><FONT face=Arial color=#0000ff size=2>>
</FONT> </SPAN>(advanced to me, at least :-) features of Python :</DIV>
<BLOCKQUOTE
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid">
<P>1. lambda<SPAN class=261372013-06012003><FONT face=Arial color=#0000ff
size=2> </FONT></SPAN></P></BLOCKQUOTE>
<P><SPAN class=261372013-06012003><FONT face=Arial color=#0000ff size=2>I cover
lambdas in my Functional Programming topic on my online
tutor...</FONT></SPAN></P>
<BLOCKQUOTE
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid">
<P>2. nested functions - a little info was given by Danny in reply to my
earlier post on local-static <SPAN class=261372013-06012003><FONT
face=Arial color=#0000ff size=2> <BR></FONT></SPAN><SPAN
class=261372013-06012003> </SPAN>variables, but I would like more.<SPAN
class=261372013-06012003><FONT face=Arial color=#0000ff
size=2> </FONT></SPAN></P></BLOCKQUOTE>
<P><SPAN class=261372013-06012003><FONT face=Arial color=#0000ff size=2>Its just
a function defined inside another function, it can either be a helper function
for the "parent" <BR></FONT></SPAN><SPAN class=261372013-06012003><FONT
face=Arial color=#0000ff size=2>one or it can be a function that is returned by
the parent in a similar way to the lambda construct<BR>(see above). This latter
style of programming is powerful in a few areas and replaces lambdas<BR>in many
cases.</FONT></SPAN></P>
<BLOCKQUOTE
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid">
<P>3. Thoughts on implementing Interfaces in Py - a la Java interfaces.<SPAN
class=261372013-06012003><FONT face=Arial color=#0000ff
size=2> </FONT></SPAN></P></BLOCKQUOTE>
<P><SPAN class=261372013-06012003><FONT face=Arial color=#0000ff size=2>You can
do it since an interface is just a class</FONT> <FONT face=Arial
color=#0000ff size=2>with empty method definitions. <BR>What Python won't do is
force you to provide definitions though.</FONT></SPAN></P>
<P><SPAN class=261372013-06012003><FONT face=Arial color=#0000ff size=2>However
there is little or no need for interfaces in Python since it support full
multiple <BR>inheritance and its dynamic nature makes the use of interfaces
redundant in most cases anyway.</FONT></SPAN></P>
<P><SPAN class=261372013-06012003><FONT face=Arial color=#0000ff size=2>Python
effectively checks the interface of any object when it uses
it.</FONT></SPAN></P>
<P><SPAN class=261372013-06012003><FONT face=Arial color=#0000ff
size=2> > </FONT></SPAN>I am planning to write a game-playing
program in Py which will have features somewhat AI - ish. <SPAN
class=261372013-06012003><FONT face=Arial color=#0000ff
size=2> </FONT></SPAN></P>
<P><SPAN class=261372013-06012003><FONT face=Arial color=#0000ff size=2>Thats
fine, but you shlouldn't need interfaces. THe other features may be
useful.</FONT></SPAN></P>
<P><SPAN class=261372013-06012003><FONT face=Arial color=#0000ff size=2>>
</FONT></SPAN> - in what way their use makes code simpler, or maybe
makes code possible <SPAN class=261372013-06012003><FONT face=Arial
color=#0000ff size=2> <BR>> </FONT></SPAN>that could not be
written otherwise ('possible' in practical terms - I'm - vaguely -
aware <SPAN class=261372013-06012003><FONT face=Arial color=#0000ff
size=2> <BR>> </FONT></SPAN>of the fact that all languages are
supposed to be theoretically 'Turing-equivalent' or <SPAN
class=261372013-06012003><FONT face=Arial color=#0000ff size=2> <BR>>
</FONT></SPAN><SPAN class=261372013-06012003> </SPAN>some such term - but
what I mean is that if something is going to take a huge <SPAN
class=261372013-06012003><FONT face=Arial color=#0000ff size=2> <BR>>
</FONT></SPAN><SPAN class=261372013-06012003> </SPAN>amount more code in
some other language, or jumping through hoops, then <SPAN
class=261372013-06012003><FONT face=Arial color=#0000ff
size=2> <BR>> <FONT face="Times New Roman" color=#000000 size=3>
</FONT></FONT></SPAN>I don't call it practically equivalent).<SPAN
class=261372013-06012003><FONT face=Arial color=#0000ff
size=2> <BR></FONT></SPAN></P>
<P><SPAN class=261372013-06012003><FONT face=Arial color=#0000ff
size=2>Languages are practically equivalent if they can do the same jobs. There
may be good <BR></FONT></SPAN><SPAN class=261372013-06012003><FONT face=Arial
color=#0000ff size=2>reasons to write reams more code - like performance! But
for most purposes each <BR>language has some things it is better at. Python is
not the best AI language but its <BR></FONT></SPAN><SPAN
class=261372013-06012003><FONT face=Arial color=#0000ff size=2>better than, say,
C++ or Java.</FONT></SPAN></P>
<P><SPAN class=261372013-06012003><FONT face=Arial color=#0000ff size=2>IMHO of
course! :-)</FONT></SPAN></P><SPAN class=261372013-06012003><FONT face=Arial
color=#0000ff size=2>
<P><FONT face="Courier New" size=2>Alan g.</FONT> <BR><FONT face="Courier New"
size=2>Author of the Learn to Program website</FONT> <BR><FONT
face="Courier New" size=2><A target=_blank
href="http://www.freenetpages.co.uk/hp/alan.gauld/">http://www.freenetpages.co.uk/hp/alan.gauld/</A></FONT>
</P>
<P></FONT></SPAN><FONT face=Arial color=#0000ff
size=2></FONT> </P></BODY></HTML>
------_=_NextPart_001_01C2B588.41E56D3E--