*
The moose likes Clojure and the fly likes Thinking functionally Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Clojure
Bookmark "Thinking functionally" Watch "Thinking functionally" New topic
Forums: Functional Programming Clojure
Author

Thinking functionally

Stian Almaas
Ranch Hand

Joined: Sep 22, 2005
Posts: 33
Hello guys!

I've been looking into clojure a little bit now and I find it fascinating but also hard. After basically twenty years of imperative programming it's really hard to change my way of thinking to solve problems effectively in clojure. What I need is basically a how-to in functional programming. How do you attack a problem when thinking functionally, that's what I'm struggling with.

Do any of you guys know of any resources that can help me with that. I'm thinking perhaps the clojure koans on github are a bit like that, but I haven't had time to look at that yet.

Regards,
Stian
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Although I haven't done them all, I think that the github exercises are more focused on the core syntax and api, rather than anything else.


[My Blog]
All roads lead to JavaRanch
Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3476

You may want to check http://codingkata.org/ and the Euler Project also.
I didn't get the functional thinking (yet) but I think it started to tickle my mind a little bit.
My suggestion is if you already know Java and want to start being functional, I recommend you play with Scala for many reasons:
1. The syntax is really similar to Java (to some degree).
2. Scala blending OOP and FP, you don't have to change your mind set instantly.
Chris Houser
author
Greenhorn

Joined: Feb 07, 2011
Posts: 22

I made the jump from imperative to functional programming while solving Project Euler problems. They're fun and I continue to recommend them. They start start simple and get harder, while never really demanding you learn a lot of miscellaneous library functions (for networking, databases, GUIs, etc.) as you might for any "real world" project you might use as a learning vehicle. This keeps them relatively approachable.

Also, lots of other people have gone there before and once you've solved a particular problem you can check and see how others have solved it. This will help you learn even faster, giving you ideas to solve the next harder problem.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Chris Houser wrote:I made the jump from imperative to functional programming while solving Project Euler problems. Also, lots of other people have gone there before and once you've solved a particular problem you can check and see how others have solved it.

This looks interesting, unless you hate mathematics :)
Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3476

I'm planning to read "Real World Haskell" to learn much more about FP when I get some time:
http://book.realworldhaskell.org/
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

John Todd wrote:I'm planning to read "Real World Haskell" to learn much more about FP when I get some time:
http://book.realworldhaskell.org/

Personally I find it confusing to study several of these languages. They look similar from the outside, but have their own notation and api. If there were something else that I'd look for, it'd be Lisp (Practical Common Lisp)
Sean Corfield
Ranch Hand

Joined: Feb 09, 2011
Posts: 252
    
    5

Christophe Verré wrote:Personally I find it confusing to study several of these languages. They look similar from the outside, but have their own notation and api.


Then I suspect you wouldn't vote for Bruce Tate's "Seven Languages in Seven Weeks"? I found it an excellent way to learn enough of several different languages in a short space of time - and be challenged to "think different".

Caveat: I got into functional programming back in the early/mid 80's, then picked up Prolog, then C and later got into OOP (with C++ in '92 and Java in '97) so my view of all this may be very different to a lot of Java developers.

I'm very pleased to see functional programming becoming mainstream with increased interest in Haskell and Lisp as well as solid options on the JVM in the form of Clojure and Scala.
Michael Fogus
author
Greenhorn

Joined: Feb 07, 2011
Posts: 12

Sean Corfield wrote:I'm very pleased to see functional programming becoming mainstream with increased interest in Haskell and Lisp as well as solid options on the JVM in the form of Clojure and Scala.


Further, functional techniques and features are finding their way into mainstream languages like C#, Javascript, and (to some extent) Java.
Stian Almaas
Ranch Hand

Joined: Sep 22, 2005
Posts: 33
Just wanted to send a thank you to Mr. Houser. I have done a few of the Euler problems before but now I have studied example solutions provided in LISP and that's been a real eye opener!

I just did problem 2 with a loop recur to generate fibonacci numbers. Yay me!

Thanks again, Chris!
Eugene Gunov
Greenhorn

Joined: Feb 09, 2011
Posts: 3
Regarding exercises - there are also 99 Lisp problems
Elchin Asgarli
Ranch Hand

Joined: Mar 08, 2010
Posts: 222

Try getting any university materials that teach about functional programming, cause even if the language is different, the concepts are the same. We've been learning SML in our university, however I am sure I after learning the syntax, I could equally well program in Clojure or any other functional language.


Personal page, SCJP 6 with 91%, SCWCD 5 with 84%, OCMJD
Matthew Lucas
Greenhorn

Joined: May 24, 2011
Posts: 4

Check out

http://4clojure.com

It's an addictive site with a ton of Clojure challenges.
Kurt Van Etten
Ranch Hand

Joined: Sep 07, 2010
Posts: 98
The classic college text for learning to think functionally is "Structure and Interpretation of Computer Programs" by Harold Abelson and Gerald Sussman. They use the Scheme dialect of Lisp in their book. There are also videos on YouTube of the course taught by Abelson and Sussman, which are worth taking a look at.
Igor Mechnikov
Ranch Hand

Joined: Feb 13, 2011
Posts: 100

Kurt Van Etten wrote:The classic college text for learning to think functionally is "Structure and Interpretation of Computer Programs" by Harold Abelson and Gerald Sussman. They use the Scheme dialect of Lisp in their book. There are also videos on YouTube of the course taught by Abelson and Sussman, which are worth taking a look at.


There is also a Cal Berkeley course teaching SICP http://www-inst.eecs.berkeley.edu/~cs61a/sp11/ with several years worth of lectures available on YouTube.
I was happy to try just now clojure koans and 4clojure.com but getting strange results with examples, f.e. false on (= (- 10 (* 2 3)) 4) on 4clojure, while (= false (= 2.0 2)) is seemingly accepted in the koans.


String knock = "\u042F \u0418\u0433\u043e\u0440\u044c";
Stian Almaas
Ranch Hand

Joined: Sep 22, 2005
Posts: 33
Matthew Lucas wrote:Check out

http://4clojure.com

It's an addictive site with a ton of Clojure challenges.


Thanks Matthew. I believe I have heard of it before but you made me go over and have a look. Great fun!
 
Don't get me started about those stupid light bulbs.
 
subject: Thinking functionally
 
Similar Threads
Is "The Joy of Clojure" for beginners?
Clojures killer app
Creating a cartesian product with to lists
Why Lisp is called "hackers language"?
What's new in "Clojure in Action"?