Re: port psutil on mac host_statistics get nil result

2019-12-17 Thread luciferjohn
Seems like a pretty straightforward port, nothing looks wrong.

What's the error value that you're seeing from the host_statistics function? 
Can you

echo error [https://11.onl](https://11.onl)/ 
[https://1921681254.mx](https://1921681254.mx)/ 
[https://acc.onl/hotmail](https://acc.onl/hotmail)


Arrays and Sequences in nim

2019-12-17 Thread drkameleon
Ok, this is a rather newbit question but despite all my experiments I'm still 
confused.

Let's say we want an array of int s.

In Nim, I would do it either like this:


var myArray: array[200, int]


Run

or like this:


var myArray: seq[int] = newSeq[int](200)


Run

But what are the _real_ differences between the two options? I mean, obviously, 
the first one declares a fixed-size array, so if our goal is to have an array 
that grows and shrinks during runtime, I guess the only option would be to use 
a seq. But if we actually _do_ want to set an upper limit to our array?

Long story short, in the stack-based bytecode VM I'm currently experimenting on 
I find myself using more of the first type (that is: "simple" fixed-size 
arrays) What are the drawbacks (memory/safety/performance-wise)? What should I 
pay attention to?


Re: Walking trees without recursive iterators

2019-12-17 Thread e
[Here](https://github.com/dcurrie/nim-bbtree/blob/master/src/bbtree.nim#L419-L446)
 is how I did it for a balanced binary tree without parent pointers, using an 
explicit stack as others have mentioned.


Re: Walking trees without recursive iterators

2019-12-17 Thread rayman22201
In general: All recursion can be converted to iteration. That is a foundation 
of the Church-Turing thesis. Also, iterators are just abstractions around 
loops. Simply put the yield where the body of the loop would go.

@GordonBGood's algorithm is just embedded recursion using closure functions. It 
still builds a stack. (he mentions this in his post.) I believe you can modify 
that code from a binary tree to the general case fairly easily.

Tree Traversal abstractly requires a way to jump back to the parent node. 
@mratsim does this by bit shifting, a trick he can use because of the array 
representation.

For the representation you are using, one way to achieve this is to keep the 
reference to the parent. Either by building a stack, or by modifying the node 
object to keep an extra "parent" ref field. This obviously has some space cost. 
You have essentially embedded the stack into the tree itself.

See here for an example in C: 
[https://stackoverflow.com/a/8976310](https://stackoverflow.com/a/8976310)

Another option is something called "Morris Traversal": 
[https://www.geeksforgeeks.org/inorder-tree-traversal-without-recursion-and-without-stack](https://www.geeksforgeeks.org/inorder-tree-traversal-without-recursion-and-without-stack)/

Note that solution requires being able to modify the tree.


Re: nim android tutorial

2019-12-17 Thread treeform
Also see my: 
[https://forum.nim-lang.org/t/5197](https://forum.nim-lang.org/t/5197)

And manual: 
[https://nim-lang.org/docs/nimc.html#cross-compilation-for-android](https://nim-lang.org/docs/nimc.html#cross-compilation-for-android)


Advanced python book with cool science excersizes

2019-12-17 Thread mervinrasquinha
Hi there! I’m looking for a python book for my boyfriend this Christmas.

He is not a beginner - he’s been working with python for a couple of years. 
However, he’s in science so he uses it for physics/science problems. He wants a 
book that’ll teach him cool python tricks - how to be more efficient with his 
code, with cool mini projects that are science related that he can try out.

Does anyone have any Suggestions?


Re: How to store an int in a register?

2019-12-17 Thread drkameleon
Thanks a lot - I had spotted it, but not sure it was the right one for this! :)


Re: How to store an int in a register?

2019-12-17 Thread Araq
You can use `.codegenDecl` to do that.


Tadapox

2019-12-17 Thread denmoastov
The American Psychiatric Reference Manual (DSM-5) defines the disorder as Ь 
ejaculation triggered by minimal stimulation before, mention the duration of 
action if there is sexual stimulation. No effect is to delay the disorder. It 
should be noted that the active compo ent (tadalafil) is suitable for 05 hours 
after taking this Cialis equivalent. You can take his dose of Tadalafil without 
prescription severa hours before without having an erection in the presence of 
stimulation. If the approach of erotic excitement. In the composition of 
Tadapox, tadalafil allows you o resume sexual activity just after penetration, 
which occurs when the therapeutic fami is suitable for subjects who do not take 
place. The main difference between Tadapox?

[https://www.gulickhhc.com/drugs/erectile-dysfunction/tadapox.htm](https://www.gulickhhc.com/drugs/erectile-dysfunction/tadapox.htm)


Re: nim android tutorial

2019-12-17 Thread timothee
this might be of help too (adapting some ideas from D to nim): 
[adamdruppe/d_android: Helper programs and interfaces for using D on Android 
systems : adamdruppe/d_android: Helper programs and interfaces for using D on 
Android 
systems]([https://github.com/adamdruppe/d_android](https://github.com/adamdruppe/d_android))

D forum 
[https://forum.dlang.org/thread/cqdqhrporufpzkwjw...@forum.dlang.org](https://forum.dlang.org/thread/cqdqhrporufpzkwjw...@forum.dlang.org)
 My Android project nearing beta


Re: How to store an int in a register?

2019-12-17 Thread drkameleon
Basically, I want to use it in one of the very very few cases where that 
keyword would - supposedly - make some difference: to store the top of my VM's 
stack.


Re: assign an object variant kind for unsafe memory block

2019-12-17 Thread treeform
I don't see a crash here, just a normal error message:


: unhandled exception: assignment to discriminant changes object branch; 
compile with -d:nimOldCaseObjects for a transition period [FieldError]

Run

The way case objects are handled has changed. Now they can only be created with 
a specific case, they can't be set at runtime. You are trying to set it at run 
time.

I can't think of other ways around this rule other then "creating and copying 
the object" or "using -d:nimOldCaseObjects"... There probably is but it will be 
just as ugly.

Maybe you don't need case objects? Maybe you don't need alloc0 them? Are you 
using pointers because of threads? 


Re: assign an object variant kind for unsafe memory block

2019-12-17 Thread treeform
Auxiliary copy object does not fill too bad though:


type
  Kinds = enum
kA, kB, kC
  ExampleBlock = object
case kind: Kinds
of kA: a: int
of kB: b: string
of kC: c: uint16
otherFields: array[16, int]

when isMainModule:
  echo "Sizeof block, ", sizeof(ExampleBlock) # Is a union after all
  let kindcrash = cast[ptr ExampleBlock](
alloc0(sizeof(ExampleBlock))
  )
  var copyObj = ExampleBlock(kind:kb)
  copyObj.b = "String Test"
  kindcrash[] = copyObj
  
  echo kindcrash.kind
  echo kindcrash.b


Run


Re: Introducing Synthesis: a Finite State Machine generator

2019-12-17 Thread geotre
Thanks @mratsim, this is really useful.

> For now I don't plan to expand the library more as it is fairly complete for 
> my use case. The most interesting additions would be a graph backend and 
> maybe saving/loading state machine definitions from JSON.

What does graph backend mean in this case?


Re: libgpiod wrapper uploaded to github

2019-12-17 Thread treeform
Nice, I like it.


Re: How to store an int in a register?

2019-12-17 Thread treeform
I am pretty sure you could drop into C with {.emit.} pragma and specify it this 
way, but it will not make your code faster.

[https://stackoverflow.com/questions/578202/register-keyword-in-c](https://stackoverflow.com/questions/578202/register-keyword-in-c)

"It hasn't been relevant for at least 15 years as optimizers make better 
decisions about this than you can."

You can't take an address of a register, or maybe you can, it will just ignore 
it. It might cause errors. But it probably be mostly ignored. It's not clear...

If it did use the register it might make the code slower because then other 
things can't use the register when they need it more.

If you are compiling for x86 which uses "register renaming" is a technique that 
abstracts logical registers from physical registers. So you are not even doing 
what you think you are doing... 
[https://en.wikipedia.org/wiki/Register_renaming](https://en.wikipedia.org/wiki/Register_renaming)


How to store an int in a register?

2019-12-17 Thread drkameleon
Is there any way I can make Nim store a specific variable (uint64 to be 
precise) into a specific register, for super-fast access?

Something along these lines:


register int *foo asm ("r12");


Run


Re: Any way to force a specific identifier name in C code?

2019-12-17 Thread Stefan_Salewski
Are you looking for

[https://nim-lang.org/docs/manual.html#foreign-function-interface-exportc-pragma](https://nim-lang.org/docs/manual.html#foreign-function-interface-exportc-pragma)


Re: Any way to force a specific identifier name in C code?

2019-12-17 Thread SolitudeSF
https://nim-lang.github.io/Nim/manual.html#foreign-function-interface-exportc-pragma


Re: GDI-style lib for Nim.

2019-12-17 Thread Aiesha_Nazarothi
Yeah, sure, awesome for 2019.

So, I can set single pixel color with setPixel. Now how can I get it back ? 
Where is my getPixel method ?


Any way to force a specific identifier name in C code?

2019-12-17 Thread drkameleon
I know Nim creates unique identifiers for every identifier used, in the form of 
"MyIdentifier__BreJK2peWZ1PII7tA5raZg".

Is there any way I can force a specific "unique" identifier and not have it 
auto-generated?


Re: GDI-style lib for Nim.

2019-12-17 Thread Trustable
So far NiGui does not provide functions to draw multi line texts. If you want 
to do this, you can use
splitLines() and increase y for each line by getTextLineHeight() plus maybe 
some line spacing.

And thanks for reporting the [black shadow 
bug](https://github.com/trustable-code/NiGui/issues/83), it's now fixed.


libgpiod wrapper uploaded to github

2019-12-17 Thread nais314
I wrapped and nimified 
[libgpiod](https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/about/). 
Tested on Rpi2. I could not wrap the iterators, #define-d in C as macros... 
but, for me, it is not a big problem ;) 
[https://github.com/nais314/nimgpiod](https://github.com/nais314/nimgpiod)

Happy Holidays and Happy New Year to All!


Re: A pure nim GUI game for Linux & Windows

2019-12-17 Thread Stefan_Salewski
> to sell only a few thousand copies

Good joke! To sell 100 with current Nim community size may be possible, maybe 
200 with a chinese translation. A free book may have indeed 1k readers. My 
guess is that manning sold some hundreds of NimInActions indeed, but that was 
when Nim was new and had some hype, in 2015. And they sold them for only 20$. 
Now many people know already Nim, so they may not want to buy a book. And we 
have a lot of free resources now.


Re: A pure nim GUI game for Linux & Windows

2019-12-17 Thread marks
`shuffle()` is in-place but it did save me one line: 


var colors = gameColors # gameColors is a const seq[Color]
shuffle(colors)
colors = colors[0 ..< game.maxColors]


Run

It is true that NiGui uses Gtk on Linux, but Gtk is pretty well always on 
desktop/laptop systems even KDE ones, since there're bound to be apps that 
depend on it.

Nim could certainly do with a really good book -- I'd certainly like to read 
one.

(I've dipped into Nim in Action, but I felt it was too close to the docs, the 
main examples didn't appeal to me, and it isn't Nim 1.0.)

As for writing a Nim book: (1) I'd need to have done a lot more Nim programming 
-- which I'm in the process of doing; (2) I'd need to have at least one core 
dev willing to read and give feedback on all the examples _and_ on the text -- 
over a 12-18 month period; (3) I'd need to interest my -- or another -- 
publisher; (4) I'd need to feel motivated to spend at least a year working on a 
book that's likely to sell only a few thousand copies and so be a labor of love 
rather than economically viable. So I'm hoping someone else does it:-)


Re: A pure nim GUI game for Linux & Windows

2019-12-17 Thread Stefan_Salewski
Outplace is new in devel, but I wrote "shuffle does the trick". I only used 
outplace in the example to generate the mutable test array from the range.

And note that NiGui depends on GTK on Linux, so your earlier statement "pure 
Nim, no depencies" is only valid for windows. There are some GUI libs which do 
not need SDL or OpenGL. GTK3 needs GTK3 of course. And wNim runs on windows 
only. First I considered making a GTK3 version of your game, may take a few 
hours over Christmas. But the game idea is too boring, and I have to do really 
many other stuff, sorry.

Are you considering writing a Nim book? Saw your Python and Go books.


Re: A pure nim GUI game for Linux & Windows

2019-12-17 Thread marks
I can't find outplace (at least not in 1.0.4 or 'latest' on the Nim 
playground). However, I'll have another go with shuffle which I already use 
elsewhere.

I'm sure there are other Nim libs that support NiGui's missing features -- but 
don't all of them depend on SDL or OpenGL or other third party libs?

As for github, I have an a/c there to contribute, but I don't put my own 
projects there. My gravitate packages include the full source.