Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a baseless method in Nim?

Tags:

oop

nim-lang

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]
like image 718
Antrikshy Avatar asked Mar 13 '17 01:03

Antrikshy


People also ask

How to use multi-methods in Nim?

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!"

How do you define an object in Nim?

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.

What is a nim pragma?

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.

What is a procedural type in Nim?

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 & "!"


1 Answers

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.

like image 110
Reimer Behrends Avatar answered Oct 03 '22 00:10

Reimer Behrends