This file contains 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
; nrepl.el 0.2.0 (Clojure 1.5.1, nREPL 0.2.1) | |
user> (use 'clojail.testers) | |
nil | |
user> (use 'clojail.core) | |
nil | |
user> (def mysb (sandbox secure-tester-without-def)) | |
#'user/mysb | |
user> (mysb '(range 10)) | |
(0 1 2 3 4 5 6 7 8 9) | |
user> (mysb '(range count)) |
This file contains 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 f [{:keys [mx acc]} x] | |
{:mx (max mx (+ acc x)) | |
:acc (max 0 (+ acc x))}) | |
(defn max-sum [v] | |
(:mx (reduce f {:mx 0 :acc 0} v))) | |
(max-sum [-1, 5, 6, -2, 20, -50, 4]) ;29 | |
(max-sum [-1, 5, 6, -2, 21, -50, 4, -100, 30, -100, 5, 8, -2, 20, -50, 4]) ;31 | |
(max-sum [-2, 1, -3, 4, -1, 2, 1, -5, 4]) ;6 |
This file contains 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
(add-hook 'js-mode-hook | |
(lambda () | |
(paredit-mode 1) | |
(local-set-key "{" 'paredit-open-curly) | |
(local-set-key "}" 'paredit-close-curly) | |
(local-set-key "\M-{" 'paredit-wrap-curly) | |
(local-set-key "\M-}" 'paredit-close-curly-and-newline) | |
(local-set-key "\M-[" 'paredit-wrap-square) | |
(local-set-key "\M-]" 'paredit-close-square-and-newline))) |
This file contains 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 m | |
[{:home "Manchester United" :away "Manchester City" :home_score 1 :away_score 0} | |
{:home "Manchester United" :away "Manchester City" :home_score 2 :away_score 0} | |
{:home "Manchester City" :away "Arsenal" :home_score 1 :away_score 1}]) | |
(def teams | |
{"Manchester United" {:points 1200} | |
"Manchester City" {:points 1200} | |
"Arsenal" {:points 1200}}) |
This file contains 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 lame[]) |
This file contains 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
;; works with core.logic 0.8.4 | |
(require '[clojure.core.logic :refer :all]) | |
(require '[clojure.core.logic.fd :as fd]) | |
(defn get-square [rows x y] | |
(for [x (range x (+ x 3)) | |
y (range y (+ y 3))] | |
(get-in rows [x y]))) | |
(defn init [vars hints] |
This file contains 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
(require '[clojure.core.logic :refer :all]) | |
(require '[clojure.tools.macro :as macro]) | |
(defne righto [x y l] | |
([_ _ [x y . ?r]]) | |
([_ _ [_ . ?r]] (righto x y ?r))) | |
(defn nexto [x y l] | |
(conde | |
((righto x y l)) |
This file contains 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
(require '[clojure.core.logic :refer :all]) | |
(require '[clojure.core.logic.fd :as fd]) | |
(defn sumo | |
([l n] (sumo l 0 n)) | |
([l acc n] | |
(matche [l] | |
([[]] (fd/== acc n)) | |
([[x . r]] | |
(fresh [nacc] |
This file contains 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 hello [x] | |
(println "Hello" x)) | |
(hello "name") |
This file contains 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
(let [q (ref []), x (ref 0)] | |
(defn run-side-effects [_] | |
(let [fs (dosync | |
(let [q' @q] | |
(ref-set q []) | |
q'))] | |
(doseq [f fs] (f)))) | |
(defn alter-and-order-side-effects [] | |
(dosync |