Skip to content

Instantly share code, notes, and snippets.

View cgrand's full-sized avatar

Christophe Grand cgrand

View GitHub Profile
package clojure.lang;
public interface ISetNode {
public static class Utils {
static public int bitpos(int hash, int shift){
return 1 << mask(hash, shift);
}
static public int index(int bit, int bitmap){
return Integer.bitCount(bitmap & (bit - 1));
<?xml version="1.0" encoding="UTF-8"?>
<site>
<description url="http://clojure-dev.googlecode.com/svn/updatesite/">
Clojuredev Update Site. Clojuredev is an Eclipse feature supporting the development of clojure code
</description>
<feature url="features/clojuredev.feature_0.0.20.jar" id="clojuredev.feature" version="0.0.20">
<category name="Clojure Programming"/>
</feature>
<category-def name="Clojure Programming" label="Clojure Programming">
<description>
(grammar
[number [#{"0" "1" "2"}+]
expr #{number ["(" sum ")"]}
sum [prod ["+" prod]*]
prod [expr ["*" expr]*])
(def simple-lisp
(parser
{:main [[:w ? :expr]* :w ?]
:expr #{:symbol ["("[:w ? :expr]* :w ? ")"]}
:symbol #"\w+"
:w #"\s+"}))
;; helper functions to display results in a more readable way
(defn terse-result [[items _]]
(map (fn self [item]
(defn walk-out [customer]
(ref-set customer :outside))
(defn wait [customer {q :queue}]
(alter q conj customer)
(ref-set customer :waiting))
(defn sleeping? [barber]
(= :sleeping (ensure barber)))
;; a better version of http://bestinclass.wordpress.com/2009/09/17/scala-vs-clojure-round-2-concurrency/
(def empty-seats (ref 3))
(def barber (agent 0))
(defn debug [msg n]
(println msg (apply str (repeat (- 35 (count msg)) \space)) n)
(flush))
(defn cut-hair [tally n]
(dosync (commute empty-seats inc))
;; philosophers must be initialized to 0
(defn behave [qty id]
(when (pos? @rounds) (send-off *agent* behave id))
(or
(dosync ; Initiate transaction
(when (and
(pos? @rounds) ; Is there more food?
(> 5 (rand-int 10)) ; Do I want to eat or think?
(got-forks? id)) ; Are both of my forks available?
(require 'clojure.main)
(defn file-repl [filename]
(let [log (java.io.FileWriter. filename)
logout (fn [#^java.io.Writer out]
(proxy [java.io.Writer] []
(write
([x]
(.write log x)
(.write out x))
(def board
(-> (vec (repeat 5 (vec (repeat 5 :off))))
(assoc-in [0 0] :on)
(assoc-in [0 1] :on)
(assoc-in [1 2] :on)))
(defn neighbors-on [above [left _ right] below]
(count (filter #{:on} (concat above [left right] below))))
(defn torus-windows [coll]
<html>
<head>
<meta name="parent" content="layout"/>
</head>
<body>
<col1><div>ccol1</div></col1>
<col2><div>ccol2</div></col2>
<col3><div>ccol3</div></col3>
</body>
<html>