diff options
-rw-r--r-- | doc/tut1.txt | 13 | ||||
-rw-r--r-- | lib/impure/re.nim | 1 | ||||
-rw-r--r-- | lib/pure/pegs.nim | 4 | ||||
-rw-r--r-- | web/news.txt | 10 |
4 files changed, 19 insertions, 9 deletions
diff --git a/doc/tut1.txt b/doc/tut1.txt index 2ca2a8ddd..28e23b0f0 100644 --- a/doc/tut1.txt +++ b/doc/tut1.txt @@ -735,12 +735,10 @@ However, this cannot be done for mutually recursive procedures: proc even(n: int): bool proc odd(n: int): bool = - if n == 1: return true - else: return even(n-1) + n == 1 or even(n-1) proc even(n: int): bool = - if n == 0: return true - else: return odd(n-1) + n == 0 or odd(n-1) Here ``odd`` depends on ``even`` and vice versa. Thus ``even`` needs to be introduced to the compiler before it is completely defined. The syntax for @@ -750,6 +748,9 @@ procedure's body. Later versions of the language may get rid of the need for forward declarations. +The example also shows that a proc's body can consist of a single expression +whose value is then returned implicitly. + Iterators ========= @@ -848,7 +849,7 @@ procedure; the length never counts the terminating zero. Accessing the terminating zero is no error and often leads to simpler code: .. code-block:: nimrod - if s[i] == 'a' and s[i+1] == 'b' and s[i+2] == '\0': + if s[i] == 'a' and s[i+1] == 'b': # no need to check whether ``i < len(s)``! ... @@ -1168,7 +1169,7 @@ subdivided in height levels accessed through their integer index: echo len(tower) # --> 10 echo len(tower[1]) # --> 4 echo repr(tower) # --> [[slowBlink, mediumBlink, ...more output.. - # The following lines don't compile due to type mistmatch errors + # The following lines don't compile due to type mismatch errors #tower[north][east] = on #tower[0][1] = on diff --git a/lib/impure/re.nim b/lib/impure/re.nim index ef02a3b1d..5041ed3ba 100644 --- a/lib/impure/re.nim +++ b/lib/impure/re.nim @@ -242,6 +242,7 @@ template `=~` *(s: string, pattern: TRegEx): expr = bind maxSubPatterns when not definedInScope(matches): var matches {.inject.}: array[0..maxSubPatterns-1, string] + {.warning: "injected 'matches' might be affected by new scoping rules in 0.9.4".} match(s, pattern, matches) # ------------------------- more string handling ------------------------------ diff --git a/lib/pure/pegs.nim b/lib/pure/pegs.nim index 240ea0945..dd694fe04 100644 --- a/lib/pure/pegs.nim +++ b/lib/pure/pegs.nim @@ -870,6 +870,7 @@ template `=~`*(s: string, pattern: TPeg): bool = bind maxSubpatterns when not definedInScope(matches): var matches {.inject.}: array[0..maxSubpatterns-1, string] + {.warning: "injected 'matches' might be affected by new scoping rules in 0.9.4".} match(s, pattern, matches) # ------------------------- more string handling ------------------------------ @@ -1718,6 +1719,7 @@ when isMainModule: assert match("_______ana", peg"A <- 'ana' / . A") assert match("abcs%%%", peg"A <- ..A / .A / '%'") + var matches: array[0..maxSubpatterns-1, string] if "abc" =~ peg"{'a'}'bc' 'xyz' / {\ident}": assert matches[0] == "abc" else: @@ -1742,8 +1744,6 @@ when isMainModule: else: assert false - when not definedInScope(matches): - var matches: array[0..maxSubpatterns-1, string] if match("abcdefg", peg"c {d} ef {g}", matches, 2): assert matches[0] == "d" assert matches[1] == "g" diff --git a/web/news.txt b/web/news.txt index 26c681d95..ef4255402 100644 --- a/web/news.txt +++ b/web/news.txt @@ -30,7 +30,7 @@ Library Additions - ``system.fields`` and ``system.fieldPairs`` support ``object`` too; they used to only support tuples. - Added ``system.CurrentSourcePath`` returning the full file-system path of - the current source file + the current source file. Changes affecting backwards compatibility @@ -39,6 +39,12 @@ Changes affecting backwards compatibility - ``shared`` is a keyword now. - Deprecated ``sockets.recvLine`` and ``asyncio.recvLine``, added ``readLine`` instead. +- The way indentation is handled in the parser changed significantly. However, + this affects very little (if any) real world code. +- The expression/statement unification has been implemented. Again this + only affects edge cases and no known real world code. +- The scope rules of ``if`` statements will change in 0.9.4. This affects the + ``=~`` pegs/re templates. Compiler Additions @@ -74,6 +80,8 @@ Language Additions - Overloading based on ASTs has been implemented. - Generics are now supported for multi methods. - Objects can be initialized via an *object constructor expression*. +- There is a new syntactic construct ``(;)`` unifying expressions and + statements. 2012-09-23 Version 0.9.0 released |