Question

I have been experimenting with functional programming and I still dont understand the concept. Do you guys know any good books or tutorials or examples that discuss this concept? Or if you could show small snippets about its usage, that would be great.

Was it helpful?

Solution

I believe that Why Functional Programming Matters by John Hughes is one of the best.

OTHER TIPS

Learn lisp or scheme. The language is the datastructure is the language. Lisp code and Lisp data structures have the same syntax rules.

If you learn tcl, you can work with a language that's procedural and the data structure syntax rules are the same as the programming language syntax rules.

It's not -- strictly speaking -- a functional programming issue. It's more an issue with a few languages where the syntax rules for data and the syntax rules for the language are the same.

REBOL is a homoiconic language. The block! datatype in REBOL is a set of square brackets within which are any valid REBOL tokens, similar to an S-expression in Lisp. For instance:

series: [1 2 3 4]
foreach item series [
    print item
]

Now, let's express that a little differently:

series: [1 2 3 4]
for-body: [print item] ; This is the body of our foreach
foreach item series for-body

Though it was declared as data, we treated the block for-body as code when we passed it to the foreach function. If we ask REBOL what the type of the first item in the block for-body is — type? first for-body — it will tell us word! and not function! (or native! or action! or any of the other REBOL function types). The reason is that as data, for-body is just an unevaluated chunk of REBOL words. When we pass it to foreach only then does it get evaluated as code.

Some have called REBOL "like Lisp but without the parentheses" and I personally prefer it to Lisp, but you may not. Still, it's a great language to start with when you want to learn about homoiconicity, a subject I find fascinating.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top