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 dojo-coding-0.core | |
(:use [clojure.test :only [run-tests]]) | |
(:use [midje.sweet]) | |
(:use [clojure.contrib.repl-utils :only [show]]) | |
(:use [clojure.pprint :only [pprint]]) | |
(:use [clojure.walk :only [macroexpand-all]])) | |
(defn prime-numbers "Return the list of the n first prime numbers" | |
[n] | |
(loop [candidate 2 current n primes []] |
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
(defpartial site-layout [& content] | |
(html5 | |
[:head | |
[:title "my site"] | |
(include-css "/css/some-css-file.css" | |
(include-js "/js/some-js-file.js"] | |
[:body | |
[:div#wrapper content]])) |
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
(defpage "/my-page" [] | |
(common/site-layout | |
[:h1 "Hello world!"] | |
[:p "loremipsum..."])) |
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
(defpage "/my-page" [] | |
(common/site-layout | |
[:h1 "Hello world!"] | |
[:p "loremipsum..."])) |
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
;; 0 represents short signal | |
;; 1 represents long signal | |
;; Intermational morse from http://en.wikipedia.org/wiki/Morse_code | |
(def letters-2-bits {\a [0 1] | |
\b [1 0 0 0] | |
\c [1 0 1 0] | |
\d [1 0 0] | |
\e [0] | |
\f [0 0 1 0] | |
\g [1 1 0] |
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 short-pulse 100) | |
(def long-pulse 250) | |
(def letter-delay 500) | |
;; pin number | |
(def pin-led 13) | |
;; functions | |
(defn blink |
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 write-morse | |
"Given a word, make the led blink in morse for each letter (no upper case, no punctuation)" | |
[board word] | |
(doseq [l word] | |
(blink-letter board (m/letters-2-bits l)))) |
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 device-board "/dev/ttyACM0") | |
;; this is a limitation on the underlying lib clodiuno uses. Indeed, it searches only for /dev/ttySxx serial devices | |
;; and on ubuntu GNU/Linux it's named /dev/ACM0 | |
(System/setProperty "gnu.io.rxtx.SerialPorts" device-board) | |
;; now declaring the board | |
(def board (arduino :firmata device-board)) | |
;; the led must be set in output mode |
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
;; time | |
(def short-pulse 100) | |
(def long-pulse 250) | |
(def letter-delay 500) | |
;; pin number | |
(def pin-led 13) | |
(defn blink "Given a board and time, make the led blink a given time" | |
[board time] |
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
(use '[clojure.core.match :only [match]]) | |
(defn evaluate [env [sym x y]] | |
(match [sym] | |
['Number] x | |
['Add] (+ (evaluate env x) (evaluate env y)) | |
['Multiply] (* (evaluate env x) (evaluate env y)) | |
['Variable] (env x))) | |
(def environment {"a" 3, "b" 4, "c" 5}) |
OlderNewer