Skip to content

Instantly share code, notes, and snippets.

@osaut
Created February 27, 2013 15:57
Show Gist options
  • Save osaut/5048969 to your computer and use it in GitHub Desktop.
Save osaut/5048969 to your computer and use it in GitHub Desktop.
Impure access
struct Box {
mut data : ~[float]
}
pub impl ops::Add<Box, Box> for Box
{
pure fn add(&self, other: &Box) -> Box {
let mut new_data : ~[float]=~[];
let mut ctr=0;
for self.data.each |value| {
new_data.push(value+other.data[ctr]);
ctr+=1;
}
Box{data:new_data}
}
}
fn main() {
let box1=Box{data:~[1.0,2.0,3.0]};
let box2=Box{data:~[4.0,5.0,6.0]};
let box3=box1+box2;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment