LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 07-12-2010, 01:23 PM   #16
raskin
Senior Member
 
Registered: Sep 2005
Location: Russia
Distribution: NixOS (http://nixos.org)
Posts: 1,893

Rep: Reputation: 68

Quote:
Originally Posted by Sergei Steshenko View Post
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)
 
Old 07-12-2010, 01:27 PM   #17
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Quote:
Originally Posted by raskin View Post
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.
 
Old 07-12-2010, 01:29 PM   #18
H_TeXMeX_H
Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269
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.
 
Old 07-12-2010, 01:31 PM   #19
raskin
Senior Member
 
Registered: Sep 2005
Location: Russia
Distribution: NixOS (http://nixos.org)
Posts: 1,893

Rep: Reputation: 68
Quote:
Originally Posted by Sergei Steshenko View Post
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.
 
Old 07-12-2010, 01:33 PM   #20
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
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.
.
 
Old 07-12-2010, 01:37 PM   #21
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Quote:
Originally Posted by H_TeXMeX_H View Post
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.
 
Old 07-12-2010, 02:55 PM   #22
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Original Poster
Rep: Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714
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?
 
Old 07-12-2010, 03:06 PM   #23
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Quote:
Originally Posted by MTK358 View Post
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.

Last edited by Sergei Steshenko; 07-12-2010 at 03:54 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Book Excerpt: Chapter 6: Functions and Functional Programming LXer Syndicated Linux News 0 10-10-2009 06:11 AM
Learning functional programming Robhogg Programming 17 03-27-2009 09:58 AM
functional programming in C++ synss Programming 2 08-03-2007 02:33 AM
Functional Programming - Discussion taylor_venable Programming 6 07-30-2006 11:20 PM
LXer: Everything Your Professor Failed to Tell You About Functional Programming LXer Syndicated Linux News 0 01-31-2006 10:31 PM


All times are GMT -5. The time now is 08:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration