Skip to content

Instantly share code, notes, and snippets.

View syou6162's full-sized avatar

Yasuhisa Yoshida syou6162

View GitHub Profile
(defn mapmap
"Return a new map, mapping keys to (keyfn key) and mapping values to
(valfn val)"
([valfn map]
(mapmap identity valfn map))
([keyfn valfn map]
(persistent! (reduce
(fn [c [k v]] (assoc! c (keyfn k) (valfn v)))
(transient {})
map))))
@condotti
condotti / gist:845081
Created February 26, 2011 09:41
An advice for paredit in lisp-interaction-mode.
(defadvice paredit-newline (around eval-print-last-sexp activate)
(if (eq major-mode 'lisp-interaction-mode)
(eval-print-last-sexp)
(paredit-newline)))
@nathanmarz
nathanmarz / gist:1350522
Created November 9, 2011 05:38
Optimized variance in Cascalog
(defn one [] 1)
(defn div [v1 v2]
(float (/ v1 v2)))
(defparallelagg count
:init-var #'one
:combine-var #'+)
(defparallelagg sum-parallel
@daveray
daveray / seesaw-repl-tutorial.clj
Created December 7, 2011 04:55
Seesaw REPL Tutorial
; 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.
@AlexBaranosky
AlexBaranosky / gist:2233328
Created March 29, 2012 04:36
state monad as a way to hold 'world' state
(defmacro defworld [name bindings & body]
`(defn ~name ~bindings
(fn [~'world]
(println ~'world)
~@body)))
(defmacro with-world [& body]
`(domonad state-m
~@body))
@mnzk
mnzk / with-open-zipfile.clj
Created March 31, 2012 09:58
with-open-zipfile.clj
(defmacro with-open-zipfile
[bindings & body]
(let [bindings# (->> bindings
(mapncat 2 (fn [v f]
`(~v (java.util.zip.ZipFile. ~f))))
(into []))]
`(with-open ~bindings# ~@body)))
;; example
@Melipone
Melipone / viterbi.clj
Created April 4, 2012 14:26
Viterbi algorithm
(ns ident.viterbi
(:use [clojure.pprint]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Example
;; (def initpr (to-array [0.6 0.4]))
;; (def transpr (to-array-2d [[0.7 0.3][0.4 0.6]]))
;; (def emisspr (to-array-2d [[0.1 0.4 0.5][0.6 0.3 0.1]]))
;; (def hmm (make-hmm {:states ["rainy" "sunny"] :obs ["walk" "shop" "clean"] :init-probs initpr :emission-probs emisspr :state-transitions transpr}))
;; optimal state sequence and probability of sequence
@nathanmarz
nathanmarz / gist:2506020
Created April 27, 2012 05:03
Concise inline operations with Cascalog serfn branch
(use 'cascalog.playground) (bootstrap)
(require '[clojure.set :as set])
(require '[cascalog.vars :as v])
(defn all-syms [form]
(if (coll? form)
(reduce (fn [curr elem] (set/union curr (all-syms elem)))
#{}
form)
;
; STMの挙動を観察する
; スレッドを作るマクロ
; http://code.google.com/p/javaee-study/source/browse/trunk/clojure-concurrency/concurrency.clj?r=5
(import '(java.lang Thread))
(defmacro with-new-thread [& body]
`(.start (Thread. (fn [] ~@body))))
; 指定された値がTrueになるまでブロックするチェックポイント
@syou6162
syou6162 / Difference_between_cl_and_clojure.md
Created August 19, 2012 11:09
On Lispを読んでいて分からなかったCommon LispとClojureの違いについて自分なりにまとめていきます

Common Lispの関数

dolist

(dolist (var init-form result) S式 ... )

dolist は名前が示すように、リストに関係があります。最初に init-form を評価します。このとき、評価結果はリストでなければいけません。リスト以外の場合はエラーとなります。dolist は、このリストの要素を順番に変数 var に代入して S 式を評価します。リストの要素がなくなったら result を評価し、その値が dolist の返り値になります。次の例を見てください。