@mratsim Thank you for your detailed and informative response, also I didn't
know about the do statement in Nim that's something else new for me. My main
takeaway is that I don't always have to use runtime resolution, especially
because the kind of code I write is mostly statistics/machine
> No you don't, you can have AbstractKernel be a procNo you don't, you can have
> AbstractKernel be a proc.
>
>
> type AbstractKernel[F] = proc(loc: var F) {.nimcall.}
>
>
> Run
I don't understand and have a couple of questions. Firstly, what would be the
syntax for
One of the things that intrigued me about Nim was it's object system, you could
create value, reference and pointer types with/without inheritance. As I
understand it, an important distinction between ptr and ref classes is that ref
classes are managed by the garbage collector while ptr classes
Isn't the point of inheritance method dispatch? Why isn't that a separate issue
from objects that are dissociated from the garbage collector?
I just wasn't sure whether when allocating for objects you have to account for
any "gubbings", just cautious I guess:
type
MyTypeA = ptr object of RootObj
x: int64
MyTypeB = ptr object of RootObj
x: array[0..4, int64]
var x0 =
One of the interesting things I remember about Nim is that you can have ptr
object rather than ref object, since ptr object is not garbage collected. How
do you create and destroy an ptr object? For example how do you correctly
instantiate and destroy the two types below?
type
I have noticed that multiple CPU's were not being used, each process is spawned
and seems to wait till it's finished before the next one starts so that only on
CPU is being used at once. Is there something I should check about my
implementation to make sure that I'm not doing something
Actually, I could just put the inner loop into its own function which should be
fine.
I am trying to parallelize kernel matrix calculations using threadpool:
proc calculateKernelMatrix*(K: AbstractKernel, data: Matrix[F]): Matrix[F] =
let n = int64(ncol(data));
var mat = Matrix[F](data: newSeq[F](n*n), dim: @[n, n]);
for j in 0..
Thanks, I don't know why I didn't think of that. I thought there would be a
builtin for transforming something to ref, but this is fine.
Sorry quick extension to that question, if I have a variable that is a seq[T],
how do I assign it to a new variable that is a ref seq[T] ... or otherwise how
do I transform a variable that is a seq[T] to a ref seq[T] ?
Many thanks, dereferencing ref s is done using x[] as in your answer.
How do you create a reference to a sequence? I can see how you create a pointer
to a sequence:
var x: seq[float64] = @[1.0, 2, 3, 4, 5];
var y = x.addr;
Run
But have no idea how to create ref seq[float64], or is it only possible to
create a ptr seq[float] while
> I don't think your code is standard though, usually void are implicit in the
> return type, also var are used for in-place mutation, not pointers.
Thanks for letting me know, I haven't written a lot of Nim so I'm still
learning. I didn't realise that using var means in-place mutation, I've
://gist.github.com/dataPulverizer/744fadf8924ae96135fc600ac86c7060](https://gist.github.com/dataPulverizer/744fadf8924ae96135fc600ac86c7060)
Thanks for the advice and the references.
How do I cast float64 to sequence of byte`s and cast sequence of `byte`s to
`float64? float64 is just an example it could be any basic type. I already did
it for an array, but don't know how to do it for a sequence.
Thanks
Ah, many apologies! I saw it in the manual and assumed that it worked in the
same thing as Julia.
I'll not make anymore assumptions and read more carefully.
Why is this not legal code?
proc printName(;firstName: string = "Jimmy", lastName: string = "Hendrix") =
echo "First Name:", firstName, ", Last Name: ", lastName
Run
The above code was just an example. In general I would like to be able to paste
code using templates or macros in a similar way that you can with D's string
mixins which allow you to generate strings using functions and then paste them
anywhere and generate code in compile time. In the above
> No, parser cannot understand `extraCode` in an object declaration, in the
> template, which is there an invalid syntax.
I would like to substitute `id: int` for extra code in the template by doing:
typeGen(Employee):
id: int
I thought (incorrectly) that this is how
@Udiknedormin many thanks for the thorough explanation and for your correction
of age from string - silly error on my part.
@stisa thanks for the heads up on dirty templates
I guess the way to generate types using templates is to insert code into a
template type structure rather than inserting
I'm trying to use templates to paste code:
template someCode(): untyped =
var
fname: string = "Mark"
age: int = "44"
someCode()
echo fname
The above code does not recognise the var declarations and the code below
doesn't run either
@LeuGim - thanks for the clarification
@mratsim I didn't know about SomeReal thanks for pointing that out.
> By the way, I don't really understand your need but you can usually go very
> far in Nim with just generics and overloading without to implement class-like
> types.
>
> If you need
This looks like a very useful library for me. I shall certainly be checking it
out. Nice one!
Many thanks! Looks like I didn't read the manual properly, I ended up thinking
that ref Parent was how inheritance works. Just for confirmation:
type
# This is equivalent to a struct
Object1 = object
# This is a reference type to the "struct" Object1
Object2
Brand new to Nim, trying out parametric type with hierarchy, got stung with an
indentation error for the last two lines that I can't figure out why
type
floatingPoint = float | float64 | float32
Parent1 = ref object
Parent2 = ref Parent1
Parent3 = ref Parent1
28 matches
Mail list logo