I really liked the style of that series when investigating Racket myself. That is, little to no preparation, and writing down everything you try, even if it doesn't work.
Hope someone finds it useful.
I really liked the style of that series when investigating Racket myself. That is, little to no preparation, and writing down everything you try, even if it doesn't work.
Hope someone finds it useful.
I think it's a bummer you can't do `LevelMap::new()` like you want, but here are two things that work that I think are improvements on your `mklevel` function:
fn mklevel() -> LevelMap { HashMap::new() }
That works because once the compiler knows that the return type is `LevelMap`, which it knows is really `HashMap<Coord, int>`, it can infer which variant of `HashMap::new` to call. Using this same idea, you can get closer to what you originally wanted without the function, like this: let mut map: LevelMap = HashMap::new();
There are also a couple things that I think are good syntactic improvements over the `Coord{x: 0, y: 0}` syntax that you made the `xy` function to avoid. First, you can just use a tuple: type LevelMapTuple = HashMap<(int, int), int>;
let mut maptuple: LevelMapTuple = HashMap::new();
maptuple.insert((0, 0), 0);
If you still want to give it a name, which I think is pretty nice, you can use a struct with anonymous members, like this: struct Coord(int, int);
let mut map: LevelMap = HashMap::new();
map.insert(Coord(0, 0), 0);
Here's a rust playpen link illustrating some of these things: http://is.gd/latFCh. Enjoy![0]: http://caskroom.io/
alias rustup='brew cask fetch --force rust cargo && brew cask install --force rust cargo && git -C ~/.vim/bundle/rust.vim pull'If your blog / series is on github, I'd happily send PRs for above. Let me know :)
Thanks a lot!
Edit: If you prefer staying away from styling your blog then even writing the content in Markdown would do the trick
I'm not a regular writer and don't have a blog, so it's not as easy as hitting 'new post' but I'll be sure to get something a bit more usable up soon.
Edit: Converted to Markdown-generated HTML for now.