Misc fixes

This commit is contained in:
flaviut 2014-07-18 16:15:17 -04:00
commit a5fdbc898e
9 changed files with 62 additions and 29 deletions

View file

@ -30,7 +30,7 @@ Alternate methods of indexing arrays are also allowed, the first type parameter
type type
PartsOfSpeech {.pure.} = enum PartsOfSpeech {.pure.} = enum
Pronoun, Verb, Article, Adjective, Noun, Adverb Pronoun, Verb, Article, Adjective, Noun, Adverb
let partOfSpeechExamples: array[PartsOfSpeech] = [ let partOfSpeechExamples: array[PartsOfSpeech, string] = [
"he", "reads", "the", "green", "book", "slowly" "he", "reads", "the", "green", "book", "slowly"
] ]
``` ```

View file

@ -18,7 +18,7 @@ block outer:
let b = 3 let b = 3
block: block:
let b = "3" # Probably a dumb idea let b = "3" # shadowing is probably a dumb idea
``` ```
Parentheses can be used as an expression, but they do not provide end of statement inference, so it is necessary to place semicolons yourself. An interesting and unexpected side effect of this syntax is that Nimrod is suitable even for brace purists! Parentheses can be used as an expression, but they do not provide end of statement inference, so it is necessary to place semicolons yourself. An interesting and unexpected side effect of this syntax is that Nimrod is suitable even for brace purists!

View file

@ -11,23 +11,23 @@ Nimrod also supports case statements, which are like switches in other languages
* It is required that every possible case be covered * It is required that every possible case be covered
``` nimrod ``` nimrod
case "charlie" case "charlie":
of "alfa": of "alfa":
echo "A" echo "A"
of "bravo": of "bravo":
echo "B" echo "B"
of "charlie": of "charlie":
echo "C" echo "C"
else: else:
echo "Unrecognized letter" echo "Unrecognized letter"
case 'h': case 'h':
of 'a', 'e', 'i', 'o', 'u': of 'a', 'e', 'i', 'o', 'u':
echo "Vowel" echo "Vowel"
of '\127'..'\255': of '\127'..'\255':
echo "Unknown" echo "Unknown"
else: else:
echo "Consonant" echo "Consonant"
proc positiveOrNegative(num: int): string = proc positiveOrNegative(num: int): string =
result = case num: result = case num:
@ -54,11 +54,11 @@ Another feature of case statements is that the possible values are narrowed, mea
``` nimrod ``` nimrod
let x = 2 let x = 2
case (x and 3) + 7 case (x and 3) + 7:
of 7: echo "A" of 7: echo "A"
of 8: echo "B" of 8: echo "B"
of 9: echo "C" of 9: echo "C"
of 10: echo "D" of 10: echo "D"
``` ```
``` console ``` console
$ nimrod c -r ./case_stmts_1.nim $ nimrod c -r ./case_stmts_1.nim

View file

