This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (clojure.core/use 'clojure.core) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| myproject=> (File/separator) | |
| CompilerException java.lang.RuntimeException: No such namespace: File, compiling:(NO_SOURCE_PATH:5) | |
| myproject=> (java.io.File/separator) | |
| "/" | |
| myproject=> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| myproject=> (clojure.core/use 'clojure.core) | |
| nil | |
| myproject=> (import '(java.io InputStream File)) | |
| java.io.File |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (ns blog.explorandoclojure | |
| (:use blog.utils clojure.contrib.str-utils) (:import (java.io File))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private static double areaCirculo(float raio) { | |
| if(raio == null) | |
| // NullPointerException | |
| return 3.14 * (raio * raio); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static List<Double> squareList(List<Double> in){ | |
| List<Double> out = new ArrayList<Double>(); | |
| for (Double d : in) | |
| out.add(d*d); | |
| return out; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| square :: [Double] -> [Double] | |
| square (x:xs) = x*x : square xs | |
| square [] = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |