'nil' as a statement is deprecated, use an empty 'discard' instead

This commit is contained in:
Araq 2014-01-19 16:54:59 +01:00
commit 73c6efdf66
54 changed files with 170 additions and 170 deletions

View file

@ -1333,7 +1333,7 @@ Examples:
# has default calling convention
echo "x: ", mouseX, " y: ", mouseY
proc setOnMouseMove(mouseMoveEvent: TOnMouseMove) = nil
proc setOnMouseMove(mouseMoveEvent: TOnMouseMove) = discard
# ok, 'onMouseMove' has the default calling convention, which is compatible
# to 'closure':

View file

@ -324,12 +324,12 @@ the compiler that for every other value nothing should be done:
case n
of 0..2, 4..7: echo("The number is in the set: {0, 1, 2, 4, 5, 6, 7}")
of 3, 8: echo("The number is 3 or 8")
else: nil
else: discard
The ``nil`` statement is a *do nothing* statement. The compiler knows that a
case statement with an else part cannot fail and thus the error disappears. Note
that it is impossible to cover all possible string values: that is why there is
no such check for string cases.
The empty ``discard`` statement is a *do nothing* statement. The compiler knows
that a case statement with an else part cannot fail and thus the error
disappears. Note that it is impossible to cover all possible string values:
that is why there is no such check for string cases.
In general the case statement is used for subrange types or enumerations where
it is of great help that the compiler checks that you covered any possible

View file

@ -614,7 +614,7 @@ simple proc for logging:
.. code-block:: nimrod
const
debug = True
debug = true
proc log(msg: string) {.inline.} =
if debug: stdout.writeln(msg)
@ -631,7 +631,7 @@ Turning the ``log`` proc into a template solves this problem:
.. code-block:: nimrod
const
debug = True
debug = true
template log(msg: string) =
if debug: stdout.writeln(msg)
@ -674,16 +674,15 @@ via a special ``:`` syntax:
template withFile(f: expr, filename: string, mode: TFileMode,
body: stmt): stmt {.immediate.} =
block:
let fn = filename
var f: TFile
if open(f, fn, mode):
try:
body
finally:
close(f)
else:
quit("cannot open: " & fn)
let fn = filename
var f: TFile
if open(f, fn, mode):
try:
body
finally:
close(f)
else:
quit("cannot open: " & fn)
withFile(txt, "ttempl3.txt", fmWrite):
txt.writeln("line 1")
@ -784,7 +783,7 @@ regular expressions:
macro case_token(n: stmt): stmt =
# creates a lexical analyzer from regular expressions
# ... (implementation is an exercise for the reader :-)
nil
discard
case_token: # this colon tells the parser it is a macro statement
of r"[A-Za-z_]+[A-Za-z_0-9]*":