Skip to content

Instantly share code, notes, and snippets.

View fogus's full-sized avatar
💭
attempting to learn how to better learn

Fogus fogus

💭
attempting to learn how to better learn
View GitHub Profile
@fogus
fogus / gist:265107
Created December 29, 2009 02:32 — forked from agentcoops/gist:265069
(defn listify [orig-list]
"Turns (1 2 3 ...) into (1 (2 (3 (...)))) using continuation passing style."
(loop [lst orig-list cont identity]
(if (= () lst)
(cont ())
(recur (rest lst)
(fn [insert]
(cont (cons (first lst)
(list insert))))))))
|| Name || Title || Age ||
| Foo | Bar | 21 |
| Baz | Qux | 21 |
@fogus
fogus / xset.clj
Created January 8, 2010 18:39 — forked from Chouser/xset.clj
(defn xseq [t]
(when t
(concat (xseq (:l t)) [(:root t)] (xseq (:r t)))))
(defn xconj [t v]
(cond
(nil? t) {:root v :l nil :r nil}
(< v (:root t)) {:root (:root t) :l (xconj (:l t) v) :r (:r t)}
:else {:root (:root t) :l (:l t) :r (xconj (:r t) v)}))
@fogus
fogus / cells.clj
Created February 18, 2010 13:59 — forked from richhickey/cells.clj
; Copyright (c) Rich Hickey. All rights reserved.
; The use and distribution terms for this software are covered by the
; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
; which can be found in the file epl-v10.html at the root of this distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.
(set! *warn-on-reflection* true)
(defprotocol MatrexOps
(like [_ r c])
(viewSelection [_ r c]))
;; Here's where the problem lies. There is no level of abstraction higher than an abstract class (i.e. no interfaces)
;; but I still want to use the Parallel Colt 2D matrix impl. The CernOps protocol would define a delegation layer
;; intended to be used for PColt libs that expect an AbstractMatrix.
;;
(defprotocol CernOps
(cardinality [_])

You may have noticed that our two functions above used different blocks; the first being when and the second if. You will often see one or the other used as a conditional, but it's not always immediately apparent why. In general, the reasons to use when are:

  • There is no else-part associated with the result of a conditional
  • You require an implicit do in order to perform side-effects

The reasons for the use of if would therefor be the inverse of those above.

<!DOCTYPE html>
<html>
<head>
<title>BAD DATA</title>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<meta content="en-us" http-equiv="Content-Language" />
</head>
<body>
<header><h1>BAD DATA</h1></header>
For each Ruby module/class, we have Ruby methods on the left and the equivalent
Clojure functions and/or relevant notes are on the right.
For clojure functions, symbols indicate existing method definitions, in the
clojure namespace if none is explicitly given. clojure.contrib.*/* functions can
be obtained from http://github.com/kevinoneill/clojure-contrib/tree/master,
ruby-to-clojure.*/* functions can be obtained from the source files in this
gist.
If no method symbol is given, we use the following notation:
(ns com.wangdera.slideshow
(:use [clojure.contrib.test-is])
(:import (java.io File)
(javax.imageio ImageIO)
(javax.swing JFrame JPanel Timer)
(java.awt Dimension Frame Color)
(java.awt.event ActionListener WindowAdapter)))
(def imagelist (atom []))
(def current-image (atom nil))
import scala.xml.{Node, Elem, Group}
/**
* A path to a Node in a Node tree.
*/
sealed trait NodePath {
def depth: Int
}
object NodePath {