Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example does not compile #55

Open
kalefranz opened this issue Apr 5, 2018 · 5 comments
Open

Example does not compile #55

kalefranz opened this issue Apr 5, 2018 · 5 comments

Comments

@kalefranz
Copy link

kalefranz commented Apr 5, 2018

First example at http://stevedonovan.github.io/rust-gentle-intro/1-basics.html#learning-where-to-find-the-ropes

 #![allow(unused_variables)]
 
fn main() {
let pi = 3.1416;
let x = pi/2.0;
let cosine = x.cos();

}

output when run in browser is

   Compiling playground v0.0.1 (file:///playground)
error[E0599]: no method named `cos` found for type `{float}` in the current scope
 --> src/main.rs:6:16
  |
6 | let cosine = x.cos();
  |                ^^^

error: aborting due to previous error

error: Could not compile `playground`.

To learn more, run the command again with --verbose.

I know this is probably something trivial. But I'm a total n00b, and that's why I'm reading this tutorial!

@stevedonovan
Copy link
Owner

Yes, it really was impossible to compile that snippet! Rust needs to know whether pi is a single or a double float (f32 or f64) so putting an explicit type let pi: f64 = ... sorts it out. It's because the standard library defines cos for both kinds of floating point number.

Fixed with the latest update!

@kalefranz
Copy link
Author

Interesting. Looks like that's an opportunity for a better compiler error message.

error[E0599]: no method named cosfound for type{float} in the current scope

Didn't to me at all suggest what the cause of the problem was. Thanks for the help!

@kalefranz
Copy link
Author

... and the very awesome rust intro. I really appreciate the references to other programming languages. Besides references to c/c++, it's something I haven't yet seen in other rust books and tutorials.

@stevedonovan
Copy link
Owner

I think we all come from somewhere, and usually it's a garbage-collected, managed language. That definitely makes life simpler. With Rust certain new distinctions have to be made, but really it's mostly about references and making sure they live just long enough.

With the new update, I included a new chapter on "Pain Points". I think this is probably the place where detailed language comparisons should go!

@kalefranz
Copy link
Author

Actually, other tutorials and sources are at least decent about describing borrows, and how they compare to c/c++. That's actually not what I was referencing. What I appreciate are all the non-memory-management-related language comparisons and references. I know C, but I'm most proficient in java and python. For example... identifying that traits are very close to java interfaces. It was like a fast-forward in my understanding of how they work. I eventually would have recognized it on my own, and would have used that exact same connection in my own mental model. The cool part was having somebody actually telling me it's so, rather than me having to make that connection on my own, and then question and prove to myself whether it's valid or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants