Starting from:
lein new foo
cd foo
Say I have a random JAR file that is not available in any repository:
touch README.md
For each Ruby module/class, we have Ruby methods on the left and the equivalent | |
Clojure functions and/or relevant notes are on the right. | |
For clojure functions, symbols indicate existing method definitions, in the | |
clojure namespace if none is explicitly given. clojure.contrib.*/* functions can | |
be obtained from http://github.com/kevinoneill/clojure-contrib/tree/master, | |
ruby-to-clojure.*/* functions can be obtained from the source files in this | |
gist. | |
If no method symbol is given, we use the following notation: |
class TodoList < Array | |
def self.load(file) | |
# read the file, create a list, create items, add them to the list, return the list | |
list = TodoList.new | |
File.read(file).each_line do |line| | |
list << line.chomp | |
end | |
list | |
end |
;; | |
;; NS CHEATSHEET | |
;; | |
;; * :require makes functions available with a namespace prefix | |
;; and optionally can refer functions to the current ns. | |
;; | |
;; * :import refers Java classes to the current namespace. | |
;; | |
;; * :refer-clojure affects availability of built-in (clojure.core) | |
;; functions. |
(ns one-lineres) | |
;; 1. Multiple Each Item in a List by 2 | |
(map #(* 2 %) (range 1 11)) | |
;; 2. Sum a List of Numbers | |
(reduce + (range 1 1001)) | |
;; 3. Verify if Exists in a String | |
(def words #{"scala" "akka" "play framework" "sbt" "typesafe"}) |
; A REPL-based, annotated Seesaw tutorial | |
; Please visit https://github.com/daveray/seesaw for more info | |
; | |
; This is a very basic intro to Seesaw, a Clojure UI toolkit. It covers | |
; Seesaw's basic features and philosophy, but only scratches the surface | |
; of what's available. It only assumes knowledge of Clojure. No Swing or | |
; Java experience is needed. | |
; | |
; This material was first presented in a talk at @CraftsmanGuild in | |
; Ann Arbor, MI. |
folder="bin/classes/" | |
package="$1" | |
inotifywait -m -q -e close_write "$folder" | while read f; do | |
# take only the filename | |
f=`awk '{print $3}' <<< "$f"` | |
# rebuild the full path | |
path="$folder$f" |
(use 'clojure.core.async) | |
(defprotocol ISendable | |
(channel [this])) | |
(defn async-agent [state] | |
(let [c (chan Long/MAX_VALUE) ;; <<-- unbounded buffers are bad, but this matches agents | |
a (atom state)] | |
(go-loop [] | |
(when-let [[f args] (<! c)] |
/** | |
* ``` | |
* Does JDK8's Optional class satisfy the Monad laws? | |
* ================================================= | |
* 1. Left identity: true | |
* 2. Right identity: true | |
* 3. Associativity: true | |
* | |
* Yes, it does. | |
* ``` |
(ns foo.core | |
(:refer-clojure :exclude [slurp])) | |
(defmacro slurp [file] | |
(clojure.core/slurp file)) | |
;; In CLJS | |
(ns bar.core | |
(:require [foo.core :include-macros true :refer [slurp]])) |