Fix out of date code

This commit is contained in:
Flaviu Tamas 2015-01-22 16:20:02 -05:00
commit fbb973b80a
3 changed files with 22 additions and 23 deletions

View file

@ -9,7 +9,7 @@ Object oriented programming is supported through inheritance and methods, which
Inheritance is created with the `of` keyword in the type declaration of an object. A method is overridden by creating a new method with parameter types of the subtype.
``` nimrod
type Animal = ref object of TObject
type Animal = ref object of RootObj
name: string
age: int
method vocalize(this: Animal): string = "..."

View file

@ -7,7 +7,7 @@ title: OOP Macro
This is the code that we currently must write to use OOP in Nim:
```nimrod
type Animal = ref object of TObject
type Animal = ref object of RootObj
name: string
age: int
method vocalize(this: Animal): string = "..."
@ -24,7 +24,7 @@ method vocalize(this: Cat): string = "meow"
All these typedefs and `this: T` parameters are repetitive, so it'd be good to write a macro to mask them. Something like this would be best:
```nimrod
class Animal of TObject:
class Animal of RootObj:
var name: string
var age: int
method vocalize: string = "..."
@ -63,7 +63,7 @@ macro class*(head: expr, body: stmt): stmt {.immediate.} =
# Infix
# Ident !"of"
# Ident !"Animal"
# Ident !"TObject"
# Ident !"RootObj"
typeName = head[1]
baseName = head[2]
@ -175,7 +175,7 @@ macro class*(head: expr, body: stmt): stmt {.immediate.} =
# ObjectTy
# Empty
# OfInherit
# Ident !"TObject"
# Ident !"RootObj"
# Empty <= We want to replace this
# MethodDef
# ...
@ -186,7 +186,7 @@ macro class*(head: expr, body: stmt): stmt {.immediate.} =
# echo repr(result)
# Output:
# type
# Animal = ref object of TObject
# Animal = ref object of RootObj
# name: string
# age: int
#
@ -198,7 +198,7 @@ macro class*(head: expr, body: stmt): stmt {.immediate.} =
# ---
class Animal of TObject:
class Animal of RootObj:
var name: string
var age: int
method vocalize: string = "..."

View file

@ -1,27 +1,27 @@
489fd1e2356eb85f81bac48e45b186a7
da4974745059fff2c0c3d0af688042ab
ef380e36bcc0ebf11902cefaa10ec31b
98f917ee2165bc9461c3e9316e8e70ee
b243592b06e93bb3cf1f7d62a25abaa3
1f6e436b0fbdc68e1776422df711c2bb
394ca46d1bf22dedef7e6e753bd033c8
8afe80a509d316a3feb3caa1c985760a
9551565b83418876b5211869acbcf7cc
ade4a4b3b6973bbb44f2e74aee1954f7
ef380e36bcc0ebf11902cefaa10ec31b
26ded9e69879069fb8970403e87a24c9
b243592b06e93bb3cf1f7d62a25abaa3
3f3dfdee017d0c329d594e9fe038ed9f
cf09b588bb8b3c6979d24dcaff932c68
448a6cb31706860e7957f8dcca732d85
4bb57235ab6f4f0dd1eea58a769570c5
394ca46d1bf22dedef7e6e753bd033c8
8afe80a509d316a3feb3caa1c985760a
0bdba4c56b6172c86726f424b4186baf
9551565b83418876b5211869acbcf7cc
ac4fe7f722b390100501e638ce8a9750
eb67590e2472e05b207856959e5461c8
f770b25468d042a02822e90df0848f35
10ae94a28a0d8f23aff5afaa0367cf27
1865b827bef365e6422beb6bc076a25d
398863bccd3691b42500dfa143a3230b
cdf52a33222c8402025606b0bb4da4d9
b8875a112bc13ea83556bcf385c1160b
bee0509ab4bcf36510a85081d563057b
30111c31170d8cd9979ae7d88fa276e7
0e641a70cbd7b3e955bb29bde934f36e
ad9e1e896361b0313c3ba66f793f4e6b
d599ef057eaaac83139eb8f949cef356
e0e0e0b5724e296371d1704996096343
2d60def87d4fa95e26b9f8eade4b0baa
@ -31,9 +31,8 @@ d01dfb20f1d8c1741eef320e82bfcdc2
fbb7977d27de5251fa736a627aaa8311
847d1c4525d9056206a1e4f4855a9e10
e4b29a303e0a22cab1f2bfb769ce66c5
e4fbe215e23d9a5c39312839c5fb1b41
bee0509ab4bcf36510a85081d563057b
ad9e1e896361b0313c3ba66f793f4e6b
f770b25468d042a02822e90df0848f35
4bb57235ab6f4f0dd1eea58a769570c5
0bdba4c56b6172c86726f424b4186baf
260d9667bbbc34ce79da5d60efecef02
24614b0b8792a9afc184e4d63e345981
217de4ce8743609c7592a3d75264b17d
36c0a24d4e54348f950ff421a33dcd38
0b0bdbed7863d3ec82d2d8cb628562ed