Add formatting css and reorganize

This commit is contained in:
flaviut 2014-05-31 21:16:18 -04:00
commit 5747e5fa90
21 changed files with 308 additions and 199 deletions

2
.gitignore vendored
View file

@ -2,3 +2,5 @@
nohup.out nohup.out
output/ output/
tmp/ tmp/
crash.log

6
Rules
View file

@ -18,8 +18,10 @@ compile '*' do
filter :kramdown filter :kramdown
layout 'blank' layout 'blank'
elsif item[:extension] == 'md' elsif item[:extension] == 'md'
filter :kramdown filter :kramdown, {:input => 'GFM'}
filter :colorize_syntax, :default_colorizer => :pygmentsrb filter :colorize_syntax, :default_colorizer => :pygmentize
filter :code_class_simplfier
filter :relativize_paths, :type => :html
layout 'default' layout 'default'
elsif item[:extension] == 'css' elsif item[:extension] == 'css'
# don’t filter stylesheets # don’t filter stylesheets

View file

@ -1,18 +0,0 @@
{
"title": "Nimrod by Example",
"description": "A book of short examples of Nimrod features",
"github": null,
"githubHost": "https://github.com/",
"plugins": [],
"links": {
"home": "http://nimrod-lang.org/",
"about": false,
"issues": null,
"contribute": null,
"sharing": {
"google": false,
"facebook": false,
"twitter": false
}
}
}

View file

@ -7,7 +7,7 @@ Nimrod also supports case statements, which are like switches in other languages
* case statements, like most things, are actually expressions * case statements, like most things, are actually expressions
* 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"
@ -38,11 +38,11 @@ proc positiveOrNegative(num: int): string =
"impossible" "impossible"
echo positiveOrNegative(-1) echo positiveOrNegative(-1)
~~~ ```
~~~ ``` console
$ nimrod c -r ./case_stmts.nim $ nimrod c -r ./case_stmts.nim
C C
Consonant Consonant
negative negative
~~~ ```

View file

@ -6,7 +6,7 @@ Nimrod has first class iterators and syntax to use them, for loops. The `continu
When iterating over an object with one item, Nimrod will call an iterator called `items` with the first parameter the type you want to iterate over. The same thing happens when iterating with two items, but in that case, the `pairs` iterator is called. When iterating over an object with one item, Nimrod will call an iterator called `items` with the first parameter the type you want to iterate over. The same thing happens when iterating with two items, but in that case, the `pairs` iterator is called.
~~~ nimrod ``` nimrod
type type
TRange = object TRange = object
low: int low: int
@ -24,18 +24,18 @@ iterator pairs(range: TRange): tuple[a: int, b: char] =
for i, c in TRange(low: 1, high: 3): for i, c in TRange(low: 1, high: 3):
echo c echo c
~~~ ```
~~~ ``` console
$ nimrod c -r items_pair.nim $ nimrod c -r items_pair.nim
b b
c c
d d
~~~ ```
## Inline Iterators ## Inline Iterators
Inline iterators basically take the body of the for loop and inline it into the iterator. This means that they do not have any overhead from function calling, but if carelessly created may increase code size dramatically. Inline iterators basically take the body of the for loop and inline it into the iterator. This means that they do not have any overhead from function calling, but if carelessly created may increase code size dramatically.
~~~ nimrod ``` nimrod
iterator countTo(n: int): int = iterator countTo(n: int): int =
var i = 0 var i = 0
while i <= n: while i <= n:
@ -44,8 +44,8 @@ iterator countTo(n: int): int =
for i in countTo(5): for i in countTo(5):
echo i echo i
~~~ ```
~~~ ```console
$ nimrod c -r ./inline_iter.nim $ nimrod c -r ./inline_iter.nim
0 0
1 1
@ -53,13 +53,13 @@ $ nimrod c -r ./inline_iter.nim
3 3
4 4
5 5
~~~ ```
## Closure Iterators ## Closure Iterators
Closure iterators hold on to their state and can be resumed at any time. The `finished()` function can be used to check if there are any more elements available in the iterator. Closure iterators hold on to their state and can be resumed at any time. The `finished()` function can be used to check if there are any more elements available in the iterator.
~~~ 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
@ -81,10 +81,10 @@ let countTo9 = countTo(9)
for i in countTo9: for i in countTo9:
output.add($i) output.add($i)
echo output echo output
~~~ ```
~~~ ```console
$ nimrod c -r ./closure_iter.nim $ nimrod c -r ./closure_iter.nim
0 0
12345678910111213141516171819200 12345678910111213141516171819200
0123456789 0123456789
~~~ ```

View file

@ -19,15 +19,15 @@ Once you have downloaded the appropriate distribution and extracted the files so
## Downloading from Git ## Downloading from Git
To install Nimrod from git, ensure that you have gcc installed on Windows, Linux, and BSDs and clang on Mac. Afterwards, run the following series of commands to download and bootstrap Nimrod: To install Nimrod from git, ensure that you have gcc installed on Windows, Linux, and BSDs and clang on Mac. Afterwards, run the following series of commands to download and bootstrap Nimrod:
~~~ ```console
git clone -b master git://github.com/Araq/Nimrod.git $ git clone -b master git://github.com/Araq/Nimrod.git
cd Nimrod $ cd Nimrod
git clone --depth 1 git://github.com/nimrod-code/csources $ git clone --depth 1 git://github.com/nimrod-code/csources
cd csources $ cd csources
sh build.sh # Replace with build.bat on windows $ sh build.sh # Replace with build.bat on windows
cd .. $ cd ..
bin/nimrod c koch $ bin/nimrod c koch
./koch boot -d:release $ ./koch boot -d:release
~~~ ```
Once compiled, you may want to add the `bin` directory to your path for easy access. Once compiled, you may want to add the `bin` directory to your path for easy access.

View file

@ -2,16 +2,16 @@
The code for a simple hello world program is as follows: The code for a simple hello world program is as follows:
~~~ Nimrod ``` nimrod
echo "Hello World" echo "Hello World"
~~~ ```
To compile and execute the program, the following command should be run To compile and execute the program, the following command should be run
~~~ ``` console
$ nimrod c -r --verbosity:0 ./helloworld.nim $ nimrod c -r --verbosity:0 ./helloworld.nim
Hello World Hello World
~~~ ```
The command has several elements: The command has several elements:

View file

@ -4,7 +4,7 @@ Nimrod many different control flow constructs, including the standard `if`s, `el
When inside a loop or block, it is possible to use `continue` or `break` any point, where `continue` skips to the next iteration and `break` ends the loop. The break statement can also receive the name of the block to break out of, so it is possible to break out of nested loops. When inside a loop or block, it is possible to use `continue` or `break` any point, where `continue` skips to the next iteration and `break` ends the loop. The break statement can also receive the name of the block to break out of, so it is possible to break out of nested loops.
~~~ Nimrod ``` nimrod
import strutils import strutils
let answer = 4 # Chosen by a fair dice roll, let answer = 4 # Chosen by a fair dice roll,
@ -25,4 +25,4 @@ block busyloops:
while true: while true:
while true: while true:
break busyloops break busyloops
~~~ ```

