reorganize and elaborate on unicode
This commit is contained in:
parent
525895019d
commit
e903e64461
6 changed files with 11 additions and 10 deletions
|
|
@ -1,47 +0,0 @@
|
|||
---
|
||||
title: Primitive Data Structures
|
||||
---
|
||||
# Primitive Data Structures
|
||||
|
||||
Nimrod contains several basic builtin data structures: sequences, strings, bitsets, and arrays.
|
||||
|
||||
## Strings
|
||||
|
||||
``` nimrod
|
||||
echo "words words words ⚑"
|
||||
echo """
|
||||
<html>
|
||||
<head>
|
||||
</head>\n\n
|
||||
|
||||
<body>
|
||||
</body>
|
||||
</html> """
|
||||
|
||||
proc re(s: string): string = s
|
||||
|
||||
echo r" "" "
|
||||
echo re"\b[a-z]++\b"
|
||||
```
|
||||
``` console
|
||||
$ nimrod c -r strings.nim
|
||||
words words words ⚑
|
||||
<html>
|
||||
<head>
|
||||
<head/>\n\n
|
||||
|
||||
<body>
|
||||
<body/>
|
||||
<html/>
|
||||
"
|
||||
\b[a-z]++\b
|
||||
```
|
||||
|
||||
There are several types of strings literals:
|
||||
|
||||
- Quoted Strings: Created by wrapping the body in triple quotes, they never interpret escape codes
|
||||
- Raw Strings: created by prefixing the string with an `r`. There are no escape sequences don't work, except for `"`, which can be escaped as `""`
|
||||
- Proc Strings: raw strings, but the method name that prefixes the string is called
|
||||
|
||||
### A note about unicode
|
||||
Unicode symbols are allowed in strings, but are not treated in any special way, so if you want count glyphs or uppercase unicode symbols, you must use the `unicode` module.
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
---
|
||||
title: Primitives
|
||||
---
|
||||
# Primitives
|
||||
|
||||
Nimrod has several primitive types:
|
||||
|
||||
* signed integers: `int8`, `int16`, `int32`, `int64`, and `int`, where `int` is the same size as a pointer
|
||||
* unsigned integers are similar with `u` prepended to the type
|
||||
* floating points numbers: `float32`, `float64`, and `float`, where `float` is the processor's fastest type
|
||||
* characters: `char`, and basically an alias for uint8
|
||||
|
||||
To indicate the size of an integer literal, append `u` or `i` and the size you'd like to the end. However, this is not typically necessary.
|
||||
|
||||
Integers can also have `0[xX]`, `0o`, `0[Bb]` prepended to indicate a hex, octal, or binary literal, respectively. Underscores are also valid in literals, and can help with readability.
|
||||
|
||||
``` nimrod
|
||||
let
|
||||
a: int8 = 0x7F # Works
|
||||
b: uint8 = 0x1111_1111 # Works
|
||||
d = 0xFF # type is int
|
||||
c: uint8 = 256 # Compile time error
|
||||
```
|
||||
|
||||
Precedence rules are the same as most other languages, but instead of `^`, `&`, `|`, `>>`, `<<`, the `xor`, `and`, `or`, `shr`, `shl` operators are used, respectively.
|
||||
|
||||
``` nimrod
|
||||
let
|
||||
a: int = 2
|
||||
b: int = 4
|
||||
echo 4/2
|
||||
```
|
||||
``` console
|
||||
$ nimrod c -r numbers2.nim
|
||||
2.0
|
||||
```
|
||||
Another difference that may be surprising is that the `/` operator returns a floating point result, even when the operands are integers. If integer division is needed, the `div` operator should be used.
|
||||
Loading…
Add table
Add a link
Reference in a new issue