diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 6204a6f..321a0de 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -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) diff --git a/src/book.json b/src/book.json index 0c470cb..a89774f 100644 --- a/src/book.json +++ b/src/book.json @@ -6,7 +6,7 @@ "plugins": [], "links": { "home": "http://nimrod-lang.org/", - "about": null, + "about": false, "issues": null, "contribute": null, "sharing": { diff --git a/src/enums.md b/src/enums.md new file mode 100644 index 0000000..1cf9f00 --- /dev/null +++ b/src/enums.md @@ -0,0 +1 @@ +# Enums \ No newline at end of file diff --git a/src/objects.md b/src/objects.md new file mode 100644 index 0000000..4d93e83 --- /dev/null +++ b/src/objects.md @@ -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 +``` diff --git a/src/oop_macro.md b/src/oop_macro.md index cb0f24c..bc7b311 100644 --- a/src/oop_macro.md +++ b/src/oop_macro.md @@ -212,7 +212,6 @@ class(Dog of Animal): class(Cat of Animal) do: method vocalize: string = "meow" - run_test() echo "Tests passed!" ``` \ No newline at end of file diff --git a/src/types.md b/src/types.md deleted file mode 100644 index 3b30843..0000000 --- a/src/types.md +++ /dev/null @@ -1 +0,0 @@ -# Types \ No newline at end of file