Dear all, Thanks for all the replies so far. Insightful discussion indeed. I
will retreat for a awhile to experiment with the code, and also to do the job
that pays my bills :-) Till very soon
That's a beautiful pattern! Although I don't yet understand the comments in the
snippet. I will try to figure it out by experimentation. Thanks a lot.
I'm honored to get the attention of the designer of Nim. You are right in your
assessment. Maybe because I saw that pattern in many languages. So what you are
saying is that the idiomatic way to support custom construction of an instance
of a type is something like
proc newTypeNam
Indeed, it is exactly that, an exploration exercise. I will have a look at that
link. Thank you.
Thanks for pointing out. Why doesn't it work just as?
var b = TypeName(1)
Run
Instead of
var b = toTypeName(1)
Run
It would be simpler. Moreover, integer get converted to floats and vice versa
just by this syntax.
var i = 12.4.int
Dear all, as promised I worked further on the topic of my question. I hope
these two examples will make my point clear. Just to summarize, the two code
examples implement currency types based on float and int respectively. The
float example works as expected and it provides a very nice coding st
Thanks for all the replies so far. It really helped me to reason about Nim.
However, at this point I'm even more convinced of the point I was trying to
make I will play a bit more with Nim to figure out how to best lay out my
thoughts in favor of a python like __init__
When I wrote constructors, what I actually had in mind was an initialization
proc like in the __init__ method in python. Thanks for pointing out the subtle
difference. That would suffice to tailor the initialization of member of
objects or, as it was the case in my example, the kind of alias to
Thanks. I agree
d = 176.toDollar
Run
reads better. I'm fine with that. But the issue remains: since the language
allows
d = 176.Dollar
Run
users of such module might be tempted to use it and get the unintended result.
But I get it, this is how t
Dear All,
Why there are no constructors in NIM?
The reason I ask is that I see several instances where it would be very useful.
Sure, one can resort to conventions like using a 'proc initTypename()' but that
doesn't seem to be as convenient as using a constructor (or specific method
like the _
10 matches
Mail list logo