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
| (dispatch-reader-macro \X xml-reader) | |
| #X" | |
| <compras> | |
| <item> | |
| <batata> | |
| <preco>1.23</preco> | |
| </batata> | |
| </item> | |
| </compras>" |
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
| ;; aqui eu crio um agent com o valor 1 e chamo de x | |
| (def y (agent 1)) | |
| ;; nossa função vai levar dez segundos a cada processamento | |
| (defn triple [c] | |
| (println "valor inicial:" c) | |
| (Thread/sleep 10000) | |
| (println "terminei") | |
| (* c 3)) |
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
| ;; Primeiro criamos um agent a | |
| (def a (agent 1)) | |
| ;; A função watch deve ter quatro parâmetros: uma chave única, | |
| ;; a referência ao próprio agent, o valor antigo e o valor novo. | |
| (defn a-watch [key ref old new] | |
| (println "Watching" key ref old new)) | |
| ;; vamos criar uma função que dobra o valor recebido e informa | |
| ;; quando está sendo executada |
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
| (defn random-number [_] | |
| (rand-int 22)) | |
| (defn a-validate [valor] | |
| (> valor 10)) | |
| (defn a-errorhandler [ag ex] | |
| (println "Error: " (.getMessage ex))) | |
| (defn a-watcher [ref chave antigo novo] |
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
| (def numeros (range 0 10000)) | |
| (def vetor (into-array Long/TYPE numeros)) | |
| (defmacro benchmark [code] | |
| `(time (first (doall (repeatedly 1000 (fn [] ~code)))))) | |
| (benchmark (reduce + numeros)) | |
| ; "Elapsed time: 123.946807 msecs" |
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
| #!/bin/sh | |
| cd /home/amanda/Downloads | |
| rm -rf /opt/jvm | |
| rm -rf jre1.8.0_45 | |
| mkdir /opt/jvm | |
| tar -zxf jre-8u45-linux-i586.tar.gz -C /opt/jdk |
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
| // Expectation: [1, 8, 6, 4, 3, 5, 7, 2] | |
| var teams = [1, 2, 3, 4, 5, 6, 7, 8]; | |
| var matches = []; | |
| for(var pos = 0; pos < teams.length / 2; pos++) | |
| { | |
| var even = pos % 2 === 0; | |
| var ta = teams[pos]; | |
| var tb = teams[(teams.length - 1) - pos]; |
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
| ;; comentários iniciados com dois ; são explicações minhas | |
| ; comentários iniciados com um ; é mensagem impressa pelo código | |
| ;; um atom é uma estrutura de dados quer permite modificações atômicas | |
| ;; de valor de forma segura e síncrona em um ambiente multithread. | |
| ;; aqui definimos um atom com valor inicial 0 | |
| (def c (atom 0)) | |
| (defn incx |
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
| ;; Demonstrando a criação de interfaces Java e seu uso no Clojure | |
| (definterface Poligono | |
| (^String nome []) | |
| (arestas []) | |
| (^long vertices []) | |
| (^double perimetro []) | |
| (^double area [])) | |
| (defn criar-quadrado [^double lado] |
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
| #include <iostream> | |
| #include <Windows.h> | |
| #include <string> | |
| namespace windows_threads | |
| { | |
| class THREAD_PARAM | |
| { | |
| public: | |
| std::string name; |