-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Add some explanations #10
Conversation
Add some explanations. Add TODO for documenting for loop break & continue.
BTW other things I just saw that need documentation - |
Hi @ntrel |
user := repo.find_user_by_id(10) or { | ||
eprintln(err) | ||
return | ||
} | ||
println(user.id) // 10 | ||
user = repo.find_user_by_id(11)? <comment>// ? propagates an error </comment> | ||
println(user.id) // 11 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added these lines so the statement?
error propagation is documented under the Option types section.
fn (db DB) query_one<T>(query string, id int) T? { | ||
<comment>// Return a value of type T from the database, or an error. | ||
// Implementation omitted...</comment> | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this because seeing the signature seems helpful to understanding this example.
} | ||
|
||
<comment>// This is a generic receiver function. V will generate it for every Repo instance it's used with. | ||
// T is a member type of Repo, so it is in scope for this receiver function.</comment> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is my understanding anyway ;-)
This code suprised me a bit. I would have thought that only members of r
would be in scope for this function, not members of Repo
. Or is T
a member of r
too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
T is not a member, it's a type. I'll make it more clear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assumed T was exposed as Repo.T
, but maybe V just makes it accessible for this function because Repo was mentioned as the receiver parameter and T is the template parameter for Repo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I understand now, see #13.
@@ -266,7 +267,7 @@ <h2 id=strings>Strings</h2> | |||
In V, a string is a read-only array of bytes. String data is encoded using UTF-8. | |||
|
|||
<p> | |||
Strings are immutable. This means that the substring function is very efficient: | |||
String contents are immutable. This means that the substring function is very efficient: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing wrong with "strings are immutable"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strings have length, and the length is not immutable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it is. It can't be modified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, so we can't append to a string to change it's length?
@@ -409,7 +410,7 @@ <h2 id=for>For loop</h2> | |||
because with the latter it's easy to forget to update the counter and get | |||
stuck in an infinite loop. | |||
|
|||
|
|||
TODO: Break and continue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lots of things are missing, I don't wont to pollute the docs with TODO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough ;-)
Thanks for merging! |
Resolve some issues discussed in pull vlang#10.
Resolve some issues discussed in pull #10.
BTW, the docs for interfaces here don't seem to be in
master
.