Skip to content

Instantly share code, notes, and snippets.

View buntine's full-sized avatar
💭
Gringo Starr

Andrew Buntine buntine

💭
Gringo Starr
View GitHub Profile
//Selecting Item Colours
$(".dress-container .select-colour a").click(function(){
//find the colour range
var colourRange = $(this).parent().next(".colours");
//find the links in the colour range
var colourRangeLink = $(colourRange).find("a");
//showing colour range
$(colourRange).show();
@buntine
buntine / cfcc-1.scm
Created December 12, 2010 06:47
Snippets for blog article on continuations
(lambda (n) (+ n 1))
; letfn is a Clojure macro that allows for mutually recursive functions.
; In some lisps, letfn (or letrec) will expand to a lambda expression.
(letfn [(fact-helper [total n]
(if (<= n 1)
total
(fact-helper (* n total) (- n 1))))]
(defn fact [n]
(fact-helper 1 n)))
(fact 5) ; 120
; This function returns a closure. That is, the returned anonymous function
; saves a reference to the free variable "n".
(defn make-adder [n]
"Returns a function that sums a given value (m) with n."
(fn [m]
(+ n m)))
(def add-10 (make-adder 10))
; When we invoke the function, rather than creating a new environment, it will
;;; Calculates all elements of Pascal's Triangle up to a particular width/row.
(define (pascal width)
(reverse (pascal-helper '((1)) width)))
(define (pascal-helper rows width)
(if (= (length rows) width)
rows
(pascal-helper (cons (next-row (car rows))
rows)