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
// CLASS 4 WEEK 1 LAB | |
// ============================================================ | |
// Define a function maxOfTwoNumbers that takes two numbers as | |
// arguments and returns the largest of them. starter code: | |
var maxOfTwoNumbers = function(a, b){ | |
// return the greater number, a or b | |
}; |
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
var m = require('mori'); | |
function uniquify(coll){ | |
var seen = m.set(); | |
var retval = m.reduce( | |
function(bldg, x){ | |
if(m.hasKey(seen, x)){ | |
return bldg; | |
}else{ | |
seen = m.conj(seen, x); |
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 vector-insert [v1 v2 i] | |
(let [c1 (count v1) | |
c2 (count v2) | |
c3 (+ c1 c2)] | |
(persistent! | |
(loop [j i, v3 (transient v1)] | |
(cond | |
(< j (+ i c2)) | |
(recur | |
(inc j) |
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
(defrecord ObliqueSnoozler []) | |
(ObliqueSnoozler.) | |
;; System.TypeInitializationException: An exception was thrown by the type initializer for user.ObliqueSnoozler ---> System.NullReferenceException: Object reference not set to an instance of an object | |
;; at clojure.lang.Compiler.TryLoadInitType (System.String relativePath) [0x00000] in <filename unknown>:0 | |
;; at clojure.lang.RT.load (System.String relativePath, Boolean failIfNotFound) [0x00000] in <filename unknown>:0 | |
;; at clojure.lang.RT.load (System.String relativePath) [0x00000] in <filename unknown>:0 | |
;; at clojure/core$load$fn__5867__5871.invoke () [0x00000] in <filename unknown>:0 | |
;; at clojure/core$load__5874.doInvoke (System.Object ) [0x00000] in <filename unknown>: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 v (volatile! nil)) | |
;; a function that I don't think will get disappeared by the compiler: | |
(defn bla [x] | |
(vreset! v x)) | |
(def stuff (vec (range 5e5))) | |
(defmacro do-reduce [[x coll] & body] | |
`(do |
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
(require '[clojure.core.async :as a]) | |
(import | |
'[java.nio.file FileSystems WatchService Files Paths Path LinkOption NotDirectoryException WatchKey | |
StandardWatchEventKinds]) | |
(defmacro async-pause [time] | |
`(a/<! (a/timeout ~time))) | |
;; wow java | |
(defn watch-directory [dir f opts] ;; only works for directories, because of fascism |
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 flumbum | |
(:use clojure.pprint clojure.repl)) | |
;; ================================================== | |
;; logging erotica | |
(def logs (atom {} :validator #(every? var? (keys %)))) | |
(defmacro deflog [name & body] | |
`(let [f# (fn [] ~@body) |
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
(defprotocol IRobot ; ha | |
(live? [_]) | |
(kill [_]) | |
(state [_])) | |
(defn robot | |
([state f] | |
(robot state (constantly true) f)) | |
([state continue? f] | |
(let [kill (a/chan (a/sliding-buffer 1)) |
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
;; feed in a traverse function; here's where you define the meaning of | |
;; the tree and so on, similar to the three zipper functions (that is, branch?, | |
;; children, make-node) | |
(defn trav-1 [x xfrm] | |
(if (coll? x) | |
(into (empty x) xfrm x) | |
x)) | |
;; terse: | |
(defn prewalk [x f traverse] |
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
<!doctype html> | |
<html><body><div><style></style></div><div style="font-family: sans-serif; | |
width: 100%; | |
margin-top: 1em; | |
margin-bottom: 1em; | |
"><div style="text-align: center; | |
max-width: 1000px; | |
width: 100%; | |
margin-right: auto; |