From 9fcd5252c79b982d90b5c17f81253c2951acac1f Mon Sep 17 00:00:00 2001 From: Oscar Campbell Date: Sun, 31 May 2015 03:59:31 +0200 Subject: Fix doc for #2523, regarding numeric literals. --- doc/manual/lexing.txt | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'doc') diff --git a/doc/manual/lexing.txt b/doc/manual/lexing.txt index ab1cd632d..fab6da416 100644 --- a/doc/manual/lexing.txt +++ b/doc/manual/lexing.txt @@ -276,7 +276,7 @@ Numerical constants are of a single type and have the form:: bindigit = '0'..'1' HEX_LIT = '0' ('x' | 'X' ) hexdigit ( ['_'] hexdigit )* DEC_LIT = digit ( ['_'] digit )* - OCT_LIT = '0o' octdigit ( ['_'] octdigit )* + OCT_LIT = '0' ('o' | 'c' | 'C') octdigit ( ['_'] octdigit )* BIN_LIT = '0' ('b' | 'B' ) bindigit ( ['_'] bindigit )* INT_LIT = HEX_LIT @@ -297,15 +297,17 @@ Numerical constants are of a single type and have the form:: exponent = ('e' | 'E' ) ['+' | '-'] digit ( ['_'] digit )* FLOAT_LIT = digit (['_'] digit)* (('.' (['_'] digit)* [exponent]) |exponent) - FLOAT32_LIT = HEX_LIT '\'' ('f'|'F') '32' - | (FLOAT_LIT | DEC_LIT | OCT_LIT | BIN_LIT) ['\''] ('f'|'F') '32' - FLOAT64_LIT = HEX_LIT '\'' ('f'|'F') '64' - | (FLOAT_LIT | DEC_LIT | OCT_LIT | BIN_LIT) ['\''] ('f'|'F') '64' + FLOAT32_SUFFIX = ('f' | 'F') ['32'] + FLOAT32_LIT = HEX_LIT '\'' FLOAT32_SUFFIX + | (FLOAT_LIT | DEC_LIT | OCT_LIT | BIN_LIT) ['\''] FLOAT32_SUFFIX + FLOAT64_SUFFIX = ( ('f' | 'F') '64' ) | 'd' | 'D' + FLOAT64_LIT = HEX_LIT '\'' FLOAT64_SUFFIX + | (FLOAT_LIT | DEC_LIT | OCT_LIT | BIN_LIT) ['\''] FLOAT64_SUFFIX As can be seen in the productions, numerical constants can contain underscores for readability. Integer and floating point literals may be given in decimal (no -prefix), binary (prefix ``0b``), octal (prefix ``0o``) and hexadecimal +prefix), binary (prefix ``0b``), octal (prefix ``0o`` or ``0c``) and hexadecimal (prefix ``0x``) notation. There exists a literal for each numerical type that is @@ -331,8 +333,11 @@ The type suffixes are: ``'u16`` uint16 ``'u32`` uint32 ``'u64`` uint64 + ``'f`` float32 + ``'d`` float64 ``'f32`` float32 ``'f64`` float64 + ``'f128`` float128 ================= ========================= Floating point literals may also be in binary, octal or hexadecimal @@ -344,8 +349,8 @@ is approximately 1.72826e35 according to the IEEE floating point standard. Operators --------- -In Nim one can define his own operators. An operator is any -combination of the following characters:: +Nim allows user defined operators. An operator is any combination of the +following characters:: = + - * / < > @ $ ~ & % | @@ -355,7 +360,7 @@ These keywords are also operators: ``and or not xor shl shr div mod in notin is isnot of``. `=`:tok:, `:`:tok:, `::`:tok: are not available as general operators; they -are used for other notational purposes. +are used for other notational purposes. ``*:`` is as a special case the two tokens `*`:tok: and `:`:tok: (to support ``var v*: T``). -- cgit 1.4.1-2-gfad0 From 9d3b2d1e058990df65c44f76e2c07eeb1c623dbb Mon Sep 17 00:00:00 2001 From: apense Date: Thu, 4 Jun 2015 13:31:40 -0400 Subject: Fixed code indentation in procs.txt Now matches tut2.txt --- doc/manual/procs.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'doc') diff --git a/doc/manual/procs.txt b/doc/manual/procs.txt index 38e343686..23b5e4d1e 100644 --- a/doc/manual/procs.txt +++ b/doc/manual/procs.txt @@ -404,7 +404,7 @@ dispatch. result.a = a result.b = b -echo eval(newPlus(newPlus(newLit(1), newLit(2)), newLit(4))) + echo eval(newPlus(newPlus(newLit(1), newLit(2)), newLit(4))) In the example the constructors ``newLit`` and ``newPlus`` are procs because they should use static binding, but ``eval`` is a method because it -- cgit 1.4.1-2-gfad0 From 846489f81330a092953ca5d4651d72f6e1341cd7 Mon Sep 17 00:00:00 2001 From: apense Date: Thu, 4 Jun 2015 16:18:18 -0400 Subject: Fixed links in Error hierarchy Manual contained invalid links --- doc/exception_hierarchy_fragment.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'doc') diff --git a/doc/exception_hierarchy_fragment.txt b/doc/exception_hierarchy_fragment.txt index f4a419fc4..a02d9ccef 100644 --- a/doc/exception_hierarchy_fragment.txt +++ b/doc/exception_hierarchy_fragment.txt @@ -11,8 +11,8 @@ * `FloatInvalidOpError `_ * `FloatOverflowError `_ * `FloatUnderflowError `_ - * `FieldError `_ - * `IndexError `_ + * `FieldError `_ + * `IndexError `_ * `ObjectAssignmentError `_ * `ObjectConversionError `_ * `ValueError `_ -- cgit 1.4.1-2-gfad0 From ab1b1c9251f6d787cf78eefd2c3d1d391f5287fd Mon Sep 17 00:00:00 2001 From: apense Date: Mon, 8 Jun 2015 16:03:57 -0400 Subject: Note about deprecation in generics.txt I'm happy to change the wording or anything. It does seem like an important thing to mention, though. It might be better not to even mention typeless procs so as not to encourage bad behavior. --- doc/manual/generics.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'doc') diff --git a/doc/manual/generics.txt b/doc/manual/generics.txt index 2736f88fb..f82cad531 100644 --- a/doc/manual/generics.txt +++ b/doc/manual/generics.txt @@ -164,11 +164,13 @@ Alternatively, the ``distinct`` type modifier can be applied to the type class to allow each param matching the type class to bind to a different type. If a proc param doesn't have a type specified, Nim will use the -``distinct auto`` type class (also known as ``any``): +``distinct auto`` type class (also known as ``any``). Note this behavior is +deprecated for procs; templates, however, support them: .. code-block:: nim # allow any combination of param types - proc concat(a, b): string = $a & $b + proc concat(a, b): string = $a & $b # deprecated + proc concat(a, b: any): string = $a & $b # preferred Procs written with the implicitly generic style will often need to refer to the type parameters of the matched generic type. They can be easily accessed using -- cgit 1.4.1-2-gfad0 From ed73a90bd3192f4994cc467f71900b62e39b0ec0 Mon Sep 17 00:00:00 2001 From: Oscar Campbell Date: Sun, 14 Jun 2015 18:36:35 +0200 Subject: Regarding num literals, mod paths, ident equality. --- doc/manual/lexing.txt | 27 ++++++++++++++++++--------- doc/manual/modules.txt | 8 ++++++++ 2 files changed, 26 insertions(+), 9 deletions(-) (limited to 'doc') diff --git a/doc/manual/lexing.txt b/doc/manual/lexing.txt index fab6da416..9419f8453 100644 --- a/doc/manual/lexing.txt +++ b/doc/manual/lexing.txt @@ -101,25 +101,28 @@ Two identifiers are considered equal if the following algorithm returns true: .. code-block:: nim proc sameIdentifier(a, b: string): bool = - a[0] == b[0] and a.replace("_", "").toLower == b.replace("_", "").toLower + a[0] == b[0] and + a.replace(re"_|–", "").toLower == b.replace(re"_|–", "").toLower That means only the first letters are compared in a case sensitive manner. Other -letters are compared case insensitively and underscores are ignored. +letters are compared case insensitively and underscores and en-dash (Unicode +point U+2013) are ignored. -This rather strange way to do identifier comparisons is called +This rather unorthodox way to do identifier comparisons is called `partial case insensitivity`:idx: and has some advantages over the conventional case sensitivity: It allows programmers to mostly use their own preferred -spelling style and libraries written by different programmers cannot use -incompatible conventions. A Nim-aware editor or IDE can show the identifiers as -preferred. Another advantage is that it frees the programmer from remembering +spelling style, be it humpStyle, snake_style or dash–style and libraries written +by different programmers cannot use incompatible conventions. +A Nim-aware editor or IDE can show the identifiers as preferred. +Another advantage is that it frees the programmer from remembering the exact spelling of an identifier. The exception with respect to the first letter allows common code like ``var foo: Foo`` to be parsed unambiguously. -Historically, Nim was a `style-insensitive`:idx: language. This means that it -was not case-sensitive and underscores were ignored and there was no distinction -between ``foo`` and ``Foo``. +Historically, Nim was a fully `style-insensitive`:idx: language. This meant that +it was not case-sensitive and underscores were ignored and there was no even a +distinction between ``foo`` and ``Foo``. String literals @@ -345,6 +348,12 @@ notation: ``0B0_10001110100_0000101001000111101011101111111011000101001101001001'f64`` is approximately 1.72826e35 according to the IEEE floating point standard. +Literals are bounds checked so that they fit the datatype. Non base-10 +literals are used mainly for flags and bit pattern representations, therefore +bounds checking is done on bit width, not value range. If the literal fits in +the bit width of the datatype, it is accepted. +Hence: 0b10000000'u8 == 0x80'u8 == 128, but, 0b10000000'i8 == 0x80'i8 == -1 +instead of causing an overflow error. Operators --------- diff --git a/doc/manual/modules.txt b/doc/manual/modules.txt index fe3360773..813505769 100644 --- a/doc/manual/modules.txt +++ b/doc/manual/modules.txt @@ -146,6 +146,14 @@ modules don't need to import a module's dependencies: var x: MyObject echo($x) +Note on paths +----------- +In module related statements, if any part of the module name / +path begins with a number, you may have to quote it in double quotes. +In the following example, it would be seen as a literal number '3.0' of type +'float64' if not quoted, if uncertain - quote it: +.. code-block:: nim + import "gfx/3d/somemodule" Scope rules ----------- -- cgit 1.4.1-2-gfad0