I'm intrigued that Python has some functional constructions in the language.

namekuseijin namekuseijin at gmail.com
Sat May 9 02:47:30 CEST 2009


On May 8, 7:22 pm, Carl Banks <pavlovevide... at gmail.com> wrote:
> On May 8, 1:56 pm, namekuseijin <namekusei... at gmail.com> wrote:
> > Carl Banks escreveu:
> > > 2. However, functional programming is cryptic at some level no matter
> > > how nice you make the syntax.
>
> > When your program is nothing but function definition and function
> > application, syntax is meaningless.
>
> For mere function application you could maybe argue that (and it'd be
> a stretch), but there is no reasonable way to claim that syntax is
> meaningless for defining functions.  Unless you meant "function
> declaration", and I think you did because you don't seem to know what
> functional programming is.
>
> >  you're just calling functions provided by
> > the host,
>
> That's not what functional programming means, nor is it remotely
> comparable to functional programming.

My point is that when all you do is call functions, syntax is
irrelevant.  You call functions pretty much in the same way regardless
of language:  functionname, optionalOpenPar, parameters,
optionalClosePar.  Office automation is all about calling predefined
functions in the host application, that's all my example was about.

Functional programming is all about defining functions and applying
functions.  Core ML, Haskell and Scheme are all like that, pretty much
an extended lambda calculus.  Haskell provides a bunch of syntatic
sugar, more so than Scheme for instance, but in the end, it all gets
converted into lambda expressions and application of arguments to
lambda expressions.

Python has a bunch of handy predefined syntax, because not everything
can be defined out of functions alone.  Syntax is much more important
here than in true functional programming languages, where pretty much
everything besides basic "if" branching is a "userland" function --
including looping constructs.  I have written my own list
comprehensions and generators in Scheme!

When you read a Haskell or Scheme program, it's truly hard to spot
predefined syntax:  most of it is composable function application.
Once in a while you spot an "if".

> > barely using any syntax or intrinsic language feature anyway.
> >   Any language will do just fine.
>
> Well, that's not true since I found it to be quite a different
> experience to invoke Microsoft library functions  in JScript than in
> Visual Basic.  (Mostly because it's a PITA even to "barely use any
> syntax or intrinsic language feature" of Visual Basic.)

Not quite Word, but here's in OpenOffice scripted either in BeanShell,
JScript and Java:
http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/Scripting/Writing_Macros

oDoc = context.getDocument();
xTextDoc = (XTextDocument) UnoRuntime.queryInterface
(XTextDocument.class,oDoc);
xText = xTextDoc.getText();
xTextRange = xText.getEnd();
xTextRange.setString( "Hello World (in BeanShell)" );

oDoc = XSCRIPTCONTEXT.getDocument();
xTextDoc = UnoRuntime.queryInterface(XTextDocument,oDoc);
xText = xTextDoc.getText();
xTextRange = xText.getEnd();
xTextRange.setString( "Hello World (in JavaScript)" );

XTextDocument xtextdocument = (XTextDocument) UnoRuntime.queryInterface
(
                                               XTextDocument.class,
xDocModel);
XText xText = xtextdocument.getText();
XTextRange xTextRange = xText.getEnd();
xTextRange.setString( "Hello World (in Java)" );

Although this is a bad example because of the closeness of syntax
between the languages, it would not be much different in a completely
alien language.  It would still make a call to get the data model of
the current document, another to get the text, another to get the end
and another to set the string.  It's all function calls, really.

No, it's not functional programming, but it illustrates what I said:
when all you do is call functions, syntax is irrelevant.



More information about the Python-list mailing list