Skip to content

Instantly share code, notes, and snippets.

View bstrie's full-sized avatar

bstrie bstrie

View GitHub Profile
@bstrie
bstrie / 1
Created November 16, 2012 04:49
Rust error
fn main() {
for int::range(1,101) |i| {
io::println(option::get_default(Some("foo"), i.to_str()));
}
}
@bstrie
bstrie / gist:4084206
Created November 16, 2012 04:51
Rust error
fizzbuzz.rs:16:53: 16:64 error: illegal borrow: borrowed value does not live long enough
fizzbuzz.rs:16 io::println(option::get_default(Some("foo"), i.to_str()));
^~~~~~~~~~~
note: borrowed pointer must be valid for the static lifetime...
fizzbuzz.rs:16:20: 16:65 note: ...but borrowed value is only valid for the call at 16:20
fizzbuzz.rs:16 io::println(option::get_default(Some("foo"), i.to_str()));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// New way
trait OwnedStrRhs<S> {
pure fn add_to_owned_str(lhs: ~str) -> S;
}
//impl<S, R: OwnedStrRhs<S>> ~str : Add<R, S> {
impl<R: OwnedStrRhs<~str>> ~str : Add<R, ~str> {
pure fn add(rhs: &R) -> ~str {
rhs.add_to_owned_str(self)
}
/media/linhaus/rust/src/libcore/float.rs:154:15: 154:47 error: failed to find an im
plementation of trait @str::traits::OwnedStrRhs<~str> for <V53>
/media/linhaus/rust/src/libcore/float.rs:154 racc = uint::str(adjusted_digi
t) + racc;
^~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~
use int::range;
use option::{get_default, opt_if};
fn main() {
for range(1,101) |i| {
io::println(get_default(
(if i % 3 == 0 { Some(~"Fizz") } else { None } +
if i % 5 == 0 { Some(~"Buzz") } else { None }),
i.to_str()
));
@bstrie
bstrie / fizzbuzz.rs
Last active October 12, 2015 20:48
// THIS CODE IS SOOO OBSOLETE. SUITABLE ONLY FOR HISTORICAL CURIOSITY
use int::range;
use option::get_default;
fn main() {
for range(1,101) |i| {
io::println(get_default(
(if i % 3 == 0 { Some(~"Fizz") } else { None } +
if i % 5 == 0 { Some(~"Buzz") } else { None }),
@bstrie
bstrie / gist:4128032
Created November 21, 2012 21:44
Rust trait return
trait A {}
impl ~[int] : A {}
fn foo()-> A {
~[0]
}
@bstrie
bstrie / gist:4163142
Created November 28, 2012 18:42
Computer bugs in the year 2000
https://groups.google.com/d/msg/net.bugs/ZGlqGwNaq3I/JX6mYJRPg34J
D Gary Grady
1/22/85
<>
> The problem won't be the computers, but the software. Some software is
> bound to be wrong, only considering the last two digits of the year.
And thereby hangs a tale: In 1978, when I was working in banking, I
ran across a curious date storage format. It seems that transaction
impl<T: Copy Add<T,T>> Option<T> : Add<Option<T>, Option<T>> {
#[inline(always)]
pure fn add(other: &Option<T>) -> Option<T> {
match (self, *other) {
(None, None) => None,
(_, None) => self,
(None, _) => *other,
(Some(ref v1), Some(ref v2)) => Some(*v1 + *v2)
}
}
@bstrie
bstrie / gist:4204324
Created December 4, 2012 14:13
RPG, sans comments
F ARMstF1 IF E K Disk Rename(ARMST:RARMST)
D pCusNo S 6p 0
D pName S 30a
D pAddr1 S 30a
D pAddr2 S 30a
D pCity S 25a
D pState S 2a
D pZip S 10a