Skip to content

Instantly share code, notes, and snippets.

View jhuni's full-sized avatar

John Bernier jhuni

View GitHub Profile
(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]
(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))
(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
(sum
(map (lambda (x) (* x x))
(filter (lambda (x) (% x 2))
(take-while (lambda (x) (< x 1000000)) (fib)))))
;;;; 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)
Module({
"id": "com.test.module",
"use": ["Some.Class", "Module.Stub", "Stub.Module"]
}, function(m) {
Class("Test", {
isa: Some.Class,
has: {
var Some = {"Class": require("Some.Class").Class};
Class("Point.Special", {
has: {
x: {
is: "rw",
init: 0
},
y: {
/* Module using the exports syntax */
exports.add = function(a, b) {
return a + b;
};
exports.subtract = function(a, b) {
return a - b;
};
// 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';
/****************************************
SIO version:
****************************************/
var io = new IO({
blocking: true
});
var text = io.slurp({ url: "./lib/js/Module.js" });