This file contains 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
extern mod std; | |
use core::task::spawn; | |
use core::comm::{stream, Port, Chan, SharedChan}; | |
// Purely functional doubler | |
// No need to combine computation / means of sending it in the same function | |
// In a real example, this could be an expensive computation | |
fn double(x: int) -> int { | |
x * 2 | |
} |
This file contains 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
extern mod std; | |
use core::num::IntConvertible; | |
use core::ops::Modulo; | |
fn find_even<T:Copy+Modulo<T,T>+IntConvertible+cmp::Eq>(vec: &[T]) -> Option<T> { | |
let zero: T = IntConvertible::from_int(0); | |
let two: T = IntConvertible::from_int(2); | |
for vec.each |x| { | |
if *x % two == zero { | |
return Some(*x); |
This file contains 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
four primitives: run*, ==, conde, fresh | |
(run* (q) | |
(== q #t)) | |
; for what values of q is q equal to true? | |
answer: q must also be #t, so | |
'(#t) ; answer comes back in a list |
This file contains 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
@-moz-document url-prefix(https://news.ycombinator.com) { | |
.comment { | |
font-family: Alegreya, serif !important; | |
font-size: 15pt !important; | |
} | |
.comment code { | |
font-family: Inconsolata-g, fixed !important; | |
font-size: 10pt !important; | |
} |
This file contains 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
mergeSort :: Ord a => [a] -> [a] | |
mergeSort [] = [] | |
mergeSort [x] = [x] | |
mergeSort xs = combineSortedLists | |
(mergeSort firstHalf) | |
(mergeSort secondHalf) | |
where (firstHalf, secondHalf) = splitInHalf xs | |
splitInHalf :: [a] -> ([a], [a]) | |
splitInHalf xs = splitAt halfLength xs |
This file contains 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
fn main() { | |
let s = [1, 2, 3, 4].map(|&x| (x * x).to_str()); | |
for s.each |&item| { | |
io::println(item); | |
} | |
} |
This file contains 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
@-moz-document url-prefix(https://news.ycombinator.com) { | |
.comment { | |
font-family: Alegreya, serif !important; | |
font-size: 15pt !important; | |
} | |
.comment code { | |
font-family: Inconsolata-g, fixed !important; | |
font-size: 10pt !important; | |
} |
This file contains 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
Exception in thread "main" java.lang.IllegalArgumentException: Don't know how to create ISeq from: ring_intro.core$wrap_uri_check$fn__205, compiling:(core.clj:27:3) | |
at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:3463) | |
at clojure.lang.Compiler$DefExpr.eval(Compiler.java:408) | |
at clojure.lang.Compiler.eval(Compiler.java:6624) | |
at clojure.lang.Compiler.load(Compiler.java:7064) | |
at clojure.lang.RT.loadResourceScript(RT.java:370) | |
at clojure.lang.RT.loadResourceScript(RT.java:361) | |
at clojure.lang.RT.load(RT.java:440) | |
at clojure.lang.RT.load(RT.java:411) | |
at clojure.core$load$fn__5028.invoke(core.clj:5530) |
This file contains 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 divides [m n] | |
(= 0 | |
(mod n m))) | |
(defn my-and [x y] | |
(and x y)) | |
(defn all? [pred xs] | |
(reduce my-and true | |
(map pred xs))) |
This file contains 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
(ns vectors | |
(:require [clojure.test :refer [deftest is run-tests]])) | |
(defprotocol VectorMath2D | |
(-vplus [v1 v2] "Adds two vectors")) | |
(defrecord Vec2D [x y] | |
VectorMath2D | |
(-vplus [v1 v2] | |
(Vec2D. (+ (:x v1) |