Both dont work haha. The system / mingw compiler looks for ...gcc.exeinstead of
the location of gcc.exe so it wont find the necessary file. Idk how to fix it
because the Path variable is correct
I use
[https://github.com/FedericoCeratto/nim_project_maker](https://github.com/FedericoCeratto/nim_project_maker)
to initialize projects with some useful files
Just to be sure, are you using the command `Nim` (uppercase N) or `nim`
(lowercase n)? The command is `nim` (lowercase n).
And there is my next problem. If i try to run anything with Nim c -r
filename.nim it gives a file not found error. even if i use f6 in VS Code
Thank you for the links it was hard for me to find anything
Thank you, I'll look into it
This is project structure I use:
[https://github.com/treeform/nimtemplate](https://github.com/treeform/nimtemplate)
. :-) The example files also have
imports so you see how a file references others.
Have you tried reading some tutorials?
[https://nim-lang.org/learn.html](https://nim-lang.org/learn.html)
There are also videos at youtube.
Generally in Nim we do not but all objects in its own source file as it is
common in Java. So generally You just create one single text file for your
like class files in java)? And if you do so how do you reference other
files/classes/whatever? Is there something like packages? How is it all
structured? Do I have to use CMD/BASH to set it all up?
Thanks in advance :)
Thanks @Araq!
Something like:
proc newAudioContext*(): AudioContext {.importjs: "new (window.AudioContext
|| window.webkitAudioContext)()".}
Run
I'm trying to fix the webaudio package to work with Safari as it exposes
`webkitAudioContext` instead of `AudioContext`.
proc newAudioContext*(): AudioContext {.importjs: "new AudioContext()".}
Run
In Javascript you'd generally do something like:
var
And finally this may look more like what you may desire:
import gintro/[gtk, gobject, gio]
type
Header = ref object of Headerbar
text: string
MainWindow = ref object of gtk.ApplicationWindow
header: Header
pb: ProgressBar
And to give you a starting point, the basic shape of your above program would
look like this:
import gintro/[gtk, gobject, gio]
type
Header = ref object of Headerbar
text: string
MainWindow = ref object of gtk.ApplicationWindow
header:
OK, when it is gintro related then your initial post is really not that smart.
Inheritance for C libs in different from inheritance in Nim . C is not an OOP
language.
I would strongly suggest YOU not using gintro!
I have recently listed most of the Nim GUI packages here, located directly
I don't think it's gintro specific. I have never used inheritance in Nim before
so I just need to get started with the basics.
import gintro/[gtk, gobject, gio]
type
Header = ref object of RootObj
base: HeaderBar
text: string
# Header = ref
I hope it is not related to gintro?
Hi, I want to create a derived type and call methods of the based type. How
does one achieve this? I was trying to just call the method on the result type
as follows:
type
Header = ref object of HeaderBar
text: string
proc newHeader(): Header =
new
Just load `libmsg.so` and get the address of the symbols that you need.
If `libmsg.so` depends on `libnet.so` then the OS loader (`ld`) should load
automatically `libnet.so` if `libmsg.so` is implicitly linked with `libnet.so`
(you can check the `.dynamic` section of `libmsg.so` with `readelf`
As far as I understand dylib this specifies in which shared library the
function is located. What happenes when you just choose the correct library?
libmsg.so depends on libnet.so. I want to load two libraries at the same time,
but this will cause errors.
dynlib only allows one library.
proc create_message*(version: cint) {.cdecl, importc, dynlib: "libnet.so
libmsg.so".}
Run
I've filed [an issue](https://github.com/nim-lang/Nim/issues/14810) to request
adding toString(openarray) to the standard library.
Interesting … I'm wondering where the 0 byte at the end of the cstring came
from, since `cast` doesn't copy anything. You might just have gotten lucky in
that particular example, and the memory after `bytes` happened to start with a
zero.
Here's a modification that fails, because the byte past
Not sure if this is helpful, but casting to cstring apparently works as
expected:
proc toString(bytes: openarray[byte]): cstring =
let str = cast[cstring](bytes)
echo "length = ", str.len
echo "str[0] = ", str[0].byte
assert str.len == 3
return str
cast is equivalent to reinterpret_cast in C++, it just reinterprets the raw bit
pattern (except for numerical types were it does zero-extension or truncation
like C casts)
Openarray are "ptr+len", I did misread your parameters and thought it was
seq[byte] when I wrote that part of my answer.
> @oswjk solution is correct.
It would be nice to have this in the standard library, so that one doesn't have
to unleash `unsafeAddr` just to do a simple conversion.
> openarray[byte] are not nul-terminated unlike strings and that would cause
> issues if you are interfacing with C code that
Author is here. Yeah, you can just fetch library sources from GitHub and use
them directly.
> where the bytes are UTF-8, of course.
This isn't relevant -- Nim is agnostic about the content of strings and doesn't
require them to contain UTF-8 or any other encoding.
@oswjk solution is correct.
`openarray[byte]` are not nul-terminated unlike strings and that would cause
issues if you are interfacing with C code that expect nul-terminated cstring.
I.e. you were probably victim of the same bug as
One way would be
proc toString(bytes: openarray[byte]): string =
result = newString(bytes.len)
copyMem(result[0].addr, bytes[0].unsafeAddr, bytes.len)
Run
There's no documentation I can find about how to convert an array of bytes to a
string (where the bytes are UTF-8, of course.) I've looked through the manual,
tutorial and several library modules.
So far I've been using `cast[string](...)`. This appears to work fine for
`seq[byte]`; at least I
time after
the main program is launched. The library itself is compiled with
\--debugger:native --passL:-s --passL:-static-libgcc. I've expected that
attaching gdb to the process should be enough to set breakpoints but thats not
the case.
So how to debug a library coded in nim?
My try
You could have a look at the WinAPI clipboard implementation of NiGui:
[https://github.com/trustable-code/NiGui/blob/master/src/nigui/private/windows/platform_impl.nim#L421](https://github.com/trustable-code/NiGui/blob/master/src/nigui/private/windows/platform_impl.nim#L421)
> Report it to the antivirus people, Nimble is not a virus :)
Why don't you whitelist it?
Thanks for the reply. Since, my antivirus is catching nimble, i am not able to
use it. And i send a message to the author of that library that i would like to
know how to use it without nimble,. :)
https://forum.nim-lang.org/t/4820#30170
Works perfectly! Thanks a lot!
Would something like this work for you?
proc a(x: int): int = x+1
proc b(x: int): int = x+2
var container: proc(x:int):int
if 4 > 5:
container = a
else:
container = b
echo $container(3)
Run
How would one declare a variable that is to contain a procedure later on?
E.g.: instead of testing a condition over and over again in each run of a proc
and branching depending on the condition, I'd create two functions, one for
each of the possible values, check the condition once (which
Hi all, I am using windows machine. I would like to know how to set and get
text in clipboard. I hope i don't need to use any libraries. Thanks in advance.
@juancarlospaco thanks, I read links you provide before. Maybe I'm skipped, but
there were no explanations of such catch.
@Yardanico oh, thanks a lot. I think that is it!
*
[imports](https://github.com/nim-lang/Nim/wiki/Nim-for-Python-Programmers#Imports)
*
[Objects](https://github.com/nim-lang/Nim/wiki/Nim-for-Python-Programmers#Objects)
* [I recommend read it
completely](https://github.com/nim-lang/Nim/wiki/Nim-for-Python-Programmers#table-of-contents)
Your example can be fixed by doing
export ex.uuid
Run
Or, if you want to export _everything_ from that module (export only exports
things which are marked by `*`:
import ex
export ex
Run
See
my smartness :)
My questions are:
* What is a nim way to write such code? (I'm thinking about `include`, but
not sure, this is the true way.)
* In other words, how should I notify users of my code, that they have to
import additional modules?
* How to explain this approach/behavior to Python
I have no experience in this, but if nobody else answered yet, I have some
supplemental questions for you, that I am thinking maybe can potentially at
least make it easier for someone to find the proper solution eventually:
* could I kindly ask you to run something like `nm libmecab.dll |
I would like to use the Japanese morpheme analyzer "MeCab"(
[https://github.com/taku910/mecab](https://github.com/taku910/mecab) ) in the
Nim language.
Since I use Windows 10, I thought about how to load the DLL in the Nim language
and use the functions defined in the DLL.
However
Kinda pseudocode, fragments scavenged from one of my projects:
import locks
var
lock: Lock
myflag: bool
lock.initLock()
proc foobar() =
echo "before lock"
lock.withLock:
if myflag:
echo "...do something with
, and it refers to a UI object. Whenever
the method `update()` is called, it makes some changes to the UI. How should I
approach this? I was unable to find any examples of Mutexes in Nim. I don't
know how and where to start.
Something similar in D:
class Listener
Note that an Option[ref T] is just a thin wrapper that checks if the reference
is nil:
[https://nim-lang.org/docs/options.html#Option](https://nim-lang.org/docs/options.html#Option).
Wrapping something that is a pointer in an Option is simply a way to get
Option semantics for pointers.
Or with Option:
proc searchTree*[T](leaf: Tree[T], searchFor: T): Option[Tree[T]] =
result =
if leaf.isNil(): none Tree[T]
elif leaf.item == searchFor: some leaf
elif searchFor < leaf.item:
some searchTree(leaf.left, searchFor)
else:
Well, first of all - you can't check `leaf.isNone()` beacause `leaf` is not an
Option type. You can however check `leaf.isNil()`.
And really in your example you don't need `Option` at all - you can just use
`nil`, but if you still want Option type, then something like `return
`proc searchTree*[T](leaf: Tree[T], searchFor: T): Tree[T] = result = if
leaf.isNil(): nil elif leaf.item == searchFor: leaf elif searchFor < leaf.item:
# are you sure you don't want leaf.left here? searchTree(leaf, searchFor) else:
searchTree(leaf.right, searchFor) `
Run
Hello, I know in a function returning a ref type, I need to construct the
result first: `new(result)`
However what if the result is an Option type? I need to construct what's inside
before wrapping it inside an option. How can I do this?
Example code:
type
Tree*[T] = ref
` git checkout devel # your version of devel git reset --hard nim-lang/devel #
reset to nim-lang/devel git push --force # push to github `
Run
To your specific question, the exact commands to get my repository back exactly
to devel
git reset --hard devel
git clean -f
Run
but I think what you actually need is to resolve merge conflicts... which is
just edit the files and then `git add ` and then `git
deleted and restarted my repository
still curious what commands would have done that for me without starting from
scratch
well now my repository is even more of a mess
somehow I managed to merge some of araqs commits into my own branch and it's
claiming I co-authored them
[https://github.com/solo989/Nim](https://github.com/solo989/Nim)/
if anyone could give me the commands to get my repository back exactly to
This is what I get when type git remote -v
origin [https://github.com/solo989/Nim.git](https://github.com/solo989/Nim.git)
(fetch)
origin [https://github.com/solo989/Nim.git](https://github.com/solo989/Nim.git)
(push)
upstream
Ok I managed to update my branch to be inline with devel.
But now it says I'm 13 commits ahead.
And whenever I try to make a pull request it includes all those commits in the
pull request.
I also recommend including the branch name in your shell prompt. For bash, I
have in my `.bashrc`:
PS1='\u@\h:\w$(__git_ps1 " [%s]")\$ '
Run
Depending on your distribution, you may need to install a package or source
some shell script to the `__git_ps1` command. For
I assume the pull got you stuck in a merge because of a merge conflict. The
output of `git status` should say something about this. If it's confirmed by
`git status`, you can either try to resolve the merge conflict by editing the
file, `git add` it and use `git merge --continue`, or you can
this is the exact error message when I try git checkout devel
error: you need to resolve your current index first
lib/pure/pegs.nim: needs merge
this is one of my commits that has now been been overridden in devel how do I
resolve/remove it?
so the cmds are
git clone [https://github.com/nim-lang/Nim](https://github.com/nim-lang/Nim)/
git checkout devel
git fetch upstream devel
git pull upstream devel
git push
git remote -v lists sources that are connected to my local copy
but how do I connect them in the first place?
and how
My workflow is:
I keep 2 sources, visible with git remote -v
origin https://github.com/mratsim/Nim (fetch)
origin https://github.com/mratsim/Nim (push)
upstreamhttps://github.com/nim-lang/Nim (fetch)
upstreamhttps://github.com/nim-lang/Nim (push)
but I have
no idea how to do that.
Not sure if I understand correctly. You want to put your commits on top of
latest commits from nim repo? The following should work.
git remote add nim https://github.com/nim-lang/Nim
git pull --rebase nim master
Run
I would like to make some more pull requests but I can't figure out to revert
my local fork back to devel. I've tried the command: git pull --rebase
--autostash as well as other commands. But it always claims it is up to date.
How do I get my repository to rebase based on
[https://github.com
I have tried it, in many ways, with no luck :(
Thanks for trying.
++
`try` / `except` or `try`/`finally`
[https://nim-lang.org/docs/tut2.html#exceptions-try-statement](https://nim-lang.org/docs/tut2.html#exceptions-try-statement)
from strutils import parseInt
# read the first two lines of a text file that should contain numbers
# and
Hello,
I am trying to build a list of mirrors and append the date when the mirror has
been refreshed. (For doing that I take the last-modified header of a file)
The program built without errors. The program begin to parse and print but, it
ends if it meet an error during the parse.
Is there a
How about more "reactive" observers ?
[https://gist.github.com/PixeyeHQ/fbec35b25b667b847b4eac413a8539a5](https://gist.github.com/PixeyeHQ/fbec35b25b667b847b4eac413a8539a5)
The idea is to subscribe for variable change. The proc you register will
trigger every time this variab
I can do this but it's not convenient to have all the subscribers be of the
same class
I think you could also do it in OOP style by defining a Subscriber object with
a ‘changed’ method, then having the real subscribers subclass that and override
the method. (Requires ‘pragma multimethods’, I think? I have to admit I haven’t
tried any real OOP in Nim yet! I’d try it out in a
Speaking from my user experience with nim (~1 yr), you don't have to worry
about the stability of async related things, they are quite robust.
The things that is not very mature is the GC. I am not talking about the arc
one, but the current default one refc. I have a single threaded project
> Not really. What you can achieve is something similar to what I created with
> httpbeast: each thread running its own Async event loop and allowing the
> system to load balance the socket connections. For clients that will likely
> be trickier.
This _event-loop per thread_ is only required
I didn't use ARC because when I started evaluating multithreading options (July
2019) and implementing Weave (November 2019) it was not ready at all.
Now at the moment, I'm ready to run my batteries of tests on arc:
> Read mratsim's post from the same thread then,
> [https://forum.nim-lang.org/t/6352#39200](https://forum.nim-lang.org/t/6352#39200)
@mratsim shows no examples of what ARC can do, but I assume that ARC can help
with the third scenario that he describes...
> You need a shared state, for
Adding to that
[https://github.com/nim-lang/Nim/issues/14429](https://github.com/nim-lang/Nim/issues/14429)
:)
> I may very well be missing something, ...
Read mratsim's post from the same thread then,
[https://forum.nim-lang.org/t/6352#39200](https://forum.nim-lang.org/t/6352#39200)
> I have limited experience with nim mobile apps. But knowing what I know don't
> think I would use async on the client. Async is great if you are doing tons
> of http style requests. But really a mobile client? Just regular threads are
> probably better if you are just writing and reading from
gt; The asyncnet module documentation has a couple of caveats about Windows, like
> "on Windows it only supports select()" and "In theory you should be able to
> work with any of these layers interchangeably (as long as you only care about
> non-Windows platforms).&
Thank you! Works great:
import tables
type EventEmitter = ref object
eventsMap: Table[string, seq[proc(event: string)]]
proc subscribe(emitter: EventEmitter, event: string, callback: proc(event:
string)) =
if not emitter.eventsMap.hasKey(event):
I've tried to summarize the state of Nim's concurrency and parallelism in this
blog post:
[https://onlinetechinfo.com/concurrency-and-parallelism-in-nim/](https://onlinetechinfo.com/concurrency-and-parallelism-in-nim/).
Some of it was based on this discussion.
This should be enough, you can capture whatever type you want inside a closure.
type
Publisher = ref object
subs: seq[proc(data: int)]
Run
The publisher has to maintain the list of subscribers.
It's easy to implement if all the subscribers are of the same type (or of the
multiple pre-defined types).
But is it possible to do not specify all possible types of subscribers?
You can implement atomic refcounting with destructors. See what I do in my
[multithreading
runtime](https://github.com/mratsim/weave/blob/33a446ca4ac6294e664d26693702e3eb1d9af326/weave/cross_thread_com/flow_events.nim#L176-L201):
type
FlowEvent* = object
e: EventPtr
supports
shared memory, but I couldn't figure it how. If Nim doesn't have this now, are
there future plans that will improve this situation? Will there be a garbage
collection algorithm that allocates all ref T on a shared heep, supports
passing them between threads, and frees the memory when
Regarding multithreading it really depends on your workload but here are 2
kinds of code architectures that would allow mixing async on threads:
1\. If the part of your code that you want threaded is stateless and only
allows the following types to crossover threads:
* plain old
> which GC is the default
The _\--gc:refc_ (deferred reference counting/heap per thread) is the default
right now. The _\--gc:arc_ (immediate reference counting/shared heap) or
_\--gc:orc_ (immediate reference counting/shared heap + cycle detector) is set
to replace it.
The _async_ stuff
> how does your C++ architecture share data between threads?
Carefully ;-) The Actor library doesn't restrict what parameters you can pass,
but by convention we're careful to limit it to primitives, pass-by-copy objects
(like std::string), immutable ref-counted objects, and Actor referen
ouple of years, so the "actor" model and copying messages between them
makes sense to me. Out of curiosity, how does your C++ architecture share data
between threads?
probably better if you are just writing and reading
> from a single websocket connection.
Async and threads are orthogonal, not opposite choices. What interests me about
async/await is how it cleans up the control flow in source code, avoiding
"callback hell".
Again, I'm considering po
> Could you explain why not?
Current current gc:refc does not allow refs object to be passed between threads
willy nilly. Async creates a reactor ref object per thread. So you can't really
share the async corutines between threads. Threads are just kind of hard to use
with gc:refc, that is why
Are you using Jester or another web framework?
> You can use closures or pass the data parameter as an input to the function.
In some sense closures and objects are isomorphic, as are functional and OOP.
There’s a famous old _koan_ about this:
> The venerable master Qc Na was walking with his student, Anton. Hoping to
> prompt the master
> it requires an introduction that explains to users what ARC is, how to make
> use of it
+1 The existing documentation is **great** (I’ve read the tutorial, manual,
and “Nim In Action” cover to cover), but in some areas seems to lag behind.
Which is understandable since the la
> Async does not mesh well with threds.
Could you explain why not? My understanding is that it’s thread-agnostic; an
unfinished async call is just a sort of lightweight continuation that can be
restarted in any context.
> Multiprocessing is more scalable anyways.
This project is a library for
> for new projects I wouldn't use anything else because the tooling is so much
> better
That would be great, but it requires an introduction that explains to users
what ARC is, how to make use of it, how it impacts multithreading, the new sync
and lent parameters, how to design colle
1 - 100 of 2120 matches
Mail list logo