Skip to content

Instantly share code, notes, and snippets.

View edipofederle's full-sized avatar
🏠
Working from home

Édipo Féderle edipofederle

🏠
Working from home
View GitHub Profile
(clojure.core/use 'clojure.core)
myproject=> (File/separator)
CompilerException java.lang.RuntimeException: No such namespace: File, compiling:(NO_SOURCE_PATH:5)
myproject=> (java.io.File/separator)
"/"
myproject=>
myproject=> (clojure.core/use 'clojure.core)
nil
myproject=> (import '(java.io InputStream File))
java.io.File
(ns blog.explorandoclojure
(:use blog.utils clojure.contrib.str-utils) (:import (java.io File)))
public class Math {
public static void Main(String[] args) {
float raio = 75;
System.out.println(areaCirculo(raio));
}
private static double areaCirculo(float raio) {
return 3.14 * (raio * raio);
}
private static double areaCirculo(float raio) {
if(raio == null)
// NullPointerException
return 3.14 * (raio * raio);
}
public void doSomeThing(){
Client client = service.findClientById("1103"); // Pode dar NPE
if(client == null)
// Faça alguma coisa.
String name = client.getName(); // Ops, sem checar por null. NPE
}
@edipofederle
edipofederle / gist:3766711
Created September 22, 2012 16:46
square.java
public static List<Double> squareList(List<Double> in){
List<Double> out = new ArrayList<Double>();
for (Double d : in)
out.add(d*d);
return out;
}
@edipofederle
edipofederle / gist:3766723
Created September 22, 2012 16:49
square.hs
square :: [Double] -> [Double]
square (x:xs) = x*x : square xs
square [] = []
@edipofederle
edipofederle / gist:3772052
Created September 23, 2012 15:34
square2.hs
import Test.QuickCheck
import Data.List
square :: [Double] -> [Double]
square (x:xs) = x*x : square xs
square [] = []
-- testing
prop_test1 xs = not(null xs) ==> map(1*) ( square xs ) == map (\x -> x * x) xs