Partially do objects, remove gitbook

This commit is contained in:
flaviut 2014-05-30 14:06:39 -04:00
commit 64313ec3ce
6 changed files with 42 additions and 4 deletions

View file

@ -5,7 +5,8 @@
* [Numbers](numbers.md)
* [Variables](variables/page.md)
* [Result](variables/result.md)
* [Types](types.md)
* [Objects](objects.md)
* [Enums](enums.md)
* [If, Else, While, Block](if_else_while.md)
* [Case Statements](case.md)
* [For Loops & Iterators](for_iterators.md)

View file

@ -6,7 +6,7 @@
"plugins": [],
"links": {
"home": "http://nimrod-lang.org/",
"about": null,
"about": false,
"issues": null,
"contribute": null,
"sharing": {

1
src/enums.md Normal file
View file

@ -0,0 +1 @@
# Enums

38
src/objects.md Normal file
View file

@ -0,0 +1,38 @@
# Objects
In Nimrod, objects are like structs from C family languages and define a grouping of fields.
``` nimrod
type
Animal* = object
name*, genus*, species*: string
age: int # None of your business!
PAnimal* = ref Animal
proc sleep*(a: var Animal) =
a.age += 1
# create a new Animal, not allocated on the heap
var carl = Animal(name : "Carl",
genus : "Lama",
species : "glama",
age : 12)
# Allocate an Animal on the heap
# Note that the pointer is immutable, not the pointee
let mittens: ref Animal = new(Animal)
mittens.name = "Mittens"
mittens.genus = "Panthera"
mittens.species = "Leo"
mittens.age = 6
# This also goes on the heap since PAnimal is a
# reference type
let spot = PAnimal(name: "Spot",
genus: "Canis",
species: "Lupus",
age: 1)
# Same as before, only pointer value is unchangeable
spot.age = 2
```

View file

@ -212,7 +212,6 @@ class(Dog of Animal):
class(Cat of Animal) do:
method vocalize: string = "meow"
run_test()
echo "Tests passed!"
```

View file

@ -1 +0,0 @@
# Types