This file contains hidden or 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
(defun str (&rest args) | |
"Returns the concatenation of string values of the args. | |
With no or nil args, returns the empty string." | |
(with-output-to-string (s) | |
(dolist (arg args) (princ (or arg "") s)))) | |
(defmacro with-gensyms ((&rest names) &body body) | |
`(let ,(loop for n in names collect `(,n (gensym))) | |
,@body)) |
This file contains hidden or 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 set-root-logger-log-level! [log-level] | |
(let [root-logger (Logger/getLogger "") | |
console-handler (first (.getHandlers root-logger)) | |
date-formatter (java.text.SimpleDateFormat. "HH:mm:ss") | |
log-formatter (proxy [Formatter] [] | |
(format | |
[#^LogRecord record] | |
(str \return | |
(.format date-formatter (Date. (.getMillis record))) | |
\space (.getMessage record) \newline)))] |
This file contains hidden or 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 fn-or | |
"Объединение функций возвращает функцию эквивалентную | |
(fn [x] (or (f x) (g x) ... ) или | |
(fn [x & xs] (or (f x1 x2 ...) (g x1 x2 ...) ... )" | |
[f & fs] | |
(if-not fs f (let [chain (apply fn-or fs)] | |
(fn ([x] (or (f x) (chain x))) | |
([x & xs] (or (apply f x xs) (apply chain x xs))))))) | |
(defn seq-dispatch |
This file contains hidden or 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
;;; -*- mode: clojure; coding: utf-8 -*- | |
;;; author: Roman Zaharov <[email protected]> | |
(ns clojure.turing-machine.machine) | |
(in-ns 'clojure.turing-machine.machine) | |
(defn convert-rules [rules] | |
(apply conj [] (for [rule rules :let [[state read jump write move] rule]] | |
{:state state :read read :jump jump :write write :move move}))) |
This file contains hidden or 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 up [] (int (Math/pow -1 (inc (.nextInt (new java.util.Random) 2))))) | |
(first (filter (partial = 10) (iterate #(+ % (up)) 0))) | |
(let [position (atom 0) | |
movements (cycle [-1 1 1])] | |
(defn up1 [] | |
(reset! position (inc @position)) | |
(nth movements @position))) |
This file contains hidden or 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
(use 'clojure.test) | |
(defn same | |
"Returns true if (f x) returns same value for any x in coll." | |
[f coll] | |
(apply = (map f coll))) | |
(deftest same-test | |
(is (same :x [{:x nil} {:y nil}])) | |
(is (same :x [{:x 1} {:x 1 :y 2}])) |
This file contains hidden or 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 fn (:refer-clojure :exclude [not and or])) | |
(def not complement) | |
(defn and "Functions intersection." | |
([f] f) | |
([f & fs] (let [chain (apply and fs)] | |
(fn [& xs] (clojure.core/and (apply f xs) | |
(apply chain xs)))))) | |
This file contains hidden or 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 (power :is number? :or (throw 'Bad-input)) | |
[(x :is number?) | |
(y :is [pos? integer?]) | |
(n :is [pos? integer?] :is [neg? float?] :is [zero? double?] :or false)] | |
(/ x 0)) |
This file contains hidden or 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
;;; Project 1, 6.001, Spring 2005 | |
(ns basebot | |
(:use clojure.test)) | |
(in-ns 'basebot) | |
;;; idea is to simulate a baseball robot | |
;; imagine hitting a ball with an initial velocity of v |
This file contains hidden or 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
(let [precedence-counter (atom 0)] | |
(defn make-agent | |
{:post [(instance? clojure.lang.Agent %)]} | |
[& state] | |
(let [state (apply array-map state) | |
agent-type (or (:type state) ::agent) | |
state (dissoc state :type) | |
a (agent (with-meta | |
(merge {:name nil |
OlderNewer