Skip to content

Instantly share code, notes, and snippets.

@lkuper
lkuper / gist:1233728
Created September 22, 2011 00:27
Stuff ignored by the C311 autograder, circa 2010
;; Load the assignment we're testing
(load input-filename
(lambda (x)
(pmatch x
;; Ignore any (load ___) expressions that might happen
;; to be in the assignment.
[(load ,anything) (void)]
;; Ignore tests they've written themselves
[(test . ,anything) (void)]
@lkuper
lkuper / gist:1406028
Created November 29, 2011 19:15
implementation of factorial for brid.js (https://github.com/jes5199/brid.js/)
> ["define", "*", ["lambda", ["n"], ["lambda", ["m"], ["if", ["eq?", "m", 0], 0, ["+", "n", [["*", "n"], ["-", "m", 1]]]]]]]
"some-lambda"
> ["define", "fact", ["lambda", ["n"], ["if", ["eq?", "n", 0], 1, [["*", "n"], ["fact", ["-", "n", 1]]]]]]
"some-lambda"
> ["fact", 5]
120
$ make petite install
./bootstrap
./tangleit petite
This is CHEZTANGLE, ChezWEB Version 2.0.
Tangling chezweb.ss
Outputing runtime.ss
Outputing chezweave.ss
Outputing runtime.sls
Outputing cheztangle.ss
[: 24: petite: unexpected operator
lkuper@lenny:~/repos$ export CHEZWEBHOME=~/repos/ChezWEB/
lkuper@lenny:~/repos$ echo $CHEZWEBHOME
/home/lkuper/repos/ChezWEB/
lkuper@lenny:~/repos$ ./ChezWEB/tangleit
./ChezWEB/tangleit: 5: ./cheztangle.ss: not found
lkuper@lenny:~/repos$
;; given a store loc l and two stores S_1 and S_2, return the lub of
;; S_1(l) and S_2(l). We know that every l this function gets is
;; going to be in the domain of either S_1 or S_2 or both.
(define-metafunction lambdapar
lubstore-helper : S S l -> D
[(lubstore-helper S_1 S_2 l)
,(let ([d_1 (term (store-lookup S_1 l))]
[d_2 (term (store-lookup S_2 l))])
(cond
[(equal? d_1 (term lookupfailed)) d_2]
Title: Monotonic data structures as a guiding principle for
deterministic parallel programming
Abstract:
Kahn process networks, Haskell's monad-par library, and Intel's
Concurrent Collections language are three diverse examples of
deterministic-by-construction models of parallel computation. In a
deterministic-by-construction model, all programs written using the
model are guaranteed to behave deterministically, so they offer
fn not_ok(a: &uint) {
let mut g: fn@(x: &uint) = fn@(x: &r.uint) {};
g(a);
}
fn main() {
}
lkuper@lenny:~/rust/build$ x86_64-unknown-linux-gnu/stage0/bin/rustc --debug-rustc ../src/test/run-pass/regions-fn-subtyping-2.rs
../src/test/run-pass/regions-fn-subtyping-2.rs:4:33: 4:49 error: mismatched types: expected `fn@(&uint)` but found `fn@(&r.uint)` (references with lifetime & do not necessarily outlive references with lifetime &r)
code:
import vec::each;
fn getBigRecord(x: int)-> [int] {
let mut myVec = [], i = 0;
while i <= x {
myVec += [i];
i += 1;
}
type circular_buf<T> = {start: uint,
end: uint,
buf: [mut T]
};
fn make_circle<T>(s: uint, e: uint, +b: [mut T]) -> circular_buf<T> {
ret {start: s, end: e, buf: b };
}
fn main() { }
fn main() {
// Bitvector to represent sets of integral types
type int_ty_set = uint;
impl methods for int_ty_set {
fn union(s: int_ty_set) -> int_ty_set { self | s }
fn intersection(s: int_ty_set) -> int_ty_set { self & s }