so, i have a problem i've got from this code:
type item[T] = object
value: any
next: ptr any
>next is ptr any cause i dont wanna write smth like >next: ptr item[any]. i'm afraid of gettin error about auto in contexts. can i get an object with pointer on other with non-same type? like that
var i: item[int] #actually there is error: Error: invalid type: 'auto' in this context: 'item[system.int]'. AND YES I KNOW: VALUE: T and NEXT: ptr item[T]/T will work
var tmp: item[string]
i.value = 3
i.next = addr(tmp)
...
or its impossible in that way?
and the second problem is: how can i transfer a pointer on proc to other proc? example:
proc a(p: ptr proc) {.procvar.} =
...
a(addr(`<`))
i've got error >Expression has no address. (on other comp i've got msg that proc is not procvar, lol) help me resolve THOSE PROBLEMS PLEASE AAAAAA
actually, on
type item = object
value: any
next: ptr item
i get >'any' is not a concrete type. (i think its cause all types like >any are generics)Yes, 'any' is a generic (typeclass). Your object should probably be defined like this
type item[T] = object
value: T
next: ptr item[T]
Likewise '<' is an overloaded proc, so not a specific proc that you can pass to a function. Also, you don't need to specify 'ptr' for a proc when used as an argument, Nim will implicitly do the right thing for the corresponding backend. You can wrap overloaded functions in a specific one if you want to pass them
proc a(p: proc) =
var x,y: int
echo p(x,y)
proc lt(x,y: int): bool =
x < y
a(lt)
or you can use a template to generate separate functions for each proc you want passed in. This can then handle overload procs.
template makeproc(f,p: untyped): untyped =
proc f =
var x,y: int
echo p(x,y)
makeproc(b, `<`)
b()