Re: Call for QT bindings

2020-02-13 Thread Stefan_Salewski
Please stop spreading these wrong and unfriendly remarks!

> but there isn't any uptodate gtk3 bindings as far as I am concerned.

You did it already in

[https://forum.nim-lang.org/t/5657#35169](https://forum.nim-lang.org/t/5657#35169)

> Same pattern goes for gtk3. The only upto date gtk binding lacks any form of 
> API reference, and it's been a couple years.

We have made a large effort to provide high level GTK3 and GTK4 bindings in the 
last years, with ARC support and already many examples: 
[https://github.com/StefanSalewski/gintro](https://github.com/StefanSalewski/gintro)


Re: Newbie With Several (Likely Dumb) Questions

2020-02-13 Thread Stefan_Salewski
Note that there are many tutorials available, the "Nim Days" is already 
advanced and for special topics. See 
[https://nim-lang.org/learn.html](https://nim-lang.org/learn.html). The 
official Tutorial part 1 and 2 are a good start.

For your first question: Some people coming from Python have not even a basic 
computer science background, for example they do not even know the basic terms 
stack vs heap, value vs reference type, purpose of references and pointers and 
such. These people would have to learn some basics before they can write 
efficient Nim code. For the transition from Python to Nim there is this wiki 
page: 
[https://github.com/nim-lang/Nim/wiki/Nim-for-Python-Programmers](https://github.com/nim-lang/Nim/wiki/Nim-for-Python-Programmers)


Re: IntelliJ / Netbeans plugin for Nim

2020-02-13 Thread adnan
Recently, Kate has announced their support for language servers. Which means if 
in future, there's any language server for Nim, Kate can offer some basic IDE 
features.


Re: Call for QT bindings

2020-02-13 Thread adnan
Recently, Qt has decided that they will offer their open-sourced libraries only 
if you have a Qt account. Furthermore their LTS versions are officially behind 
a paywall.

[https://www.qt.io/blog/qt-offering-changes-2020](https://www.qt.io/blog/qt-offering-changes-2020)

I hope to start using the Nuklear binding soon. I am familiar with Gtk myself, 
but there isn't any uptodate gtk3 bindings as far as I am concerned. 


Re: In love with Nim

2020-02-13 Thread schmidh
Who's Nim? Your Korean girl friend?

You can get very far with Nim. It's a programmable programming language. 


In love with Nim

2020-02-13 Thread wintonmc
Hi all, I am very happy to have known this language and I have really loved to 
think that I have been learning about Nim for 1 month and a half. My favorite 
language was really C # but right now I am in a few moments that I just want to 
use Nim Syntax Legible, Clear and Comfortable. I am sure and I know that little 
by little this community will grow quite a lot.

At the moment I do not deny that there are little things that make me 
uncomfortable since they say that whoever programs Python or C, Nim would be 
very easy to my liking and point of thinking I never liked C / C ++ simply that 
I did not feel comfortable for The syntax for the moment has been true, I don't 
think I can give it a chance. I still do not know how far you can get 
programmed in Nim since my thoughts are broad to say that they are great, for 
now I stay with Nim really is a friendly language and especially I have been 
studying that this forum people do help and hopefully We can continue with that 
enthusiasm to help the needy without offense.

By the time I study I have shared Nim's information and my teammates liked the 
backend and front-end function. long life Nim

sorry if you find fault, I speak Spanish.


Newbie With Several (Likely Dumb) Questions

2020-02-13 Thread trivium
First off, I'm still getting my head wrapped around the language. I was 
considering Rust when Nim caught my attention for a few basic reasons:

  1. It compiles to C, so it's not interpreted.
  2. It's safer than C and _seems_ comparable to Rust in terms of type safety 
and concurrence but accomplishes this by different means.
  3. It's more intuitive than Rust for someone coming from Python/Bash with 
bits of Perl.
  4. The code is rather beautiful to look at.



I'm working my way though the [Nim Days](https://xmonader.github.io/nimdays/) 
tutorial. My biggest questions are:

  1. What are some of the common "gotchas" coming to Nim from Python?
  2. Are there any good libraries floating around for low-level work with 
binaries akin to the [Bitstrings](https://github.com/scott-griffiths/bitstring) 
library in Python?
  3. I found the [Stew](https://github.com/status-im/nim-stew) project. Is that 
the correct way to attempt to contribute code to the standard library?



BTW, Nim looks like it would be really flexible at implementing things like ASN 
or EBNF grammars. Wouldn't it make sense to have a single abstract grammar just 
for protocols and use that for all of the network code? The closest thing to 
that I can find for Nim is this [NPEG](https://nimble.directory/pkg/npeg) but 
it looks like it's a bit more tuned to text-based structures higher up the 
stack than, say, Ethernet frames, TCP packets, etc. Stop me if this is one of 
those ideas that sounds _great_ in theory but wouldn't be as helpful as it 
sounds in actual fact. 


Re: Threadpool slower than single-core

2020-02-13 Thread treeform
\--d:danger just does all of the possible optimizations.|   
---|---  
  
I use --threads:on and when compileOption("threads"): to include or not include 
threadpool. See line 3: 
[https://play.nim-lang.org/#ix=2bFk](https://play.nim-lang.org/#ix=2bFk)


Re: Suggestion for reading the docs?

2020-02-13 Thread schmidh
T and S in square brackets are generic types. You should read `Nim in Action`. 
Very nicely written book on Nim.

[https://book.picheta.me](https://book.picheta.me)


Re: Threadpool slower than single-core

2020-02-13 Thread schmidh
Your are right about randomness. I tried this out yesterday and it had a huge 
impact on the second output. So I commented it out. But overall same 
performance problem. Will try out your other suggestions tomorrow or so. Thank 
you.

One quick question: with the danger option you can compile module `threadpool` 
without thread support? 


Re: Idiomatic sequence functions

2020-02-13 Thread schmidh
Awesome. Thanks for your answer! 


Re: Threadpool slower than single-core

2020-02-13 Thread schmidh
  * I can increase `numDrawings` as I want. It's only getting worse.
  * There are no writes. The return values from each thread are just collected 
at the end. The return values are very small.
  * Every thread is independent of the other. There should be no blocking at 
all.




Re: Threadpool slower than single-core

2020-02-13 Thread treeform
I don't think threads run slower in my case.

I changed your program slightly to support threads and non threads: 
[https://play.nim-lang.org/#ix=2bFk](https://play.nim-lang.org/#ix=2bFk)


nim c -d:release -d:danger --threads:on "/p/tmp/prisoners.nim"
time ./prisoners
Succs: 311894   Fails: 688106   Total: 100  Success Rate: 31.1894%.
Succs: 0Fails: 100  Total: 100  Success Rate: 0.0%.

real0m8.288s
user0m15.779s
sys 0m0.008s


Run


nim c -d:release -d:danger "/p/tmp/prisoners.nim"
time ./prisoners
Succs: 312323   Fails: 687677   Total: 100  Success Rate: 31.2323%.
Succs: 0Fails: 100  Total: 100  Success Rate: 0.0%.

real0m11.459s
user0m11.452s


Run

Threads took 8s while non threads took 11s. Threads are faster. I only have two 
cores on this linux box so speed it was not that huge.

Some thoughts:

This code does call toSeq inside for loops for optimal speed there might be a 
way to allocate it only once and reuse it per thread.

You are using random numbers ... randomness might be causing different runs 
take different times.

You are using a global random which might not work great when accessed from 
different threads.


Suggestion for reading the docs?

2020-02-13 Thread lagerratrobe
Day 6 of my journey through Nim. I woke up refreshed and eager to understand 
the parsecsv module.

Very quickly I got to the point where I wanted to obtain the index position for 
a particular value in a sequence. A quick search led me to Stack Overflow 
([https://stackoverflow.com/questions/47638393/nim-find-the-index-of-an-item-in-an-array-or-sequence](https://stackoverflow.com/questions/47638393/nim-find-the-index-of-an-item-in-an-array-or-sequence))
 and a suggestion to use system.find()

I went to the appropriate docs page and found this:


proc find[T, S](a: T; item: S): int {...}


Run

I stared at that for awhile and then proceeded to try all of the following:


var headers = @["one", "two", "three", "four", "five"]

echo find["three",  headers]() # nope

echo headers.find["three"] # nope

echo headers.find("three") # Holy biscuits, YES!!!

echo find(headers, "three") # YAYY!


Run

I think the docs are great, but this isn't the 1st time I've misunderstood 
them. Could someone explain to me how I should interpret the syntax that's 
used? I happened to figure this one out because I happened to glance at the 
contains proc listed immediately below find in the doc.


find(a, item) >= 0.


Run


Re: Threadpool slower than single-core

2020-02-13 Thread treeform
I think your problem might come from:

  * trying to do too little work per thread - so thread stuff eats up all the 
time.
  * trying to write same cache line from multiple threads.
  * too much blocking




Re: Idiomatic sequence functions

2020-02-13 Thread treeform
Its [0 ..< 5]

You want slicing: 
[https://narimiran.github.io/nim-basics/#_indexing_and_slicing](https://narimiran.github.io/nim-basics/#_indexing_and_slicing)

See here: 
[https://play.nim-lang.org/#ix=2bFa](https://play.nim-lang.org/#ix=2bFa)


Idiomatic sequence functions

2020-02-13 Thread schmidh
Being new to Nim I'm missing basic list/sequence functions like e.g. take.


var lst = @[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
for n in lst.take(5)
  echo n
# 1
# 2
# 3
# 4
# 5


Run

I would also assume that there would be an iterator but I couldn't find any in 
the documentation. Is there a reason for it? Like functional style in Nim is 
discouraged? Or is there another more Nim idiomatic way to do it? Slices might 
be used in this case but would throw an exception when the list is too short. 
Enlightening welcome! :-)


Threadpool slower than single-core

2020-02-13 Thread schmidh
Just trying to learn Nim by going through the problems on "Rosetta Code". I 
wrote a Nim version for the "100 Prisonsers" problem - 
[http://rosettacode.org/wiki/100_prisoners#Nim](http://rosettacode.org/wiki/100_prisoners#Nim)
 \- and wanted to speed up things by going multi-core. Unfortunately the 
multi-core version is slower than the single-core one and I don't have a clue 
why.


import random, sequtils, strutils, threadpool, cpuinfo

type
  Sample = tuple
succ: int
fail: int

const
  numPrisoners = 100
  numDrawsEachPrisoner = numPrisoners div 2
  numDrawings = 1_000_000 div 1

proc `$`(s: Sample): string =
  "Succs: $#\tFails: $#\tTotal: $#\tSuccess Rate: $#%." % [$s.succ, 
$s.fail, $(s.succ + s.fail), $(s.succ.float / numDrawings.float * 100.0)]

proc prisonersWillBeReleasedSmart(): bool =
  result = true
  var drawers = toSeq(0..

Re: Newbie - trying to compile for macos from windows

2020-02-13 Thread Yardanico
You shouldn't run it with bash, you should just run it like ./hello after doing 
chmod +x hello on the resulting macOS machine


Re: Newbie - trying to compile for macos from windows

2020-02-13 Thread iwcoetzer
Thank you everyone! Great, I have a virtual box up with latest UBUNTU desktop 
installed. Managed to compile easy to Linux (ubuntu) no issues Also , managed 
to use mingw-w64 to compile an exe for windows Now, still playing with a way to 
compile to MacOS - I got a binary file compiled but cannot bash run it or mac 
os ...?

Good Evening Thank you for all the replies!

I have decided to push on with a new UBUNTU desktop installation in VirtualBOX 
(host is Windows 10). I managed to get it up and running in the UBUNTU desktop.

Compiling

  1. Managed to use mingw-w64 to compile an executable that works on Windows 
from Ubuntu :-)
  2. Managed to compile a terminal program for Ubuntu itself that is working :)
  3. I am still trying to see if I can compile a program (simple terminal app) 
for MacOS Sierra
not working :-(
* I managed to use this type of nim commands to get a binary compiled
nim -d:release --os:macosx --cpu:amd64 c 
"/home/ian/Desktop/nimproject/hello"
* but macOS Sierra does not want to run this thing vir a terminal using 
bash ./hello ...




Re: Newbie - trying to compile for macos from windows

2020-02-13 Thread iwcoetzer
Thank you everyone! Great, I have a virtual box up with latest UBUNTU desktop 
installed. Managed to compile easy to Linux (ubuntu) no issues Also , managed 
to use mingw-w64 to compile an exe for windows Now, still playing with a way to 
compile to MacOS - I got a binary file compiled but cannot bash run it or mac 
os ...?

Good Evening Thank you for all the replies!

I have decided to push on with a new UBUNTU desktop installation in VirtualBOX 
(host is Windows 10). I managed to get it up and running in the UBUNTU desktop.

Compiling

  1. Managed to use mingw-w64 to compile an executable that works on Windows 
from Ubuntu :-)
  2. Managed to compile a terminal program for Ubuntu itself that is working :)
  3. I am still trying to see if I can compile a program (simple terminal app) 
for MacOS Sierra
not working :-(
* I managed to use this type of nim commands to get a binary compiled
nim -d:release --os:macosx --cpu:amd64 c 
"/home/ian/Desktop/nimproject/hello"
* but macOS Sierra does not want to run this thing vir a terminal using 
bash ./hello ...




Re: Newbie - trying to compile for macos from windows

2020-02-13 Thread iwcoetzer
Thank you everyone! Great, I have a virtual box up with latest UBUNTU desktop 
installed. Managed to compile easy to Linux (ubuntu) no issues Also , managed 
to use mingw-w64 to compile an exe for windows Now, still playing with a way to 
compile to MacOS - I got a binary file compiled but cannot bash run it or mac 
os ...? 


Re: Programming help - Binary Search

2020-02-13 Thread adnan
Thanks. I missed that equal case. 


Re: Programming help - Binary Search

2020-02-13 Thread cblake
I think you just need `hi >= lo` instead of just `>` (the Java code you posted 
has that). You should also be told that this is in the Nim stdlib as 
`algorithm.binarySearch`, although it does use the simpler -1 return to signal 
"not found" rather than `Option[T]` stuff.


Programming help - Binary Search

2020-02-13 Thread adnan
Hi, my question is not specific to Nim but I'm asking it here because I'm using 
it :)

I am debugging a simple iterative binary search but it seems to fail my test. 
Here's my impl:


import options

proc index_of*[T](list: openArray[T]; key: T): Option[int] =
var
lo = list.low()
hi = list.high()
while hi > lo:
let mid: int = lo + (hi - lo).div(2)
if list[mid] < key:
lo = mid + 1
elif list[mid] > key:
hi = mid - 1
else:
return some(mid)
return none(int)



Run

My unittest:


import unittest, options

import cdsan/binary_search
test "binary_search":
  let list = @[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
  for item in list:
check index_of[int](list, item) == some(item)


Run

However my unittest fails witch cases below:

> /home/u9898287/proj/cdsan/tests/test1.nim(7, 36): Check failed: 
> index_of[int](list, item) == some(item) index_of[int](list, item) was 
> None[int] some(item) was Some(1) 
> >/home/u9898287/proj/cdsan/tests/test1.nim(7, 36): Check failed: 
> index_of[int](list, item) == some(item) index_of[int](list, item) was 
> None[int] some(item) was Some(4) 
> >/home/u9898287/proj/cdsan/tests/test1.nim(7, 36): Check failed: 
> index_of[int](list, item) == some(item) index_of[int](list, item) was 
> None[int] some(item) was Some(7) 
> >/home/u9898287/proj/cdsan/tests/test1.nim(7, 36): Check failed: 
> index_of[int](list, item) == some(item) index_of[int](list, item) was 
> None[int] some(item) was Some(10) >[FAILED] binary_search

Error: execution of an external program failed: 
'/home/u9898287/proj/cdsan/tests/test1 '
Tip: 1 messages have been suppressed, use --verbose to show them.


Error: Execution failed with exit code 1
... Command: "/home/u9898287/.nimble/bin/nim" c --noNimblePath 
-d:NimblePkgVersion=0.1.0 "-r" "\-->path:." 
"/home/u9898287/proj/cdsan/tests/test1"

The code is a somewhat similar to this piece of java code:


public static int indexOf(int[] a, int key) {
int lo = 0;
int hi = a.length - 1;
while (lo <= hi) {
// Key is in a[lo..hi] or not present.
int mid = lo + (hi - lo) / 2;
if  (key < a[mid]) hi = mid - 1;
else if (key > a[mid]) lo = mid + 1;
else return mid;
}
return -1;
}


Run

I can't seem to find the bug in my logic. Any pointers?


Re: Raylib Forever (4Nim)

2020-02-13 Thread federico3
Shameless plug: This can help updating the naming style: 
[https://github.com/FedericoCeratto/nimfmt](https://github.com/FedericoCeratto/nimfmt)


Re: Raylib Forever (4Nim)

2020-02-13 Thread Araq
Oh I'm aware there is a tradeoff here and everybody's time is finite. I only 
tried to get the point across **why** some people, me included, prefer code 
that uses Nim's naming conventions.


Re: Raylib Forever (4Nim)

2020-02-13 Thread Aiesha_Nazarothi
Well, right, but... Look, there are 90+ examples provided for original raylib, 
yet almost none of them was converted to Nim. I started translating some more 
basic stuff today and I'm completely, absolutely, positively against additional 
procname fixing.

Samples conversion is already errartic by itself, given some of them are 
outdated already (like shapes_draw_ring.c). I will probably think about 
aliasing proc signatures, but that't it.