@ -88,7 +88,7 @@ Closure iterators hold on to their state and can be resumed at any time. The `fi
``` nimrod ``` nimrod
proc countTo(n: int): iterator(): int = proc countTo(n: int): iterator(): int =
return iterator (): int = return iterator(): int =
var i = 0 var i = 0
while i <= n: while i <= n:
yield i yield i
@ -100,7 +100,7 @@ echo countTo20()
var output = "" var output = ""
while not finished(countTo20): while not finished(countTo20):
output.add($countTo20()) output.add($countTo20() & " ")
echo output echo output
output = "" output = ""

View file

@ -10,7 +10,7 @@ When inside a loop, `continue` can be used to skip the rest of the loop body and
Along with [its other uses](/block/), the `block` statement can be used to create a label so that it's possible to break out of nested loops. Along with [its other uses](/block/), the `block` statement can be used to create a label so that it's possible to break out of nested loops.
``` nimrod <!--skip-->``` nimrod
import strutils, math import strutils, math
randomize() randomize()

View file

@ -10,7 +10,7 @@ title: Main
Getting started? Head over to the [installation instructions](/getting_started/)! Getting started? Head over to the [installation instructions](/getting_started/)!
``` nimrod <!--skip-->``` nimrod
import tables, strutils import tables, strutils
var wordFrequencies = newCountTable[string]() var wordFrequencies = newCountTable[string]()

View file

@ -17,7 +17,7 @@ Integers can also have `0[xX]`, `0o`, `0[Bb]` prepended to indicate a hex, octal
``` nimrod ``` nimrod
let let
a: int8 = 0x7F # Works a: int8 = 0x7F # Works
b: uint8 = 0x1111_1111 # Works b: uint8 = 0b1111_1111 # Works
d = 0xFF # type is int d = 0xFF # type is int
c: uint8 = 256 # Compile time error c: uint8 = 256 # Compile time error
``` ```

View file

@ -6,7 +6,7 @@ title: Seqs
Seqs provide dynamically expandable storage, they are extended as needed. Seqs provide dynamically expandable storage, they are extended as needed.
There are two ways to create seqs, with the `@` operator and with the `newSeq[T](n: int)` method. Once a seq is created, it can be modified using the `add(item: T)`, `remove(idx: int)`. The length of a seq can be found through `len: int`, and the maximum index through `high: int`. The standard `items: T` and `pairs: tuple[i: int, v: T]` iterators are also available. There are two ways to create seqs, with the `@` operator and with the `newSeq[T](n: int)` method. Once a seq is created, it can be modified using the `add(item: T)`, `delete(idx: int)`. The length of a seq can be found through `len: int`, and the maximum index through `high: int`. The standard `items: T` and `pairs: tuple[i: int, v: T]` iterators are also available.
``` nimrod ``` nimrod
var var
@ -19,7 +19,7 @@ for i, v in a:
for i in 4..100: for i in 4..100:
b.add(i * i) b.add(i * i)
b.remove(0) # takes «O(n)» time b.delete(0) # takes «O(n)» time
b = a[0] & b # Same as original b b = a[0] & b # Same as original b
``` ```

33
validcodehashes.txt Normal file
View file

@ -0,0 +1,33 @@
489fd1e2356eb85f81bac48e45b186a7
da4974745059fff2c0c3d0af688042ab
ef380e36bcc0ebf11902cefaa10ec31b
98f917ee2165bc9461c3e9316e8e70ee
b243592b06e93bb3cf1f7d62a25abaa3
1f6e436b0fbdc68e1776422df711c2bb
394ca46d1bf22dedef7e6e753bd033c8
8afe80a509d316a3feb3caa1c985760a
9551565b83418876b5211869acbcf7cc
ade4a4b3b6973bbb44f2e74aee1954f7
26ded9e69879069fb8970403e87a24c9
3f3dfdee017d0c329d594e9fe038ed9f
cf09b588bb8b3c6979d24dcaff932c68
448a6cb31706860e7957f8dcca732d85
ac4fe7f722b390100501e638ce8a9750
eb67590e2472e05b207856959e5461c8
10ae94a28a0d8f23aff5afaa0367cf27
1865b827bef365e6422beb6bc076a25d
398863bccd3691b42500dfa143a3230b
cdf52a33222c8402025606b0bb4da4d9
b8875a112bc13ea83556bcf385c1160b
30111c31170d8cd9979ae7d88fa276e7
0e641a70cbd7b3e955bb29bde934f36e
d599ef057eaaac83139eb8f949cef356
e0e0e0b5724e296371d1704996096343
2d60def87d4fa95e26b9f8eade4b0baa
180c2775b35bd48de55453713ccb5828
d01dfb20f1d8c1741eef320e82bfcdc2
4f19f7a7103d8aec86dd2ab995e5a0a8
fbb7977d27de5251fa736a627aaa8311
847d1c4525d9056206a1e4f4855a9e10
e4b29a303e0a22cab1f2bfb769ce66c5