Skip to content

Instantly share code, notes, and snippets.

@mango314
Last active August 29, 2015 13:55
Show Gist options
  • Save mango314/8731875 to your computer and use it in GitHub Desktop.
Save mango314/8731875 to your computer and use it in GitHub Desktop.
Review of Clojure Meetup at PR Science Trust
; greatest common divisor
(defn gcd [a b]
(if (= b 0)
a
(gcd b (rem a b))))
; > (gcd 15 25)
; > 5
; http://mitpress.mit.edu/sicp/full-text/sicp/book/node19.html
(define (gcd a b)
(if (= b 0)
a
(gcd b (remainder a b))))
; > (gcd 15 25)
; 5

¿ What is Functional Programming ?

In our meetup, programmers and non-programmer alike sat down and read through the Clojure docs to understand how functional programming could help us.

Why FP ?

  • As a data scientist I have found it useful to describe complex transformations. Twitter currently uses Scala.
  • Potential alternative to Java (for Android) or JavaScript (for web development)

Why Pick Clojure ?

Tutorials

The form 'foo is simply a faster way to type the special form (quote foo) which is to say, "do not evaluate the name foo and replace it with its value; I really mean the name foo".

For Programmers

For Data Scientists

D3 is written in JavaScript and C2 is written in Clojure. Clojure is a richer language than JavaScript, with features like destructuring, lazy evaluation, namespaces, and macros, which JavaScript does not provide. Since Clojure runs on the Java Virtual Machine, it’s possible to work with much larger data sets than JavaScript can handle, directly access datastores, and perform advanced computations (in parallel).

Spanish Punctuation Tutorial

  • ' comilla
  • " comillas
  • ; punto-y-coma
  • - guion
  • _ underscore

Credits

Thanks to Jośe Padilla @ Blimp for hosting is at Puerto Rico Science and Technology Trust.

Clojure

Clojure (pronounced like "closure"[3]) is a dialect of the Lisp programming language created by Rich Hickey. Clojure is a functional general-purpose language, and runs on the Java Virtual Machine, Common Language Runtime, and JavaScript engines. Like other Lisps, Clojure treats code as data and has a sophisticated macro system.

Clojure's focus on programming with immutable values and explicit progression-of-time constructs are intended to facilitate the development of more robust programs, particularly multithreaded ones.

Functional Programming

In computer science, functional programming is a programming paradigm, a style of building the structure and elements of computer programs, that treats computation as the evaluation of mathematical functions and avoids state and mutable data. Functional programming emphasizes functions that produce results that depend only on their inputs and not on the program state—i.e. pure mathematical functions. It is a declarative programming paradigm, which means programming is done with expressions...

Functional programming has its roots in lambda calculus, a formal system developed in the 1930s to investigate computability, the Entscheidungsproblem, function definition, function application, and recursion. Many functional programming languages can be viewed as elaborations on the lambda calculus, where computation is treated as the evaluation of mathematical functions and avoids state and mutable data...

In contrast, imperative programming changes state with commands in the source language, the most simple example is the assignment. Functions do exist, not in the mathematical sense, but the sense of subroutine. They can have side effects that may change the value of program state. Functions without return value therefore make sense. Because of this, they lack referential transparency, i.e. the same language expression can result in different values at different times depending on the state of the executing program.

Why not Functional Programming?

  • purists
  • too much extra work, Object Oriented Programming (OOP) works great
  • unreadable

Why not Clojure ?

  • maybe Scala?
  • Ruby?
  • Python?
  • Lisp is on its way out in favor of R and Julia
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment