In the Parameters section of the tutorial:
proc printSeq(s: seq, nprinted: int = -1) =
var nprinted = if nprinted == -1: s.len else: min(nprinted, s.len)
for i in 0 .. <nprinted:
echo s[i]
What is the < for?
Hi @cdunn2001,
To elaborate on the answer from @Sixte, unary < is a proc defined in the system module.
Unary < is roughly equivalent to a single-argument invocation of pred (ie, the y parameter of pred will be 1). So basically, <num means "the value that is one less than num".
As the documentation states, unary < is useful for nice-looking for-loop ranges (to programmers who are used to C-style closed-open "excluding" ranges in their for-loops, such as myself):
for i in 0 .. <numElems:
echo i
PS: Don't forget to have a space between .. and <. The single token ..< (without a space) doesn't work (currently?).
A side note to the Nim documentation admins:
Would anyone have any objections to an update to docgen so that the auto-generated URI for an identifier like < is:
http://nim-lang.org/system.html#%3C,Ordinal[T]
rather than the current:
http://nim-lang.org/system.html#<,Ordinal[T]
That is, generate %3C in the URI rather than <, since < messes with HTML in general, and Nim-forum link markup in particular.
Every time I want to paste a link to something like <, I notice the problem in the preview and then I have to look up a table of URL encodings to make the translation manually.
Would I be correct in assuming the change should be made in Nim/lib/packages/docutils/rstgen.nim? I got there from Nim/compiler/docgen.nim.