Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > I'm intrigued that Python has some functional constructions in the language.

Reply
Thread Tools

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

 
 
Casey Hawthorne
Guest
Posts: n/a
 
      05-08-2009
I'm intrigued that Python has some functional constructions in the
language.

Would it be possible to more clearly separate the pure code (without
side effects) from the impure code (that deals with state changes,
I/O, etc.), so that the pure code could be compiled and have
aggressive functional transformations applied to it for efficiency.

That way, the syntax would be a lot easier to understand, than most
functional languages, like Haskell.

I gave a presentation at the beginning of last year on Haskell and at
the end, someone's comment was, "I can see the benefits of functional
programming but why does it have to be so cryptic."
--
Regards,
Casey
 
Reply With Quote
 
 
 
 
pruebauno@latinmail.com
Guest
Posts: n/a
 
      05-08-2009
On May 8, 3:04*pm, Casey Hawthorne <(E-Mail Removed)> wrote:
> I'm intrigued that Python has some functional constructions in the
> language.
>
> Would it be possible to more clearly separate the pure code (without
> side effects) from the impure code (that deals with state changes,
> I/O, etc.), so that the pure code could be compiled and have
> aggressive functional transformations applied to it for efficiency.
>
> That way, the syntax would be a lot easier to understand, than most
> functional languages, like Haskell.
>
> I gave a presentation at the beginning of last year on Haskell and at
> the end, someone's comment was, "I can see the benefits of functional
> programming but why does it have to be so cryptic."
> --
> Regards,
> Casey


Don't forget that the Python interpreter is simple. It makes
maintenance easier and allows embedding it into other programs. Good
optimizing compilers for functional languages are not simple. Your
idea would be something that could be added to the PyPy project in the
future.
 
Reply With Quote
 
 
 
 
Carl Banks
Guest
Posts: n/a
 
      05-08-2009
On May 8, 12:04*pm, Casey Hawthorne <(E-Mail Removed)>
wrote:
> I'm intrigued that Python has some functional constructions in the
> language.
>
> Would it be possible to more clearly separate the pure code (without
> side effects) from the impure code (that deals with state changes,
> I/O, etc.), so that the pure code could be compiled and have
> aggressive functional transformations applied to it for efficiency.


No not really, at least not in any way that it maintains compatibility
with Python.

Python does either expose or mimic the parsing process to the user, so
you could maybe exploit it to get parse trees of functions (checking
that there is nothing that has side-effects) to feed to a specialized
optimizer, but if you do that it might as well be a new langauge.


> That way, the syntax would be a lot easier to understand, than most
> functional languages, like Haskell.
>
> I gave a presentation at the beginning of last year on Haskell and at
> the end, someone's comment was, "I can see the benefits of functional
> programming but why does it have to be so cryptic."


A couple thoughts:

1. It's just one person's opinion.
2. However, functional programming is cryptic at some level no matter
how nice you make the syntax.


Carl Banks
 
Reply With Quote
 
Lawrence D'Oliveiro
Guest
Posts: n/a
 
      05-08-2009
In message <gu269i$16if$(E-Mail Removed)>, namekuseijin 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.


On the contrary, syntax is vital to the correct interpretation of functional constructs. See, for example,
<http://mail.python.org/pipermail/python-list/2008-October/683816.html>.

 
Reply With Quote
 
Carl Banks
Guest
Posts: n/a
 
      05-08-2009
On May 8, 1:56*pm, namekuseijin <(E-Mail Removed)> 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.

> It's kinda like scripting, say, Microsoft Word in either Visual Basic,
> Python, Haskell or whatever:


No it's nothing like that at all.

> *you're just calling functions provided by
> the host,


That's not what functional programming means, nor is it remotely
comparable to functional programming.

> 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.)

However, that has nothing to do with functional programming.


Carl Banks
 
Reply With Quote
 
namekuseijin
Guest
Posts: n/a
 
      05-09-2009
