Closed Adrien79 closed 6 years ago
This is suprisingly difficult to support in the compiler, but I improved the error message.
@Adrien79 Note that you can also minimize the syntactical overhead by using range[0..size.pred]
.
@Adrien79 From issue #6216, I have learned that it's always best to put a space before and after the ..
operator. So this works:
const size = 6
type A = range[0 .. <size]
@kaushalmodi That's not true, .. <
is in fact deprecated.
@Araq Ah! I wasn't aware.. need to update my notes.. So as @bluenote10 says, should we instead always do [0 .. str.pred]
instead of [0 .. <str.high]
?
OK.. [0 .. str.pred]
does not work. So I am missing out on something.. So if I have:
var str = "abc"
echo str[0 .. <str.high]
what's the new way of writing the same (as of the latest devel
version, the above works)?
@Araq OK, I found the commit https://github.com/nim-lang/Nim/commit/70ea45cdbaa9d26a7196ab2718f60c9ca77e2d12
So I believe, following the convention of:
var str = "abc"
echo str[0 .. str.high]
It would be preferred to do the below (space before and after ..<
)?
var str = "abc"
echo str[0 ..< str.high]
Just that now ..<
is treated as a single binary operator, just as ..
. Is that correct?
Update: Updated my notes.
It would be preferred to do the below (space before and after ..<)?
The jury is still out on this matter, but I would say, yes, that is the way to do the formatting.
Just that now ..< is treated as a single binary operator, just as ... Is that correct?
Yes.
Unfortunately my book uses 0 .. <len(x)
everywhere :\
@dom96 Yeah, I noticed that immediately after I fixed my post. :(
We'll just have to keep it deprecated post-v1 I guess
@dom96 Don't mean to ruin this thread with off-topic question.. but do you plan to release digital copies of your book with fixes for such deprecated syntax? Does MEAP support providing PDF/ebook updates to folks to bought stuff from them?
I don't think I will do that. Fixes should go into a "second edition", making small incremental changes to the ebook would make it diverge from the printed copy. Maybe that would be fine, to be honest I'm not sure, would need to ask Manning and see how they feel about it.
making small incremental changes to the ebook would make it diverge from the printed copy
Isn't that the benefit of an ebook that it can always stay up to date? I remember the days in school where I would take my printed textbook, open a pdf of its errata and manually fix all the typos and errors in the book. With ebooks, the book owner cannot do those errata fixes manually, but the author can :)
I hope Manning and you are fine and willing to keep the ebook/pdf versions up to date. Thanks!
I will do my best to do that. Current plan is for the book to work with v1 though, so changes shouldn't be critical :)
I'm surprised that this fails to compile:
and I have to type this instead:
I thought it would be the same.