Posts

Showing posts from January, 2017

SICP in Clojure: Chapter 2 (part 1)

Going on with my study of SICP, this is the first part of chapter 2 (that is a very big chapter and also has a lot of great examples). I also updated the code in the first chapter for some issues with chapter 2 names that were replicated (I made some private definitions there to use refer all here). The painter example of this book was really cool and actually you can create a painter with Quil library if you want to see it works. (ns sicp.chapter-2 (:require [sicp.chapter-1 :refer :all])) ;Common functions (defn null? [l] (and (seq? l) (empty? l))) ;Chapther 2: Building Abstractions with Data (defn linear-combination [a b x y] (+ (* a x) (* b y))) (declare add mul) (defn linear-combination [a b x y] (add (mul a x) (mul b y))) ;Chapter 2.1.1 (declare make-rat numer denom) (defn add-rat [x y] (make-rat (+ (* (numer x) (denom y)) (* (numer y) (denom x))) (* (denom x) (denom y)))) (defn sub-rat [x y] (make-rat (- (* (numer x) (denom y))

What Clojure is missing...

Ok, now I have played with Clojure for a lot of time. I know how to write clojure programs, how to write in a functional style (on a base-medium level). What is my main work, what kind of applications I build for my company... Web Applications, batch programs for some heavy computations. Our main application is built with Grails, and I can't say that I'm am so found on Grails..... buuut .... Lately I built a web app to handle the deployment through Docker of our Web Application and I was thinking about using Clojure. This is how the discussion went (more or less): Marco : "I would like to use Clojure, is great, it gives immediate feedback and I would like to try because I feel I can do a good job" Other People  (in this company before starting we discuss pro and contro of every decision): "Mmm I heard of it.. yes it can be an idea, but what are you going to use, what is the standard. Let's say that you start the application and then you have to move on

SICP in Clojure: Chapter 1

With a new year some new objectives should be set. Learn French Understand better functional programming Use Clojure in a real project (if you need help in some real project let me know :) ) This post is about the 2nd point. To learn more about functional programming I'm reading  Structure and Interpretation of Computer Programs .  This is really a great book but all the examples are in Lisp. To make it more actual I'm rewriting all the examples in clojure (and some exercises too).    I think it can be useful to others too, so here it is chapter 1: (ns sicp.chapter-1) ;1.1 Expressions (+ 137 349) (- 1000 334) (* 5 99) (/ 10 5) (+ 2.7 10) (+ 21 35 12 7) (* 25 4 12) (+ (* 3 5) (- 10 6)) (+ (* 3 (+ (* 2 4) (+ 3 5))) (+ (- 10 7) 6)) (+ (* 3 (+ (* 2 4) (+ 3 5))) (+ (- 10 7) 6)) ;1.2 Naming and the Environment (def size 2) size (* 5 size) (def pi 3.14159) (def radius 10) (* pi (* radius radius)) (def circumference (* 2 pi radius)) circumferenc