On May 8, 6:48*pm, Lawrence D'Oliveiro <l...@geek-
central.gen.new_zealand> wrote:
> In message <gu269i$(E-Mail Removed)>, namekuseijin 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.

>
> On the contrary, syntax is vital to the correct interpretation of functional constructs. See, for example,
> <http://mail.python.org/pipermail/python-list/2008-October/683816.html>.


Yeah, it's important in an imperative language to have predefined
syntax to allow you to do things. Point taken.
 
Reply With Quote
 
namekuseijin
Guest
Posts: n/a
 
      05-09-2009
On May 8, 7:22*pm, Carl Banks <(E-Mail Removed)> wrote:
> On May 8, 1:56*pm, namekuseijin <(E-Mail Removed)> 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/...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.
 
Reply With Quote
 
Paul Rubin
Guest
Posts: n/a
 
      05-09-2009
Casey Hawthorne <(E-Mail Removed)> writes:
> Would it be possible to more clearly separate the pure code (without
> side effects) from the impure code (that deals with state changes,
> I/O, etc.), so that the pure code could be compiled and have
> aggressive functional transformations applied to it for efficiency.


This doesn't fit Python semantics terribly well.

> That way, the syntax would be a lot easier to understand, than most
> functional languages, like Haskell.


I don't think it would help much, even if it was done (see below).

> I gave a presentation at the beginning of last year on Haskell and at
> the end, someone's comment was, "I can see the benefits of functional
> programming but why does it have to be so cryptic."


Haskell's syntax (like Python's or Lisp's) takes a little getting used
to, but in my experience it's not really cryptic. IMHO, functional
programming is difficult for imperative programmers to understand at
first, because the concepts in it are really different from what
imperative programmers are generally used to, and that take some head
scratching to make sense of. Think of a beginning imperative
programmer encountering recursion or coroutines for the first time, or
how someone learning calculus deals with the concepts of limits and
continuity. These subjects have certain hurdles that require effort
to get past, but which expand the range of problems that someone who
has put in the effort can solve. Functional programming presents more
such hurdles, and more such expansion.
 
Reply With Quote
 
Carl Banks
Guest
Posts: n/a
 
      05-09-2009
On May 8, 5:47*pm, namekuseijin <(E-Mail Removed)> wrote:
> 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.


then...

> Functional programming is all about defining functions and applying
> functions. *Core ML, Haskell and Scheme are all like that,


Yet all three use a different syntax to call functions, none of them
the "pretty much the same way" you listed above.

Haskell, Python, and (I think) ML can define operators with different
syntax than function calls, that matters.

Haskell and Python have syntax for list operations, that matters.

Haskell nexts using indentation, the others nest using tokens(**),
that matters.

I can go on, but you get the idea. Point is: functional programmint
isn't "nothing but calling functions".

[snip irrelevant stuff about office scripting]

Carl Banks

(**) Python does using indentation to nest, of course, but not at the
expression level.
 
Reply With Quote
 
Paul Rubin
Guest
Posts: n/a
 
      05-09-2009
Carl Banks <(E-Mail Removed)> writes:
> I can go on, but you get the idea. Point is: functional programmint
> isn't "nothing but calling functions".


I would mainly describe functional programming as programming with the
pervasive use of higher order functions. For example, loops in
functional programming can be implemented using recursion, but in
practice, one doesn't see actual explicit recursion in Haskell code
all that often. Instead we see wide use of functions like map,
filter, and fold (a/k/a "reduce"), which can take the place of looping
constructs.

Python also has higher-order functions like that, but their use is
disfavored in certain circles. With Python 3, there has actually been
movement towards removing them from the language.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in running a basic code in python 3.3.0 that includes HTML file Satabdi Mukherjee Python 1 04-04-2013 07:48 PM
Has Implicit Int been disabled in the new C11 standard? What aboutother previously depreciated constructions eg gets? Lord Voldermort C Programming 20 03-01-2012 10:57 AM
Some shareware has a time limit and the software will not work after the time limit has expired. anthony crowder Computer Support 20 01-16-2007 10:01 AM



Advertisments