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
use a::b::c; | |
pub fn mk_pass(name: ~str, op: @fn(&str) -> ~str) -> Pass { | |
let op = Cell(op); | |
Pass { | |
name: copy name, | |
f: |srv: astsrv::Srv, doc: doc::Doc| -> doc::Doc { | |
run(srv, doc, op.take()) | |
} | |
} |
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
#[test] fn main() { | |
let z = match 3 { | |
x() => x | |
}; | |
assert_eq!(z,3) | |
} |
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
;; link to the rust library: | |
(define rust-lib (ffi-lib (build-path here "libblur-68a2c114141ca-0.0"))) | |
(define rust-blur-fun (get-ffi-obj "blur" rust-lib (_fun _uint _uint _cvector -> _void))) | |
(define (rust-blur width height data) | |
(define cvec (list->cvector data _byte)) | |
(rust-blur-fun width height cvec) | |
(cvector->list cvec)) | |
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
#[no_mangle] | |
pub extern fn blur(width: c_uint, height: c_uint, data: *mut u8) { | |
let width = width as uint; | |
let height = height as uint; | |
unsafe { | |
do vec::raw::mut_buf_as_slice(data, width * height) |data| { | |
let out_data = blur_rust(width, height, data); | |
vec::raw::copy_memory(data, out_data, width * height); | |
} |
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
fn blur_rust(width: uint, height: uint, data: &[u8]) -> ~[u8] { | |
let filter = [[0.011, 0.084, 0.011], | |
[0.084, 0.620, 0.084], | |
[0.011, 0.084, 0.011]]; | |
let mut newdata = ~[]; | |
for uint::range(0, height) |y| { | |
for uint::range(0, width) |x| { |
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
;; the gaussian filter used in the racket blur. | |
;; boosted center value by 1/1000 to make sure that whites stay white. | |
(define filter '[[0.011 0.084 0.011] | |
[0.084 0.620 0.084] | |
[0.011 0.084 0.011]]) | |
;; racket-blur: blur the image using the gaussian filter | |
;; number number list-of-bytes -> vector-of-bytes | |
(define (racket-blur width height data) | |
(define data-vec (list->vector data)) |
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
#lang racket | |
(define lines | |
(list "hootehutt 23 hoethoet 4" | |
"abc 9 thuoteh 9")) | |
(for/list ([l lines]) | |
(match-define (list name age lastname donuts) (string-split l)) | |
(list name (string->number age) lastname (string->number donuts))) |
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
#lang racket | |
(define lines | |
(list "hootehutt 23 hoethoet 4" | |
"abc 9 thuoteh 9")) | |
(define (maybe-numify s) | |
(match (regexp-match #px"[0-9]+" s) | |
[#f s] | |
[else (string->number s)])) |
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
#lang racket | |
;; Rafael George Homework 5 | |
;; definition of structures for MUPL programs | |
(define-struct var (string)) ;; a variable, e.g., (make-var "foo") | |
(define-struct int (num)) ;; a constant number, e.g., (make-int 17) | |
(define-struct add (e1 e2)) ;; add two expressions | |
(define-struct ifgreater (e1 e2 e3 e4));;if e1 > e2 then e3 else e4 | |
(define-struct fun (nameopt formal body)) ;; a recursive(?) 1-argument function |
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
pub struct Bogo { | |
x: fn@() -> uint | |
} | |
pub fn bugfun2(_exts: @mut uint) | |
-> uint { 3 } | |
pub fn bugfun() { | |
let mut exts = 146; | |
let _f_pre = @Bogo { |