If you want to make your design a reality, you can try to use constructor.

With that you can make your code work like this:
    
    
    import constructor/defaults
    
    type Foo {.defaults.} = object
       bar: proc( n: int) : int = proc(n: int): int = n+n
    
    implDefaults(Foo)
    
    
    var foo = initFoo()
    let x = 5
    echo foo.bar(x)
    
    
    Run

I wouldn't deem it _advisable_ to put procs in there because that smells like 
you want true-OO which IIRC isn't a favored paradigm in nim, as there's 
method-call-syntax instead.

Reply via email to