LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Functional Programming? (https://www.linuxquestions.org/questions/programming-9/functional-programming-819310/)

raskin 07-12-2010 12:23 PM

Quote:

Originally Posted by Sergei Steshenko (Post 4031052)
H_TeXMeX_H:

Anyway, I'm impatiently waiting to see how H_TeXMeX_H will implement the suggested code snippet in C, Python, Java (well, the very very latest Java is supposed to have closures).

Sorry to disappoint you, but even Python has closures. But as we are discussing functional programming languages here, Common Lisp, Scheme, Clojure, OCaml, Haskell, JavaScript are also fair game.

By the way, delegates (bound object methods passed as functions) were present in Object Pascal and so semantically closures were even there (it was clumsy for some uses, because it was apparently optimized for a fixed use case)

Sergei Steshenko 07-12-2010 12:27 PM

Quote:

Originally Posted by raskin (Post 4031065)
Sorry to disappoint you, but even Python has closures. ...


Half way: http://en.wikipedia.org/wiki/Closure...ence%29#Python .

Rather, used to be half-way until Python 3.1 - I have already written in a different forum that after more than 10 years Python finally catches up with Perl.

On my Suse-11.1 Python version is 2.6.

H_TeXMeX_H 07-12-2010 12:29 PM

I can't write that in bash, bash arrays are no good, maybe in python or C. But, I don't think I would even need such a program as you wrote.

raskin 07-12-2010 12:31 PM

Quote:

Originally Posted by Sergei Steshenko (Post 4031072)
Rather, used to be half-way until Python 3.1 - I have already written in a different forum that after more than 10 years Python finally catches up with Perl.

I said "even Python" for a reason. And 10 years is a great result - those catching up with Common Lisp, Haskell or SmallTalk tend to spend much more.

Sergei Steshenko 07-12-2010 12:33 PM

Well, but WRT anonymity Python is still behind Perl:

http://en.wikipedia.org/wiki/Anonymous_function#Python :

Quote:

Python supports simple anonymous functions through the lambda form. The executable body of the lambda must be an expression and can't be a statement, which is a restriction that limits its utility. The value returned by the lambda is the value of the contained expression. Lambda forms can be used anywhere ordinary functions can, however these restrictions make it a very limited version of a normal function.
.

Sergei Steshenko 07-12-2010 12:37 PM

Quote:

Originally Posted by H_TeXMeX_H (Post 4031074)
I can't write that in bash, bash arrays are no good, maybe in python or C. But, I don't think I would even need such a program as you wrote.

So, write in "C" something similar, for starters without closures, and we'll discuss how readable it is and how it does (not) pollute global name space.

What I wrote is a rudimentary object - a set of encapsulated and possibly related data and functions.

MTK358 07-12-2010 01:55 PM

I wanted to say something here:

When reading about Haskell, I found that it said all variables were unchangable once they were created, and I understood that this was part of all functional languages. Is this true?

Sergei Steshenko 07-12-2010 02:06 PM

Quote:

Originally Posted by MTK358 (Post 4031137)
I wanted to say something here:

When reading about Haskell, I found that it said all variables were unchangable once they were created, and I understood that this was part of all functional languages. Is this true?

In Haskell variables are immutable; functional language treats functions as first class objects, i.e. functions can be passed as arguments and returned from other functions - mutability is a separate issue.

Immutability allows much better optimizations and formal correctness proofs.

OCaml, for example, allows to explicitly declare a variable or a field mutable, but recommends to do this as seldom as possible and when really needed. The tutorial has examples/explanations on this.


All times are GMT -5. The time now is 01:38 AM.