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
def ∑(r:Range)(f:Int =>Int)=r.reduceLeft(_+ f(_)) | |
def ∏(r:Range)(f:Int =>Int)=r.reduceLeft(_* f(_)) | |
// And now we can write: | |
val s= ∑(1 to 100)(x=>x^2) | |
val p= ∑(1 to 100 by 2)(x=>x^2) | |
val y= ∏(1 to 30 by 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
(define (in-same-diagonal cell1 cell2) | |
(let((diff (map (compose abs -) cell1 cell2))) | |
(and (not (zero? (cadr diff))) | |
(= 1 (apply quotient diff)) | |
(= 0 (apply modulo diff))))) |
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
; http://groups.google.com/group/clojure/browse_thread/thread/974e2c7f89e27231/5f4bff3e58dfa36f | |
; output images http://i.imgur.com/gSASS.png (square maze) | |
; http://i.imgur.com/uEqaq.png (hex maze) | |
;; generic Wilson's algorithm implementation | |
(defn maze | |
"Returns a random maze carved out of walls; walls is a set of | |
2-item sets #{a b} where a and b are locations. | |
The returned maze is a set of the remaining walls." | |
[walls] |
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 express_sample | |
(:require [cljs.nodejs :as node])) | |
(def express (node/require "express")) | |
(def app (. express (createServer))) | |
(defn -main [& args] | |
(doto app | |
(.use (. express (logger))) | |
(.get "/" (fn [req res] |
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
(run-cc | |
($lambda () | |
($let ((p (make-prompt))) | |
(+ 2 ($push-prompt p | |
($if (with-sub-cont p | |
($lambda (k) | |
(+ ($push-sub-cont k #f) | |
($push-sub-cont k #t)))) | |
3 | |
4)))))) |
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 fj | |
(:import [java.util.concurrent RecursiveTask | |
ForkJoinPool])) | |
(set! *warn-on-reflection* true) | |
;; ----------------------------------------------- | |
;; Helpers to provide an idiomatic interface to FJ | |
(defprotocol IFJTask |
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
#!/bin/sh | |
# This script is for building the hsx/hotspot-comp branch in isolation. | |
# | |
# Prerequisites: | |
# * appropriate build tools | |
# * a working Sun Java 6 build (i.e. JDK6) is available at: | |
# HOME/java/re/j2se/1.6.0/latest/binaries/linux-[i586/amd64] | |
# * a working Sun Java 7 build (i.e. JDK7) is available at: | |
# HOME/java/re/j2se/1.7.0/latest/binaries/linux-[i586/amd64] | |
# HOME/java/re/j2se/1.7.0/promoted/latest/binaries/linux-[i586/amd64] |
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
package gameoflife | |
class Board[T](val b:Array[Array[T]]) { | |
val h=b.size | |
val w=b(0).size | |
def conv(idx:Int,max:Int)=if (idx<0) (max-Math.abs(idx %max) ) else (idx % max ) | |
def apply(x:Int,y:Int)=b(conv(x,h))(conv(y,w)) | |
def update(x:Int,y:Int,value:T)= b(conv(x,h))(conv(y,w))=value |
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
val Π = Math.Pi | |
def √(x:Double)=Math.sqrt(x) | |
val x= √(9*Π) |
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 ruby | |
# the stack | |
$stack = [] | |
def pop() $stack.pop || ufe end | |
def push(f) $stack<<f end | |
# poor man's Exception class | |
def ufe() raise("Stack underflow") end | |
# lambda constructor helpers |