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
;; largest prime factor | |
(defn lpf | |
"Takes a number n and a starting number d > 1 | |
and calculates the largest prime factor of n | |
starting at number d. | |
usage: (lpf 364362978 2) => 8675309" | |
[n d] | |
(if (> d 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
""" | |
Simple forking echo server built with Python's SocketServer library. A more | |
Pythonic version of http://gist.github.com/203520, which itself was inspired | |
by http://tomayko.com/writings/unicorn-is-unix. | |
""" | |
import os | |
import SocketServer | |
class EchoHandler(SocketServer.StreamRequestHandler): |
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/ruby | |
RLSP_VERSION = "1.4.1" | |
class Lambda | |
attr_accessor :args, :body | |
def initialize(args=[],body="") | |
@args = (args.class == Array) ? args : [args] | |
@body = body | |
end |
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
(defprotocol Matchable (match [me matcher])) | |
(defmacro data [name & constructors] | |
`(do | |
(defprotocol ~name) | |
(defprotocol ~(symbol (str "match-"name)) | |
~@(for [[const & args] constructors] | |
`(~(symbol (str "match-"const)) [_# ~@args]))) | |
~@(for [[const & args] constructors] |
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 constrained-fn [f x] | |
{:pre [(pos? x)] | |
:post [(= % (* 2 x))]} | |
(f x)) | |
(constrained-fn #(* 2 %) 2) | |
;=> 4 | |
(constrained-fn #(float (* 2 %)) 2) | |
;=> 4.0 |
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 constrained-fn [f x] | |
{:pre [(pos? x)] | |
:post [(= % (* 2 x))]} | |
(f x)) | |
(constrained-fn #(* 2 %) 2) | |
;=> 4 | |
(constrained-fn #(float (* 2 %)) 2) | |
;=> 4.0 |
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 constrained-fn [f x] | |
{:pre [(pos? x)] | |
:post [(= % (* 2 x))]} | |
(f x)) | |
(constrained-fn #(* 2 %) 2) | |
;=> 4 | |
(constrained-fn #(float (* 2 %)) 2) | |
;=> 4.0 |
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 constrained-fn [f x] | |
{:pre [(pos? x)] | |
:post [(= % (* 2 x))]} | |
(f x)) | |
(constrained-fn #(* 2 %) 2) | |
;=> 4 | |
(constrained-fn #(float (* 2 %)) 2) | |
;=> 4.0 |
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 constrained-fn [f x] | |
{:pre [(pos? x)] | |
:post [(= % (* 2 x))]} | |
(f x)) | |
(constrained-fn #(* 2 %) 2) | |
;=> 4 | |
(constrained-fn #(float (* 2 %)) 2) | |
;=> 4.0 |
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 constrained-fn [f x] | |
{:pre [(pos? x)] | |
:post [(= % (* 2 x))]} | |
(f x)) | |
(constrained-fn #(* 2 %) 2) | |
;=> 4 | |
(constrained-fn #(float (* 2 %)) 2) | |
;=> 4.0 |