Nim Tutorial (Part I) 0.17.1(Some languages call them methods or functions.) In Nim new procedures are defined with the proc keyword: proc yes(question: string): bool = echo question, "(y/n)" while true: case readLine(stdin) always returned automatically at the end of a procedure if there is no return statement at the exit. proc sumTillNegative(x: varargs[int]): int = for i in x: if i < 0: return result = result with var in the procedure body. Shadowing the parameter name is possible, and actually an idiom: proc printSeq(s: seq, nprinted: int = -1) = var nprinted = if nprinted == -1: s.len else: min(nprinted0 码力 | 24 页 | 271.23 KB | 1 年前3
Nim 2.0.8 ManualMultiline comment in already commented out code.]# proc p[T](x: T) = discard ]# Multiline documentation comments also exist and support nesting too: proc foo = ##[Long documentation comment here. ]## You include interface is isnot iterator let macro method mixin mod nil not notin object of or out proc ptr raise ref return shl shr static template try tuple type using var when while xor yield dentifier equality Two identifiers are considered equal if the following algorithm returns true: proc sameIdentifier(a, b: string): bool = a[0] == b[0] and a.replace(_", "").toLowerAscii ==0 码力 | 132 页 | 5.73 MB | 1 年前3
Computer Programming with the Nim Programming Language.. 164 Nested procedures and closures ..... 165 Anonymous procedures ..... 167 Compile-time proc execution ..... 168 Inlining procedures ..... 168 Recursion ..... 169 Converters ..... 169 equivalent to myNum.abs. The Python code from above might look like this in Nim: type User = object proc say(self: User) = echo ("It does not work!") let user = User() user.say() Instead of actual problem in Nim. This is because procedure overload resolution typically works reliably when the proc parameter types are not all identical. Conflicts may only occur in rare situations for constants or0 码力 | 512 页 | 3.54 MB | 1 年前3
Computer Programming with the Nim Programming Language.. 164 Nested procedures and closures ..... 165 Anonymous procedures ..... 167 Compile-time proc execution ..... 168 Inlining procedures ..... 168 Recursion ..... 169 Converters ..... 169 equivalent to myNum.abs. The Python code from above might look like this in Nim: type User = object proc say(self: User) = echo ("It does not work!") let user = User() user.say() Instead of actual problem in Nim. This is because procedure overload resolution typically works reliably when the proc parameter types are not all identical. Conflicts may only occur in rare situations for constants or0 码力 | 512 页 | 3.53 MB | 1 年前3
Computer Programming with the Nim Programming Language.. 164 Nested procedures and closures ..... 165 Anonymous procedures ..... 167 Compile-time proc execution ..... 168 Inlining procedures ..... 168 Recursion ..... 169 Converters ..... 169 equivalent to myNum.abs. The Python code from above might look like this in Nim: type User = object proc say(self: User) = echo ("It does not work!") let user = User() user.say() Instead of actual problem in Nim. This is because procedure overload resolution typically works reliably when the proc parameter types are not all identical. Conflicts may only occur in rare situations for constants or0 码力 | 512 页 | 3.50 MB | 1 年前3
Computer Programming with the Nim Programming Language.. 164 Nested procedures and closures ..... 165 Anonymous procedures ..... 167 Compile-time proc execution ..... 168 Inlining procedures ..... 168 Recursion ..... 169 Converters ..... 169 equivalent to myNum.abs. The Python code from above might look like this in Nim: type User = object proc say(self: User) = echo ("It does not work!") let user = User() user.say() Instead of actual problem in Nim. This is because procedure overload resolution typically works reliably when the proc parameter types are not all identical. Conflicts may only occur in rare situations for constants or0 码力 | 512 页 | 3.53 MB | 1 年前3
Computer Programming with the Nim Programming Language.. 164 Nested procedures and closures ..... 165 Anonymous procedures ..... 167 Compile-time proc execution ..... 168 Inlining procedures ..... 168 Recursion ..... 169 Converters ..... 169 equivalent to myNum.abs. The Python code from above might look like this in Nim: type User = object proc say(self: User) = echo ("It does not work!") let user = User() user.say() Instead of actual problem in Nim. This is because procedure overload resolution typically works reliably when the proc parameter types are not all identical. Conflicts may only occur in rare situations for constants or0 码力 | 512 页 | 3.52 MB | 1 年前3
Computer Programming with the Nim Programming Language.. 164 Nested procedures and closures ..... 165 Anonymous procedures ..... 167 Compile-time proc execution ..... 168 Inlining procedures ..... 168 Recursion ..... 169 Converters ..... 169 equivalent to myNum.abs. The Python code from above might look like this in Nim: type User = object proc say(self: User) = echo ("It does not work!") let user = User() user.say() Instead of actual problem in Nim. This is because procedure overload resolution typically works reliably when the proc parameter types are not all identical. Conflicts may only occur in rare situations for constants or0 码力 | 512 页 | 3.50 MB | 1 年前3
Computer Programming with the Nim Programming Language.. 160 Nested procedures and closures ..... 162 Anonymous procedures ..... 164 Compile-time proc execution ..... 164 Inlining procedures ..... 165 Recursion ..... 165 Converters ..... 166 equivalent to myNum.abs. The Python code from above might look like this in Nim: type User = object proc say(self: User) = echo ("It does not work!") let user = User() user.say() Instead of actual problem in Nim. This is because procedure overload resolution typically works reliably when the proc parameter types are not all identical. Conflicts may only occur in rare situations for constants or0 码力 | 508 页 | 3.50 MB | 1 年前3
Computer Programming with the Nim Programming Language.. 164 Nested procedures and closures ..... 165 Anonymous procedures ..... 167 Compile-time proc execution ..... 168 Inlining procedures ..... 168 Recursion ..... 169 Converters ..... 169 equivalent to myNum.abs. The Python code from above might look like this in Nim: type User = object proc say(self: User) = echo ("It does not work!") let user = User() user.say() Instead of actual problem in Nim. This is because procedure overload resolution typically works reliably when the proc parameter types are not all identical. Conflicts may only occur in rare situations for constants or0 码力 | 512 页 | 3.50 MB | 1 年前3
共 1000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 100













