I'm new to the language. When trying to compile a new object type with a method (where the first argument is an instance of my new type), the compiler warned me like this:
Warning: use {.base.} for base methods; baseless methods are deprecated [UseBase]
Note: Starting from Nim 0.20, to use multi-methods one must explicitly pass --multimethods:on when compiling. In a multi-method all parameters that have an object type are used for the dispatching: type Thing = ref object of RootObj Unit = ref object of Thing x: int method collide(a, b: Thing) {.inline.} = quit "to override!"
An object can be defined in Nim with the type statement. An object in Nim is more like a simple struct than a real object - it's a structured grouping of variables, but doesn't have its own methods that act on it, and there are no built in constructors or destructors.
This document is a tutorial for the advanced constructs of the Nim programming language. Note that this document is somewhat obsolete as the manual contains many more examples of the advanced language features. Pragmas are Nim's method to give the compiler additional information/ commands without introducing a massive number of new keywords.
A procedural type is a (somewhat abstract) pointer to a procedure. nil is an allowed value for a variable of a procedural type. Nim uses procedural types to achieve functional programming techniques. proc greet(name: string): string = "Hello, " & name & "!"
Base methods correspond to what would be the base class for a method in a single-dispatch language. The base method is the most general application of a method to one or more classes. If you are dispatching on just a single argument, the base method should be associated with the type that would normally be the base class containing the method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With