This file contains 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 org.enrico_franchi.paip.simplegrammar.grammar | |
(:use clojure.core)) | |
(def *simple-grammar* | |
'((sentence -> (noun-phrase verb-phrase)) | |
(noun-phrase -> (Article Noun)) | |
(verb-phrase -> (Verb noun-phrase)) | |
(Article -> the a) | |
(Noun -> ball man woman table) | |
(Verb -> hit took saw liked))) |
This file contains 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 lazier.bench | |
(:use clojure.core | |
[clojure.contrib.str-utils :only (re-sub str-join)] | |
clojure.contrib.pprint)) | |
(defn slow-computation [& more] | |
(Thread/sleep 500) | |
(if (seq more) more 1)) | |
(defmacro benchmark |
This file contains 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
initial_state(mc, mc(left, bank(3,3), bank(0,0))). | |
final_state(mc(right, bank(0,0), bank(3,3))). | |
move(mc(left, L, _R), Boat) :- | |
choose_passengers(L, Boat). | |
move(mc(right, _L, R), Boat) :- | |
choose_passengers(R, Boat). | |
choose_passengers(bank(C, _M), boat(2, 0)) :- | |
C > 1. |
This file contains 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
(defmacro mdef [keys values] | |
`(do | |
~@(loop [keys keys, values values, forms ()] | |
(if (seq keys) | |
(recur (rest keys) (rest values) | |
(cons `(def ~(first keys) ~(first values)) | |
forms)) | |
forms)))) | |
(mdef [a b c] [1 2 3]) |
This file contains 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 -initialize [this params] | |
(let-array [ | |
{:keys [is-starting-node connections-on-spawn starting-nodes] | |
:or {is-starting-node false} | |
:as options} params] | |
(dosync (alter (.state this) merge options)) | |
true)) |
This file contains 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
(defmacro unpack-parameters [params keys defaults & body] | |
`(let [{:keys ~keys :or ~defaults} | |
(apply hash-map (interleave (map keyword '~keys) ~params))] | |
~@body)) |
This file contains 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 -initialize [this params] | |
(dosync | |
(alter (.state this) assoc :starting-node false) | |
(alter (.state this) assoc :m-value (int *m*)) | |
(alter (.state this) assoc :logger | |
(Logger/getLogger (->> this .getAddress .getName)))) | |
(condp = (alength params) | |
0 true | |
1 (dosync | |
(alter (.state this) assoc :starting-node (boolean (aget params 0))) |
This file contains 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 -initialize [this params] | |
(dosync | |
(alter (.state this) merge | |
(unpack-parameters | |
params | |
[:is-starting-node :connections-on-spawn :starting-nodes] | |
(array-map :is-starting-node false)))) | |
true) |
This file contains 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
# Copyright (C) 2011 by Enrico Franchi | |
# | |
# This file is released under the terms of the MIT license | |
# http://www.opensource.org/licenses/mit-license.php | |
import itertools as it | |
def silence_generator_already_executing(generator): | |
try: | |
for element in generator: |
This file contains 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
<?xml version="1.0" encoding="UTF-8"?> | |
<project name="module_clojure" default="compile.module.clojure"> | |
<dirname property="module.hdsnetsym.basedir" file="${ant.file.module_clojure}"/> | |
<target name="compile.module.clojure" description="Compile clojure scripts of ..."> | |
<java classname="clojure.lang.Compile"> | |
<classpath> | |
<path location="${current_module.output.dir}"/> |
NewerOlder