View file

@ -1,6 +1,6 @@
Nimrod is a powerful statically typed language that allows the programmer expressiveness without compromising run-time performance. Nimrod is a powerful statically typed language that allows the programmer expressiveness without compromising run-time performance.
~~~ nimrod ``` nimrod
import tables, strutils import tables, strutils
var wordFrequencies = initTable[string, int] var wordFrequencies = initTable[string, int]
@ -17,4 +17,4 @@ for word, frequency in wordFrequencies:
mostFrequentWord = word mostFrequentWord = word
echo "The most frequent word is '", word, "'" echo "The most frequent word is '", word, "'"
~~~ ```

View file

@ -10,13 +10,13 @@ To indicate the size of an integer literal, append `u` or `i` and the size you'd
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. 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 ``` nimrod
let let
a: int8 = 0x7F # Works a: int8 = 0x7F # Works
b: uint8 = 0x1111_1111 # Works b: uint8 = 0x1111_1111 # Works
d = 0xFF # type is int d = 0xFF # type is int
c: uint8 = 256 # Compile time error 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. Precedence rules are the same as most other languages, but instead of `^`, `&`, `|`, `>>`, `<<`, the `xor`, `and`, `or`, `shr`, `shl` operators are used, respectively.

View file

@ -2,7 +2,7 @@
In Nimrod, objects are like structs from C family languages and define a grouping of fields. In Nimrod, objects are like structs from C family languages and define a grouping of fields.
~~~ nimrod ``` nimrod
type type
Animal* = object Animal* = object
name*, genus*, species*: string name*, genus*, species*: string
@ -35,4 +35,4 @@ let spot = PAnimal(name: "Spot",
# Same as before, only pointer value is unchangeable # Same as before, only pointer value is unchangeable
spot.age = 2 spot.age = 2
~~~ ```

View file

@ -2,7 +2,7 @@
# OOP Macro # OOP Macro
This is the code that we currently must write to use OOP in nimrod: This is the code that we currently must write to use OOP in nimrod:
~~~nimrod ```nimrod
type Animal = type Animal =
ref object {.inheritable.} ref object {.inheritable.}
name: string name: string
@ -15,11 +15,11 @@ method vocalize(self: Dog): string = "woof"
type Cat = ref object of Animal type Cat = ref object of Animal
method vocalize(self: Cat): string = "meow" method vocalize(self: Cat): string = "meow"
~~~ ```
All these typedefs and `self: T` parameters are repetitive, so it'd be good to write a macro to mask them. Something like this would be best: All these typedefs and `self: T` parameters are repetitive, so it'd be good to write a macro to mask them. Something like this would be best:
~~~nimrod ```nimrod
class(Animal of TObject): class(Animal of TObject):
var name: string var name: string
method vocalize: string = "..." method vocalize: string = "..."
@ -38,9 +38,9 @@ proc run_test() =
pets.add Dog(name: "ruffles") pets.add Dog(name: "ruffles")
assert(@["meow", "woof"] == @[pets[0].vocalize, assert(@["meow", "woof"] == @[pets[0].vocalize,
pets[1].vocalize]) pets[1].vocalize])
~~~ ```
~~~nimrod ```nimrod
import macros import macros
macro class*(): stmt {.immediate.} = macro class*(): stmt {.immediate.} =
@ -214,4 +214,4 @@ class(Cat of Animal) do:
run_test() run_test()
echo "Tests passed!" echo "Tests passed!"
~~~ ```

View file

@ -1,101 +0,0 @@
* {
margin: 0;
padding: 0;
font-family: Georgia, Palatino, serif;
}
body {
background: #fff;
}
a {
text-decoration: none;
}
a:link,
a:visited {
color: #f30;
}
a:hover {
color: #f90;
}
#main {
position: absolute;
top: 40px;
left: 280px;
width: 500px;
}
#main h1 {
font-size: 40px;
font-weight: normal;
line-height: 40px;
letter-spacing: -1px;
}
#main p {
margin: 20px 0;
font-size: 15px;
line-height: 20px;
}
#main ul, #main ol {
margin: 20px;
}
#main li {
font-size: 15px;
line-height: 20px;
}
#main ul li {
list-style-type: square;
}
#sidebar {
position: absolute;
top: 40px;
left: 20px;
width: 200px;
padding: 20px 20px 0 0;
border-right: 1px solid #ccc;
text-align: right;
}
#sidebar h2 {
text-transform: uppercase;
font-size: 13px;
color: #333;
letter-spacing: 1px;
line-height: 20px;
}
#sidebar ul {
list-style-type: none;
margin: 20px 0;
}
#sidebar li {
font-size: 14px;
line-height: 20px;
}

View file

@ -0,0 +1,141 @@
* {
margin: 0;
padding: 0;
font-family: Georgia, Palatino, serif;
box-sizing: border-box;
}
body {
background: #E6E6E6;
color: #2B2B2B;
text-rendering: optimizelegibility;
}
a {
text-decoration: none;
}
a:link,
a:visited {
color: #DE1B1B;
}
a:hover {
color: #FE3B3B;
}
#main {
position: absolute;
top: 40px;
left: 255px;
max-width: 600px;
}
#main h1 {
font-size: 40px;
font-weight: normal;
line-height: 40px;
letter-spacing: -1px;
}
#main p {
margin: 20px 0;
font-size: 15px;
line-height: 20px;
}
#main ul, #main ol {
margin: 20px;
}
#main li {
font-size: 15px;
line-height: 20px;
}
#main ul li {
list-style-type: square;
}
#main table, th, td {
border-collapse: collapse;
border: 1px solid #CCC;
background-color: #EEEEEE;
padding: 3px;
font-size: 15px;
line-height: 20px;
}
#main code, code * {
font-family: Monaco,Menlo,Consolas,"Courier New",monospace;
}
#main code {
border-radius: 3px;
border: 1px solid #CCC;
background-color: #EEEEEE;
padding: 0px 3px;
}
#main pre code { /* Block Code */
display: block;
word-wrap: break-word;
overflow: auto;
white-space: pre-wrap; /* css-3 */
white-space: -moz-pre-wrap; /* Mozilla, since 1999 */
white-space: -pre-wrap; /* Opera 4-6 */
white-space: -o-pre-wrap; /* Opera 7 */
word-wrap: break-word; /* Internet Explorer 5.5+ */
border-radius: 3px;
border: 1px solid #CCC;
background-color: #EEEEEE;
padding: 20px 10px;
font-size: 15px;
margin: 30px 5px
}
#main span.line-numbers {
display: none;
}
#sidebar {
position: absolute;
top: 40px;
left: 20px;
width: 175px;
padding: 20px 20px 0 0;
border-right: 1px solid #ccc;
}
#sidebar h2 {
text-transform: uppercase;
font-size: 13px;
color: #333;
letter-spacing: 1px;
line-height: 20px;
}
#sidebar ul {
position: relative;
left: 30px;
list-style: decimal-leading-zero;
}
#sidebar li {
font-size: 14px;
line-height: 20px;
}

View file

@ -0,0 +1,72 @@
/* pygments-css colorful */
.codehilite .hll { background-color: #ffffcc }
.codehilite .c { color: #808080 } /* Comment */
.codehilite .err { color: #F00000; background-color: #F0A0A0 } /* Error */
.codehilite .k { color: #008000; font-weight: bold } /* Keyword */
.codehilite .o { color: #303030 } /* Operator */
.codehilite .cm { color: #808080 } /* Comment.Multiline */
.codehilite .cp { color: #507090 } /* Comment.Preproc */
.codehilite .c1 { color: #808080 } /* Comment.Single */
.codehilite .cs { color: #cc0000; font-weight: bold } /* Comment.Special */
.codehilite .gd { color: #A00000 } /* Generic.Deleted */
.codehilite .ge { font-style: italic } /* Generic.Emph */
.codehilite .gr { color: #FF0000 } /* Generic.Error */
.codehilite .gh { color: #000080; font-weight: bold } /* Generic.Heading */
.codehilite .gi { color: #00A000 } /* Generic.Inserted */
.codehilite .go { color: #808080 } /* Generic.Output */
.codehilite .gp {
color: #c65d09;
font-weight: bold;
/* NOTE: Hacks to allow copy-paste */
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
} /* Generic.Prompt */
.codehilite .gs { font-weight: bold } /* Generic.Strong */
.codehilite .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
.codehilite .gt { color: #0040D0 } /* Generic.Traceback */
.codehilite .kc { color: #008000; font-weight: bold } /* Keyword.Constant */
.codehilite .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */
.codehilite .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */
.codehilite .kp { color: #003080; font-weight: bold } /* Keyword.Pseudo */
.codehilite .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */
.codehilite .kt { color: #303090; font-weight: bold } /* Keyword.Type */
.codehilite .m { color: #6000E0; font-weight: bold } /* Literal.Number */
.codehilite .s { background-color: #fff0f0 } /* Literal.String */
.codehilite .na { color: #0000C0 } /* Name.Attribute */
.codehilite .nb { color: #007020 } /* Name.Builtin */
.codehilite .nc { color: #B00060; font-weight: bold } /* Name.Class */
.codehilite .no { color: #003060; font-weight: bold } /* Name.Constant */
.codehilite .nd { color: #505050; font-weight: bold } /* Name.Decorator */
.codehilite .ni { color: #800000; font-weight: bold } /* Name.Entity */
.codehilite .ne { color: #F00000; font-weight: bold } /* Name.Exception */
.codehilite .nf { color: #0060B0; font-weight: bold } /* Name.Function */
.codehilite .nl { color: #907000; font-weight: bold } /* Name.Label */
.codehilite .nn { color: #0e84b5; font-weight: bold } /* Name.Namespace */
.codehilite .nt { color: #007000 } /* Name.Tag */
.codehilite .nv { color: #906030 } /* Name.Variable */
.codehilite .ow { color: #000000; font-weight: bold } /* Operator.Word */
.codehilite .w { color: #bbbbbb } /* Text.Whitespace */
.codehilite .mf { color: #6000E0; font-weight: bold } /* Literal.Number.Float */
.codehilite .mh { color: #005080; font-weight: bold } /* Literal.Number.Hex */
.codehilite .mi { color: #0000D0; font-weight: bold } /* Literal.Number.Integer */
.codehilite .mo { color: #4000E0; font-weight: bold } /* Literal.Number.Oct */
.codehilite .sb { background-color: #fff0f0 } /* Literal.String.Backtick */
.codehilite .sc { color: #0040D0 } /* Literal.String.Char */
.codehilite .sd { color: #D04020 } /* Literal.String.Doc */
.codehilite .s2 { background-color: #fff0f0 } /* Literal.String.Double */
.codehilite .se { color: #606060; font-weight: bold; background-color: #fff0f0 } /* Literal.String.Escape */
.codehilite .sh { background-color: #fff0f0 } /* Literal.String.Heredoc */
.codehilite .si { background-color: #e0e0e0 } /* Literal.String.Interpol */
.codehilite .sx { color: #D02000; background-color: #fff0f0 } /* Literal.String.Other */
.codehilite .sr { color: #000000; background-color: #fff0ff } /* Literal.String.Regex */
.codehilite .s1 { background-color: #fff0f0 } /* Literal.String.Single */
.codehilite .ss { color: #A06000 } /* Literal.String.Symbol */
.codehilite .bp { color: #007020 } /* Name.Builtin.Pseudo */
.codehilite .vc { color: #306090 } /* Name.Variable.Class */
.codehilite .vg { color: #d07000; font-weight: bold } /* Name.Variable.Global */
.codehilite .vi { color: #3030B0 } /* Name.Variable.Instance */
.codehilite .il { color: #0000D0; font-weight: bold } /* Literal.Number.Integer.Long */

View file

@ -1,16 +1,16 @@
## Summary ## Summary
* [Getting Started](getting_started/) * [Getting Started](/getting_started/)
* [Hello World](hello_world/) * [Hello World](/hello_world/)
* [Numbers](numbers/) * [Numbers](/numbers/)
* [Variables](variables/page/) * [Variables](/variables/page/)
* [Result](variables/result/) * [Result](/variables/result/)
* [Objects](objects/) * [Objects](/objects/)
* [Enums](enums/) * [Enums](/enums/)
* [If, Else, While, Block](if_else_while/) * [If, Else, While, Block](/if_else_while/)
* [Case Statements](case/) * [Case Statements](/case/)
* [For Loops & Iterators](for_iterators/) * [For Loops & Iterators](/for_iterators/)
* [Exceptions](exceptions/) * [Exceptions](/exceptions/)
* [Functions]() * [Functions]()
* [Varargs](varargs/) * [Varargs](/varargs/)
* [OOP Macro](oop_macro/) * [OOP Macro](/oop_macro/)

View file

@ -2,41 +2,41 @@
Standard varargs simply allows you to pass multiple parameters to your function. Standard varargs simply allows you to pass multiple parameters to your function.
~~~ nimrod ``` nimrod
proc printThings(things: varargs[string]) = proc printThings(things: varargs[string]) =
for thing in things: for thing in things:
echo thing echo thing
printThings "words", "to", "print" printThings "words", "to", "print"
~~~ ```
~~~ ```console
$ nimrod c -r ./varargs1.nim $ nimrod c -r ./varargs1.nim
words words
to to
print print
~~~ ```
However, trying to run However, trying to run
~~~ nimrod ``` nimrod
printThings 1, "string", @[1, 2, 3] printThings 1, "string", @[1, 2, 3]
~~~ ```
will fail to compile because the compiler won't coerce anything into strings. Luckily enough, there is a tool to fix this, the coercing varargs: will fail to compile because the compiler won't coerce anything into strings. Luckily enough, there is a tool to fix this, the coercing varargs:
~~~ nimrod ``` nimrod
proc printThings(things: varargs[string, `$`]) = proc printThings(things: varargs[string, `$`]) =
for thing in things: for thing in things:
echo thing echo thing
printThings "thing 1", 2, @[4, 5, 6] printThings "thing 1", 2, @[4, 5, 6]
~~~ ```
~~~ ```console
$ nimrod c -r ./varargs2.nim $ nimrod c -r ./varargs2.nim
thing 1 thing 1
2 2
@[4, 5, 6] @[4, 5, 6]
~~~ ```
It works by finding a function `` `$` `` that returns string for each argument type, and applying it to each argument. It works by finding a function `` `$` `` that returns string for each argument type, and applying it to each argument.

View file

@ -2,7 +2,7 @@
Nimrod supports three different types of variables, `let`, `var`, and `const`. As with most things, multiple variables can be declared in the same section. Nimrod supports three different types of variables, `let`, `var`, and `const`. As with most things, multiple variables can be declared in the same section.
~~~ nimrod ``` nimrod
proc getAlphabet(): string = proc getAlphabet(): string =
result = "" result = ""
for letter in 'a'..'z': for letter in 'a'..'z':
@ -23,22 +23,22 @@ b.inc # This is also fine.
c.add "bar" # This will result in an error. c.add "bar" # This will result in an error.
d.inc # As will this. d.inc # As will this.
~~~ ```
~~~ ``` console
$ nimrod c --verbosity:2 ./assignment.nim $ nimrod c --verbosity:2 ./assignment.nim
a20.nim(19, 0) Error: for a 'var' type a variable needs to be passed a20.nim(19, 0) Error: for a 'var' type a variable needs to be passed
c.add "bar" # This will result in an error. c.add "bar" # This will result in an error.
^ ^
~~~ ```
Without `--verbosity:2` only the error will be shown. Without `--verbosity:2` only the error will be shown.
A `const` variable's value will be evaluated at compile-time, so if you inspect the C sources, you'll see the following line: A `const` variable's value will be evaluated at compile-time, so if you inspect the C sources, you'll see the following line:
~~~ C ``` c
STRING_LITERAL(TMP129, "abcdefghijklmnopqrstuvwxyz", 26); STRING_LITERAL(TMP129, "abcdefghijklmnopqrstuvwxyz", 26);
~~~ ```
The limitation with this is that procedures which are evaluated at compile-time cannot interface with C because there is no compile-time foreign function interface at this time. The limitation with this is that procedures which are evaluated at compile-time cannot interface with C because there is no compile-time foreign function interface at this time.

View file

@ -2,19 +2,19 @@
The `result` variable is a special variable that serves as an implicit return variable. This is useful because in most cases, the control flow semantics of the `return` statement are unneeded. `result` is initialized with the default value for a given return type, so the following code starts as `0`, before being initialized to `number`: The `result` variable is a special variable that serves as an implicit return variable. This is useful because in most cases, the control flow semantics of the `return` statement are unneeded. `result` is initialized with the default value for a given return type, so the following code starts as `0`, before being initialized to `number`:
~~~ nimrod ``` nimrod
proc `**`(number, power: int): int = proc `**`(number, power: int): int =
result = number result = number
for i in 1..power: for i in 1..power:
result *= number result *= number
~~~ ```
A possible gotcha is declaring a variable called result and expecting it to have the same semantics. A possible gotcha is declaring a variable called result and expecting it to have the same semantics.
~~~ nimrod ``` nimrod
proc unexpected(): int = proc unexpected(): int =
var result = 5 var result = 5
result += 5 result += 5
echo unexpected() # Prints 0, not 10 echo unexpected() # Prints 0, not 10
~~~ ```

View file

@ -3,7 +3,8 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>A Brand New nanoc Site - <%= @item[:title] %></title> <title>A Brand New nanoc Site - <%= @item[:title] %></title>
<link rel="stylesheet" href="<%= @items['/stylesheet/'].path %>"> <link rel="stylesheet" href="<%= @items['/stylesheets/main/'].path %>">
<link rel="stylesheet" href="<%= @items['/stylesheets/syntax/'].path %>">
<!-- you don't need to keep this, but it's cool for stats! --> <!-- you don't need to keep this, but it's cool for stats! -->
<meta name="generator" content="nanoc <%= Nanoc::VERSION %>"> <meta name="generator" content="nanoc <%= Nanoc::VERSION %>">

View file

@ -1,2 +1,12 @@
# All files in the 'lib' directory will be loaded # All files in the 'lib' directory will be loaded
# before nanoc starts compiling. # before nanoc starts compiling.
class CodeClassSimplfier < Nanoc::Filter
identifier :code_class_simplfier
type :text
def run(content, params={})
return content.dup.gsub!(/"language-\w+?"/, "codehilite")
end
end