No description
Find a file
2020-09-16 10:13:19 -06:00
src/extensions Add objprint 2020-09-16 10:06:58 -06:00
tests Cleanup a bit 2018-06-21 18:43:28 +09:00
extensions.nimble Version bump 2020-09-16 10:11:03 -06:00
LICENSE Initial commit 2015-02-02 14:15:08 +13:00
README.md Cleanup readme spacing 2020-09-16 10:13:19 -06:00

nim-extensions

Extensions for the Nim programming language.

These extensions aim to improve the usability of Nim in practical applications.

Extensions so far include:

OOP macro

This module was modified from the OOP section on the excellent website http://nim-by-example.github.io/

Usage:

import extensions / oop

class BaseObject: # inherits from RootObj
  # attributes/properties
  var
    x: int
    y: float
    
  method override_me(argx: float): int =
    result = int(argx) + self.x
    
class ClassName of BaseObject:
    method method_name(arg1: int, arg2: float=0.3): float =
      ## do stuff here
      result = arg2
      
    method override_me(argx: float): int =
      result = int(self.y) + int(argx) + self.x

There's also an example in the code that demonstrates the inheritance that can be run by executing:

nim c -r tests/test1.nim

Enumerate

This macro is useful for enumerating on any iterator. It will autodetect which iterator you want to use and give you a useful enumeration.

Usage:

import os
import extensions / enumerate

for i, line in enumerate(lines, "file.txt"):
    echo i, " ", line

for i, tup in enumerate(walkDir, "."):
    echo i, " ", tup

Objprint

These printing procs are useful for printing objects and their types.

import extensions / objprint

type Unit = ref object
  name: string

echo Unit(name: "Ref")
echo Unit(name: "Non-ref")[]
echo (str: "value")

# Prints:
#  ref Unit(name: "Ref")
#  Unit(name: "Non-ref")
#  tuple[str: string](str: "value")