Created
February 27, 2013 15:57
-
-
Save osaut/5048969 to your computer and use it in GitHub Desktop.
Impure access
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
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