import macros
type
S = string
I = int
O = object
i: int
P = ref O
var i: I
var s: S
var p: P
var o: O
macro mconnect(arg: typed): typed =
let at = getType(arg)
echo $(at.toStrLit)
if at.len > 1:
More precisely: for exported entities. Meaning:
# foo.nim
const sth* = 5
const oth = 4
# bar.nim
from foo import sth
export sth
bar.nim docs should include sth but not oth. Also, it should be explicitly
marked as exported in the docs unless foo.nim is
Overloading has one major disadvantage:
proc hasTwoIntArgs(x = 3, y = 4) = ...
hasTwoIntArgs(x = -1) # args: x = -1, y = 4
hasTwoIntArgs(y = -1) # args: x = 3, y = -1
proc hasTwoIntArgsInvalid(x, y) = ...
proc hasTwoIntArgsInvalid(x) =
It seems to me it would be better to not allow a getter/setter to be named just
like a private field. It's quite misleading.
Wow! I'm really lucky as far as finding bizzare language subtelties or compiler
bugs but... I've actually encountered this behaviour before. I guess I just
assumed you can use constructor syntax with any type.
@rayman22201 array is pretty much std::array and seq is pretty much
std::vector. I
> That is precisely what's happening
Excellent!
I'll carry on with Nimble, then
> and it looks like that Nimble is slowly obsoleting Nake by incorporating most
> (all?) of Nake's features
That is precisely what's happening
You should be able to use Nimble for most use cases nowadays.
Thank you for your help everyone.
@BigEpsilon:
I understand the difference seq vs array. An array is a fixed size from compile
time (a C array with the size information stored in the type system), and a seq
is closer to a std::vector in C++. My question is about setting the default
values of
Thanks, Andrea, for confirming my thinking.
To me, it makes a lot of sense to let a package manager handle builds, versions
and dependencies, and it looks like that Nimble is slowly obsoleting Nake by
incorporating most (all?) of Nake's features. At the very least it can explain
the overlap
Notice that nimble now supports tasks, which are custom command, scriptable
with nimscript. This should be extensible enough to cover your needs.
Nake is a build tool - I have never used it, since I find that build tools need
to be coupled to a package manager to be useful - there is no way to
> will compile not only your_program.nim, but also all imported modules
> recursively and build the final complete executable, so most of time you need
> just the compiler to build your project.
That is true, and also how I started out - mainly due to the fact that the Nim
tutorial does not
Yeah, I guess I assumed a blog was stories rather than news announcements.
Other (younger) people probably would not have made that assumption.
Thanks again @Lando for confirming this. It more clear to me now. Best Regards
That's obviously supposed to work and it's a bug when using methods in
combination with generics. Without generics it works fine:
type
Console* = ref object of RootObj
ViewportConsole* = ref object of Console
method draw*(self: Console, engine: string) =
Probably an [object
variant](https://nim-lang.org/docs/manual.html#types-object-variants). Or maybe
wait until concepts are implemented.
That's because of the sequence. If you would store the objects in two separate
sequences for _Console_ and _ViewportConsole_ instead, you would get the
expected result. Apparently, _var consoles: seq[Console]_ sets the runtime type
of the elements to **exactly** _Console_.
Correct. This is why the name of the field was changed to something other than
_host_ in the updated example code.
I think you should use `object`, it is the equivalent of `struct` from C.
type
Vec2i = object
x,y: int
Vec2f = object
x,y: float
NVGglyphPosition = int32
GlyphArray* = array[100, NVGglyphPosition]
TextBuffer* = object
@Lando, Many thanks for your reply, much appreciated. I was really confused.
This is how I understand the concept from your reply. Please correct me if I am
wrong.
* if ' s.host = 34 ' is called from the _same module_, it will directly
access the object variable bypassing the 's.host='
> You access them from the blog:
> [https://nim-lang.org/blog.html](https://nim-lang.org/blog.html). Why isn't
> this obvious?
Because it should be named "news" instead?
The example from the tutorial is a bit misleading, try the updated [version
from the language
manual](https://nim-lang.org/docs/manual.html#procedures-properties) instead.
The _host_ field of a _Socket_ object is invisible to code from a different
module, but the tutorial example code accesses
> my needs are simple
Consider first in Nim running just `nim c your_program` will compile not only
_your_program.nim_, but also all imported modules recursively and build the
final complete executable, so most of time you need just the compiler to build
your project.
Aplologies, there was an error in my program, corrected now. My question still
stands though. Thanks.
The reason I am confused is because if nimble is able to handle builds (nimble
build) I would rather not have to deal with nake, if I can help it.
Nake is probably more fully featured, but my needs are simple.
Since I am totally new to Nim, I thought I'd ask you guys for advice.
Are you using
In addition to what _BigEpsilon_ says, if you want to instantiate it that way,
you may use a template for not creating an additional variable explicitly each
time and to fit all in one initialization:
template ofType(typ: typedesc): auto =
var x: typ
x
# usage
I am a bit confused about the difference between nake and nimble when it
applies to project management.
Coming from Rust, where I am used to use Cargo to manage my projects/builds.
I am currently using 'nimble init' to kick off a new Nim project, but I am
aware of nake, which is a build tool.
You don't need to instentiate an array because it is already instentiated. Try
this
Var x :TextBuffer
echo repr (x.glyphPositions)
Which should print 100 element with the default value of NVGglyphPosition, and
that because array[100, X] is a fixed size array, wich means
I am a Nim n00b, and one of the hardest things I am having trouble with is
dealing with arrays in Nim.
I have the following typedef
type GlyphArray* = array[100, NVGglyphPosition]
type
TextBuffer* = tuple
position: tuple[ x : float, y : float ]
@dom96 I am fairly sure that I submitted a pull request (that got accepted) not
that long age that fixed the doc comments.
Hello all,
A newbie here. I have been learning Nim using the online tutorials and is
thoroughly enjoying Nim . I have completed the part 1 and have advanced to Part
2 of the tutorial. Have a question regarding the setter methods discussed in
the 'Properties' section of the tutorial. Can you
30 matches
Mail list logo