Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get my brain moving in "lisp mode?"

My professor told us that we could choose a programming language for our next programming assignment. I've been meaning to try out a functional language, so I figured I'd try out clojure. The problem is that I understand the syntax and understand the basic concepts, but I'm having problems getting everything to "click" in my head. Does anyone have any advice? Or am I maybe picking the wrong language to start functional programming with?

like image 832
Jason Baker Avatar asked Mar 03 '09 14:03

Jason Baker


4 Answers

It's a little like riding a bike, it just takes practice. Try solving some problems with it, maybe ProjectEuler and eventually it'll click.

Someone mentioned the book "The Little Schemer" and this is a pretty good read. Although it targets Scheme the actual problems will be worth working through.

Good luck!

like image 190
Sean Avatar answered Nov 04 '22 06:11

Sean


Well, for me, I encountered the same problem as you do in the beginning when I started doing OCAML, but the trick is that you must start thinking about what you want from the code and not how to do it!!!

For example, to calculate the square of list's elements, forget about the length of the list and such tricks, just think mathematically like that:

  • if the list is empty -> I am done

  • if not, then the list must have a head and tail -> you calculate the square of the head, then ask your function to do the same with the tail.

Just think about the general case and the base one, and that you are emitting data and not modifying it (unless you want to modify it ;) ).

Good luck!

like image 34
0xFF Avatar answered Nov 04 '22 06:11

0xFF


You could check out The Little Schemer.

like image 6
Andrew Hare Avatar answered Nov 04 '22 04:11

Andrew Hare


How about this: http://www.defmacro.org/ramblings/lisp.html

It is a very simple, step-by-step introduction to thinking in lisp from the point of view of a regular imperative programmer (Java, C#, etc.).

like image 5
Joshua Hayworth Avatar answered Nov 04 '22 05:11

Joshua Hayworth