Functions, Lists, Input, Output.

I paired with Daisy on the roman numerals Kata in Clojure. Daisy doesn’t have much experience with Lisp or Clojure, so this was a great opportunity for me to teach someone a language that I had recently been learning.

The first thing that I felt was important to cover is parenthesis..(there’s so many of them!). Okay while they’re important (meaning lost minutes would attest), there are four concepts that are more important.

Those are…….

Functions,  Lists, Input, Output.

When tackling a problem, think of these four and they will lead you to a possible solution.

These four concepts aren’t in complete isolation of each other, they connect and flow between.

A rudimentary example of adding a number to a list of our favourite numbers.

“`clojure

(def my-favourite-number [7 11 24 50 100])

(cons 5 my-favourite-numers)

““

It contains a function called “cons” that takes a number and a list as an an input. Finally outputs the result.

We of course could also have a function that takes another function as an input, such as the map function which takes a functions as an input and returns a collection as it’s output.

There are many examples out. Thinking in this approach has helped me a lot in understand functional programming and clojure.

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s