Unluckily, I can't replace Python with Nim as I need some science libraries not
yet available in Nim (maybe I'll port them another day...). While my friend
uses Nim for similar things, I chose Rust for my thesis and I had some good
reasons:
* when I started it, Nim lacked advanced generics it
Is there a way to make nim compiler to evaluate constants from C-header files
at compile time?
For example, symbols S_IFREG and S_IFDIR (from posix.nim <\- sys/stat.h) used
in following code snippet:
case x:
of S_IFREG: echo "file"
of S_IFDIR: echo "dir"
else:
> I've been away from Nim for about 9 months. Can anyone give me a quick update
> ...
We keep [accelerating toward
C](https://www.quora.com/Which-language-has-the-brightest-future-in-replacement-of-C-between-D-Go-and-Rust-And-Why),
but v1.0 [remains elusive](https://en.wikipedia.org/wiki/Time_d
As far as I know, the most advanced Nim development environment so far is
[VSCode](https://en.wikipedia.org/wiki/Visual_Studio_Code) \+
[this](https://github.com/pragmagic/vscode-nim)
[extension](https://marketplace.visualstudio.com/items?itemName=kosz78.nim).
Someone please correct me if I'm w
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:
ec
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 p
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) = hasTwoIntArgsInvali
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 t
Not quite. The type of a variable in your code is indeed Console but the type
of b is ViewportConsole. It's a subtle difference: in the seq exemple it's a
variable of a type Console which stores a value of ViewportConsole. The
difference is:
# in seq example:
consoles[0] of Co
@dom96 I am quite sure that when I was writing some macros in Nim some time
ago, it was clearly stated somewhere that doc-comments cannot be read from (or
created as) AST.
> 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.
@def: still seems that the sequence plays a role in a way I don't quite
understand here, because this works as intended:
type
Console* = ref object of RootObj
ViewportConsole* = ref object of Console
method draw*[T](self: Console, engine: T) {.base.} =
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 t
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 bet
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 b
> 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 men
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.
Is there a way to get my expected behavior while keeping all the Consoles in a
single sequence?
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
posit
@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=' method
> 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
Nimble can handle your build as well; I think you can safely ignore Nake
> 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
va
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 t
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 ]
cur
@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 ple
39 matches
Mail list logo