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 factorial [n] | |
(apply * (range 1 n))) | |
(defn triangular-number [n] | |
(apply + (range 1 n))) | |
(defn dot-product [& matrix] | |
(apply + (apply map * matrix))) | |
(defn vector-addition [& matrix] |
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 *a* (atom [1 2 5 1 7])) | |
(def done? (atom false)) | |
(while (not (deref done?)) | |
(swap! done? (constantly true)) | |
(let [a (deref *a*)] | |
(doseq [i (range 1 (count a))] | |
(if (< (nth a i) (nth a (dec i))) | |
(swap! done? (constantly false)) |
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
(import java.awt.Color) | |
(import java.awt.Dimension) | |
(import java.awt.event.KeyListener) | |
(import javax.swing.JFrame) | |
(import javax.swing.JPanel) | |
(def x (ref 0)) | |
(def y (ref 0)) | |
(def panel |
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
(sum | |
(map (lambda (x) (* x x)) | |
(filter (lambda (x) (% x 2)) | |
(take-while (lambda (x) (< x 1000000)) (fib))))) |
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
;;;; Created on 2011-01-15 00:49:18 | |
; Common range function | |
(defun range (start end) | |
(cond | |
((< end start) nil) | |
(t (append (range start (1- end)) (list end))))) | |
; Basic mathematical functions upon ranges | |
(defun factorial (n) |
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
Module({ | |
"id": "com.test.module", | |
"use": ["Some.Class", "Module.Stub", "Stub.Module"] | |
}, function(m) { | |
Class("Test", { | |
isa: Some.Class, | |
has: { |
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
var Some = {"Class": require("Some.Class").Class}; | |
Class("Point.Special", { | |
has: { | |
x: { | |
is: "rw", | |
init: 0 | |
}, | |
y: { |
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
/* Module using the exports syntax */ | |
exports.add = function(a, b) { | |
return a + b; | |
}; | |
exports.subtract = function(a, b) { | |
return a - b; | |
}; | |
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
// This function will get the text from the url | |
var slurp = function(props) { | |
var req = new XMLHttpRequest(); | |
var isSuccess = function() { | |
var status = req.status; | |
return (status === 200 || status === 0) && typeof req.responseText === 'string'; |
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
/**************************************** | |
SIO version: | |
****************************************/ | |
var io = new IO({ | |
blocking: true | |
}); | |
var text = io.slurp({ url: "./lib/js/Module.js" }); |
NewerOlder