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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
__author__ = "Deepak.G.R." | |
__credits__ = "Sumod Hajela" | |
__license__ = 'Public Domain' | |
""" | |
usage: | |
Go to command line and type |
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-e f [x y] | |
([_ 0] (a/< x 3)) | |
([_ 2] (a/<= 3 x) (a/< x 6)) | |
([_ 4] (a/<= 6 x))) |
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
(defmacro match | |
"shitty pattern matching macro | |
Example: | |
(def eval [exp] | |
(match exp | |
(:var v) v | |
(:abstraction arg body) (create-procedure arg body) | |
(:application operator operand) (operator operand))) |
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 alternate | |
"Take two collections and return a lazy seq of alternating items | |
from the first coll, then from the second etc until one of the | |
collections is runs out of elements. Unlike interleave, the first | |
collection may contain one element more than the second, which will | |
be included in the resulting laz seq." | |
[c1 c2] | |
(lazy-seq | |
(when-first [x c1] | |
(cons x (alternate c2 (rest c1)))))) |
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.contrib [reflect :only [get-field]]) | |
'(clojure [string :only [join replace]])) | |
(deftype Comment [content]) | |
(defmethod print-method Comment [comment ^String out] | |
(.write out (str \" (.content comment) \"))) | |
(defn read-comment [reader semicolon] | |
(let [sb (StringBuilder.)] |
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 persistent-heap) | |
(defn swap [heap idx idy] | |
(assoc heap idx (get heap idy) idy (get heap idx))) | |
(defn children [idx] | |
(let [idx (inc (* idx 2)) | |
idy (inc idx)] | |
[idx idy])) |
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 slouchdb) | |
; Fast scalable in-memory concurrent NoSQL database | |
(def db (ref {:bob {:age 59 :sex :male} | |
:bill {:age 17 :sex :male} | |
:mary {:age 28 :sex :female}})) | |
;; Views ;; | |
(defn total-age [] |
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
(defmacro arrow | |
([val] | |
val) | |
([val x & xs] | |
(if (symbol? x) | |
(list* 'user/arrow (list x val) xs) | |
(list* 'user/arrow | |
(list* (first x) val (rest x)) | |
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
user=> (import 'System.Linq.Enumerable) | |
System.Linq.Enumerable | |
user=> (def r1 (Enumerable/Range 1 10)) | |
#'user/r1 | |
user=> (seq r1) | |
(1 2 3 4 5 6 7 8 9 10) | |
user=> (def r2 (. Enumerable (generic Repeat Int32) 3 4)) | |
#'user/r2 | |
user=> (seq r2) | |
(3 3 3 3) |
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
; The New Year in Snowflakes | |
; A Clojure doodle by Chouser | |
(import '(java.awt Color Graphics Frame RenderingHints)) | |
(defonce draw-agent (agent nil)) | |
(defonce halt (atom false)) | |
(defmacro ui-thread [& body] | |
`(javax.swing.SwingUtilities/invokeAndWait (fn [] ~@body))) |
NewerOlder