implemented 'let' statement
This commit is contained in:
parent
31a994cc10
commit
7fcbdc6d42
33 changed files with 169 additions and 103 deletions
10
doc/tut2.txt
10
doc/tut2.txt
|
|
@ -580,13 +580,13 @@ via a special ``:`` syntax:
|
|||
.. code-block:: nimrod
|
||||
|
||||
template withFile(f: expr, filename: string, mode: TFileMode,
|
||||
actions: stmt): stmt =
|
||||
body: stmt): stmt =
|
||||
block:
|
||||
var fn = filename
|
||||
let fn = filename
|
||||
var f: TFile
|
||||
if open(f, fn, mode):
|
||||
try:
|
||||
actions
|
||||
body
|
||||
finally:
|
||||
close(f)
|
||||
else:
|
||||
|
|
@ -596,10 +596,10 @@ via a special ``:`` syntax:
|
|||
txt.writeln("line 1")
|
||||
txt.writeln("line 2")
|
||||
|
||||
In the example the two ``writeln`` statements are bound to the ``actions``
|
||||
In the example the two ``writeln`` statements are bound to the ``body``
|
||||
parameter. The ``withFile`` template contains boilerplate code and helps to
|
||||
avoid a common bug: to forget to close the file. Note how the
|
||||
``var fn = filename`` statement ensures that ``filename`` is evaluated only
|
||||
``let fn = filename`` statement ensures that ``filename`` is evaluated only
|
||||
once.
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue