Promote "echo" syntax without parenthesis
This commit is contained in:
parent
4246f660ea
commit
cd574d1976
7 changed files with 93 additions and 93 deletions
|
|
@ -15,15 +15,15 @@ Example:
|
|||
try:
|
||||
var a = readLine(f)
|
||||
var b = readLine(f)
|
||||
echo("sum: " & $(parseInt(a) + parseInt(b)))
|
||||
echo "sum: " & $(parseInt(a + parseInt(b)))
|
||||
except OverflowError:
|
||||
echo("overflow!")
|
||||
echo "overflow!"
|
||||
except ValueError:
|
||||
echo("could not convert string to integer")
|
||||
echo "could not convert string to integer"
|
||||
except IOError:
|
||||
echo("IO error!")
|
||||
echo "IO error!"
|
||||
except:
|
||||
echo("Unknown exception!")
|
||||
echo "Unknown exception!"
|
||||
finally:
|
||||
close(f)
|
||||
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@ modules don't need to import a module's dependencies:
|
|||
|
||||
# B.MyObject has been imported implicitly here:
|
||||
var x: MyObject
|
||||
echo($x)
|
||||
echo $x
|
||||
|
||||
Note on paths
|
||||
-----------
|
||||
|
|
|
|||
|
|
@ -129,9 +129,9 @@ to supply any type of first argument for procedures:
|
|||
|
||||
.. code-block:: nim
|
||||
|
||||
echo("abc".len) # is the same as echo(len("abc"))
|
||||
echo("abc".toUpper())
|
||||
echo({'a', 'b', 'c'}.card)
|
||||
echo "abc".len # is the same as echo len "abc"
|
||||
echo "abc".toUpper()
|
||||
echo {'a', 'b', 'c'}.card
|
||||
stdout.writeLine("Hallo") # the same as writeLine(stdout, "Hallo")
|
||||
|
||||
Another way to look at the method call syntax is that it provides the missing
|
||||
|
|
@ -486,7 +486,7 @@ state are automatically saved between calls. Example:
|
|||
inc(i)
|
||||
|
||||
for ch in items("hello world"): # `ch` is an iteration variable
|
||||
echo(ch)
|
||||
echo ch
|
||||
|
||||
The compiler generates code as if the programmer would have written this:
|
||||
|
||||
|
|
@ -494,7 +494,7 @@ The compiler generates code as if the programmer would have written this:
|
|||
var i = 0
|
||||
while i < len(a):
|
||||
var ch = a[i]
|
||||
echo(ch)
|
||||
echo ch
|
||||
inc(i)
|
||||
|
||||
If the iterator yields a tuple, there can be as many iteration variables
|
||||
|
|
|
|||
|
|
@ -234,11 +234,11 @@ Example:
|
|||
var name = readLine(stdin)
|
||||
|
||||
if name == "Andreas":
|
||||
echo("What a nice name!")
|
||||
echo "What a nice name!"
|
||||
elif name == "":
|
||||
echo("Don't you have a name?")
|
||||
echo "Don't you have a name?"
|
||||
else:
|
||||
echo("Boring name...")
|
||||
echo "Boring name..."
|
||||
|
||||
The ``if`` statement is a simple way to make a branch in the control flow:
|
||||
The expression after the keyword ``if`` is evaluated, if it is true
|
||||
|
|
@ -269,17 +269,17 @@ Example:
|
|||
|
||||
case readline(stdin)
|
||||
of "delete-everything", "restart-computer":
|
||||
echo("permission denied")
|
||||
of "go-for-a-walk": echo("please yourself")
|
||||
else: echo("unknown command")
|
||||
echo "permission denied"
|
||||
of "go-for-a-walk": echo "please yourself"
|
||||
else: echo "unknown command"
|
||||
|
||||
# indentation of the branches is also allowed; and so is an optional colon
|
||||
# after the selecting expression:
|
||||
case readline(stdin):
|
||||
of "delete-everything", "restart-computer":
|
||||
echo("permission denied")
|
||||
of "go-for-a-walk": echo("please yourself")
|
||||
else: echo("unknown command")
|
||||
echo "permission denied"
|
||||
of "go-for-a-walk": echo "please yourself"
|
||||
else: echo "unknown command"
|
||||
|
||||
|
||||
The ``case`` statement is similar to the if statement, but it represents
|
||||
|
|
@ -326,13 +326,13 @@ Example:
|
|||
.. code-block:: nim
|
||||
|
||||
when sizeof(int) == 2:
|
||||
echo("running on a 16 bit system!")
|
||||
echo "running on a 16 bit system!"
|
||||
elif sizeof(int) == 4:
|
||||
echo("running on a 32 bit system!")
|
||||
echo "running on a 32 bit system!"
|
||||
elif sizeof(int) == 8:
|
||||
echo("running on a 64 bit system!")
|
||||
echo "running on a 64 bit system!"
|
||||
else:
|
||||
echo("cannot happen!")
|
||||
echo "cannot happen!"
|
||||
|
||||
The ``when`` statement is almost identical to the ``if`` statement with some
|
||||
exceptions:
|
||||
|
|
@ -435,7 +435,7 @@ Example:
|
|||
if a[j][i] == 7:
|
||||
found = true
|
||||
break myblock # leave the block, in this case both for-loops
|
||||
echo(found)
|
||||
echo found
|
||||
|
||||
The block statement is a means to group statements to a (named) ``block``.
|
||||
Inside the block, the ``break`` statement is allowed to leave the block
|
||||
|
|
@ -462,10 +462,10 @@ While statement
|
|||
Example:
|
||||
|
||||
.. code-block:: nim
|
||||
echo("Please tell me your password: \n")
|
||||
echo "Please tell me your password: \n"
|
||||
var pw = readLine(stdin)
|
||||
while pw != "12345":
|
||||
echo("Wrong password! Next try: \n")
|
||||
echo "Wrong password! Next try: \n"
|
||||
pw = readLine(stdin)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -546,7 +546,7 @@ so that the builtin ``echo`` proc does what is expected:
|
|||
.. code-block:: nim
|
||||
proc echo*(x: varargs[expr, `$`]) {...}
|
||||
|
||||
echo(@[1, 2, 3])
|
||||
echo @[1, 2, 3]
|
||||
# prints "@[1, 2, 3]" and not "123"
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue