サクサク読めて、アプリ限定の機能も多数!
トップへ戻る
iPhone 16
clj-me.cgrand.net
Thanks to Mark Engelberg there’s now a nice priority map in contrib. With such a facility, it becomes really easy to write a nice implementation of the A* algorithm. (ns net.cgrand.clj-me.a-star (:use [clojure.contrib.priority-map :only [priority-map]])) (defn A* "Finds a path between start and goal inside the graph described by edges (a map of edge to distance); estimate is an heuristic for the a
Follow up See here. Update: I was wrong and Rich Hickey set me right: I didn’t measure the gains I’m expecting because the inline-expanded form still go through the var lookup. See here (or the comments) for real gains (around 800ms on my laptop). This is a quick and dirty hack to emulate primitive types support for globally-bound fns: (defmacro defhintedfn [name args & body] (let [iface (gensym "
This morning I wrote some code which looked like: (reduce (fn [acc x] (reduce (fn [acc y] (reduce f acc y)) acc x)) init xs) (it was slightly more complex with some filtering and destructuring thrown in for good measure). I wasn’t happy with those nested reduces and it occured to me that I could refactor it to use a single one: (reduce f init (for [x xs, y x, z y] z)) Now that reads better! 34 Com
Utilities (defn array? [x] (-> x class .isArray)) (defn see [x] (if (array? x) (map see x) x)) Creation Blank and rectangular: (see (make-array Double/TYPE 3 2)) ; ((0.0 0.0) (0.0 0.0) (0.0 0.0)) From a nested collection: (see (into-array (map (partial into-array Double/TYPE) [[1 2 3 4] [5 6]]))) ; ((1.0 2.0 3.0 4.0) (5.0 6.0)) Reading A multidim array: (def dd (make-array Double/TYPE 1000 1000))
このページを最初にブックマークしてみませんか?
『Clojure and me』の新着エントリーを見る
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く