Re: Godot and Blender

2019-12-03 Thread carterza
Godot already has Nim support via GDNative. If you want Nim support for 
Blender, it would be better to suggest it to the Blender folks. Or you could 
add it yourself.


Godot and Blender

2019-12-03 Thread Hendrik
I want to put forward a suggestion of maybe NIM support for Godot and Blender. 
Both are open source and Blender especially now since 2.8 have jumped in 
potential. Godot is improving by a lot and many people are moving from Unreal 
and Unity to it. The only problem its got is it is slow which I believe NIM can 
remedy. I think it be amazing for both NIM, Godot and Blender to work together 
to create the ultimate free and opensource combination. 


Sublime Text 3 support

2019-12-03 Thread Hendrik
Was wondering if anybody got NIM to work with Sublime text 3? It is the editor 
I am using and I enjoy it quite a bit I can't seem to get NIM to work. I 
installed a package for NIM but it doesn't seem to be updated for a year.


Any possibility of a near term Lazarus/C#-like GUI-designer IDE?

2019-12-03 Thread stph
This is my first post - and I confess I've not used Nim -- but I LIKE what I 
see: it looks like Python. And I'm aware of the benchmarks showing run speed 
incredibly close to C. What stops me from getting really excited is that there 
doesn't appear to be good GUI support, nor any clearly specified roadmap to 
prioritize that.

I'm specifically looking for a language which will allow me to do C# like 
enterprise development for the Linux top - bringing together a lot of GUI 
input/output and a lot of database access. I'm considering Lazarus; it's 
probably the best currently obvious bet.

But I confess I prefer Python-like clean and readable syntax. And Nim certainly 
has that!

Forgive me if this is an ignorant question, or if it has been asked and 
answered, but Lazarus is open source. Has there been any thought of adapting it 
to self-reflectively work with Nim? Or, if it is just too hard to mix the 
languages, would it be worth using Lazarus as a model to follow to speed the 
develop a totally Nim-based Delphi-like IDE?

I could be wrong, of course, but it seems that could be a real game changer for 
Nim...looks like Python, acts like Delphi, and dominates on Linux.

If this is improbably difficult or there is a better plan I'd like to better 
understand. Actually, I'd appreciate any clear statement of the roadmap re this 
possibility -- it will let me know when to come back.


Re: Set object field from strings at run time?

2019-12-03 Thread jasper
One possible implimentation with fieldPairs: 


import std/strutils
from std/macros import expandMacros

type Foo = object
  ival: int
  fval: float

proc setField[T: int](val: var T, str: string) =
  val = parseInt(str)

proc setField[T: float](val: var T, str: string) =
  val = parseFloat(str)

template implSetObjectField(obj: object, field, val: string): untyped =
  block fieldFound:
for objField, objVal in fieldPairs(obj):
  if objField == field:
setField(objVal, val)
break fieldFound
raise newException(ValueError, "unexpected field: " & field)

proc setObjectField[T: object](obj: var T, field, val: string) =
  # inside a generic proc to avoid side-effects and reduce code size.
  expandMacros: # to see what it generates
implSetObjectField(obj, field, val)

var a = Foo(ival: 1, fval: 2.0)
setObjectField(a, "ival", "38")
setObjectField(a, "fval", "4e8")
echo a


Run


Re: Set object field from strings at run time?

2019-12-03 Thread doofenstein
Nim is a compiled language, this means when you access a field the regular way 
the constant relative memory location of an object field has to be known at 
compile time, which in turn forbids these things.

While it is possible to associate this offset with strings, either yourself 
(offsetof is the key here). Or you can use the runtime time informations which 
are meant for **internal** use via typeinfo 
. Neither of these methods are 
recommended in any way, unless you are very very sure what you want to do.

You're probably better off using either a simple table 
 or json nodes 
 (they can be created manually). Though 
again, think triece, you loose most of the speed and type safety when using the 
latter, essentially you then access variables like in a interpreted language.


Set object field from strings at run time?

2019-12-03 Thread pmags
I'm trying to write a template to set a value to an object's field, at run 
time, where the field name and the value are passed to the template as strings. 
The code below illustrates what I'm trying to do. Is there a way to accomplish 
this? i.e. is there some equivalent of my hypothetical untypedFromString 
function below?


type Foo = object
  bar: int

template setObjectField(obj: untyped, field: string, value: string): 
untyped =
  let
f = untypedFromString(field)
v = untypedFromString(value)
  obj.f = v

a = Foo(bar: 1)
setObjectField(a, "bar", "3")



Run


Re: How to create a trojan and reverse shell with NIM

2019-12-03 Thread kodkuce
beh evil is overated, anyway i would help you if i know how, i newer writed a 
trojan but if converting python to nim guess it isent uber complicated


Re: Question about multithreaded use of filestream.readLine() function

2019-12-03 Thread forcefaction
Hm yes that makes sense.

The input fie contains a URL per line which has to be checked and the result 
should be written into a file. Because this depends on Network latency i 
thought it would speed up the program if i spawn many connections ~300-400 
concurrently. But maybe i'm mistaken.


Re: Advent of Nim 2019 megathread

2019-12-03 Thread Kaynato
Relatively new to nim but decided to have fun learning with this year's AoC 
(and practicing on previous years' for speed). This is probably filled with 
non-idiomatic and misc. bad practices. 
[https://github.com/Kaynato/AdventOfCode](https://github.com/Kaynato/AdventOfCode)


Re: Nim is the friendliest language to start

2019-12-03 Thread juancarlospaco
It has project creation/scaffolding `nimwc --initplugin`. Frontend, NimF or 
Karax is recommended, but it is JavaScript framework Agnostic. Plugins, 
Components, same stuff, you can bundle all assets, files, folders together. 


Re: Nim tutorial -- Kaushal Modi's notes

2019-12-03 Thread carterza
  1. Did you ask Kaushal Modi if this was okay?
  2. Why don't Vernon / other authors post about these updates themselves and 
why do multiple authors post messages through this single account?
  3. Is Chapter 11 ever going to become something coherent / relevant, or is 
explaining to the Nim community about the anthropology of money something 
you're really striving after?




Re: Nim is the friendliest language to start

2019-12-03 Thread kodkuce
isent it better to have have components then all boundled together


Re: Nim is the friendliest language to start

2019-12-03 Thread Willyboar
Yes. Also, assets, project creation, scaffolding, and all the things make it 
newbie-friendly but also enough powerfull for advance users.


Re: Nim is the friendliest language to start

2019-12-03 Thread Araq
Well what do you consider "full stack"? A database layer and authentification?


Re: Question about multithreaded use of filestream.readLine() function

2019-12-03 Thread mratsim
The issue is that to write to a file, you basically need to serialize the 
writes. Multithreading will only help you for compute tasks that are CPU-bound. 
Writing to disk is very very very **very** slow, even a SSD, to give you an 
idea:

>From [What every programmer should know about 
>latency](https://gist.github.com/jboner/2841832)



Latency Comparison Numbers (~2012)
--
L1 cache reference   0.5 ns
Branch mispredict5   ns
L2 cache reference   7   ns  
14x L1 cache
Mutex lock/unlock   25   ns
Main memory reference  100   ns  
20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000   ns3 us
Send 1K bytes over 1 Gbps network   10,000   ns   10 us
Read 4K randomly from SSD* 150,000   ns  150 us  
~1GB/sec SSD
Read 1 MB sequentially from memory 250,000   ns  250 us
Round trip within same datacenter  500,000   ns  500 us
Read 1 MB sequentially from SSD* 1,000,000   ns1,000 us1 ms  
~1GB/sec SSD, 4X memory
Disk seek   10,000,000   ns   10,000 us   10 ms  
20x datacenter roundtrip
Read 1 MB sequentially from disk20,000,000   ns   20,000 us   20 ms  
80x memory, 20X SSD
Send packet CA->Netherlands->CA150,000,000   ns  150,000 us  150 ms

Notes
-
1 ns = 10^-9 seconds
1 us = 10^-6 seconds = 1,000 ns
1 ms = 10^-3 seconds = 1,000 us = 1,000,000 ns

Credit
--
By Jeff Dean:   http://research.google.com/people/jeff/
Originally by Peter Norvig: http://norvig.com/21-days.html#answers

Contributions
-
'Humanized' comparison:  https://gist.github.com/hellerbarde/2843375
Visual comparison chart: http://i.imgur.com/k0t1e.png


Run

On a 3Ghz CPU (i.e. ~3 billions basic instructions per second), a basic 
operation like add, sub, or, and, mul, shift, xor, if/then/else takes 1s / 3e9 
instr = 0.33 ns/instr. Assuming a SSD at 15 us / 0.33 (ns/instr) = 454545 
basic operations in the time required to write 4kB to a SSD.

Unless you have **very heavy** processing to do before writing to disk you 
don't need to parallelize.


Re: Question about multithreaded use of filestream.readLine() function

2019-12-03 Thread forcefaction
Thank you for your time and the detailed explanation , now i understand and it 
works across many physical cores.

Because i have to write data into a single file the lines are now mixed up, i 
think i need channels (?) to solve this, i will read how that works try it out 
and ask again if i have problems :)


Re: Nim is the friendliest language to start

2019-12-03 Thread Willyboar
I agree. Both are awesome tools. But I am talking about a full stack framework. 
Something that attract more people in the Nim community because is a huge 
market.


Re: Nim is the friendliest language to start

2019-12-03 Thread Willyboar
I agree. Both are awesome tools. But I am talking about a full stack web 
framework. Something that attract more people in the Nim community because is a 
huge market.


Re: Nim tutorial -- Kaushal Modi's notes

2019-12-03 Thread Lecale
Thanks I can't get enough of tutorials.


Re: What's wrong with pull requests auto checks?

2019-12-03 Thread Araq
There is only a single unstable test case as far as I can tell that keeps 
triggering. We already increased the involved timeout, not sure if that solves 
it for good or not. If not, we can disable the test.


Nim tutorial -- Kaushal Modi's notes

2019-12-03 Thread edu500ac
This is to bring you up to date with the Nim tutorial that the Della-Vos group 
is writing. Vernon started working on Kaushal Modi's notes. These notes are 
very instructive and cover very basic material, which could be quite helpful 
for beginners. Therefore, we decided to place Kaushal Modi's material at the 
very beginning of the book. The notes start with commands to print text in 
different colors and styles, a Nim feature that is not often found in compiled 
languages, and which newcomers to Nim will certainly appreciate. As a reminder, 
updates to the book are given every Tuesday at the following link:

[https://github.com/FemtoEmacs/nimacros](https://github.com/FemtoEmacs/nimacros)/


Re: [C backend] Environment of closure on stack

2019-12-03 Thread mratsim
I also require more ways to manipulate closures or being able to implement my 
own from macros.

This would allow me to emulate the OpenMP API or the `parallel` API in my 
multithreading runtime.

I still have to explore the liftLocal pragma or the `owner` macro though 
([https://forum.nim-lang.org/t/4031#25106](https://forum.nim-lang.org/t/4031#25106)
 / 
[https://github.com/nim-lang/Nim/pull/8253](https://github.com/nim-lang/Nim/pull/8253))


Re: Nim extension libs for python

2019-12-03 Thread mratsim
3 people at least managed to ship Nim libraries on Conda:

  * 
[https://github.com/fragcolor-xyz/nimtorch/tree/master/conda/nimtorch](https://github.com/fragcolor-xyz/nimtorch/tree/master/conda/nimtorch)
  * 
[https://anaconda.org/bioconda/hts-nim-tools](https://anaconda.org/bioconda/hts-nim-tools)
  * 
[https://github.com/conda-forge/nim-feedstock](https://github.com/conda-forge/nim-feedstock)



I can't say how it works though.

Otherwise, I think the best way to do that is to make producing a .dll/.so part 
of your CI (i.e. continuous deployment). There are a couple of examples here 
for CI: 
[https://github.com/nim-lang/Nim/wiki/BuildServices](https://github.com/nim-lang/Nim/wiki/BuildServices),
 I'm not sure there are some for auto-deployments.


Re: Nim extension libs for python

2019-12-03 Thread juancarlospaco
[https://github.com/yglukhov/nimpy/wiki#publish-to-pypi](https://github.com/yglukhov/nimpy/wiki#publish-to-pypi)

I use Docker for Windows on Windows, and most people seems to be using Docker 
anyways, for other OS, both languages have a construct named `if` that can be 
used to branch the build.

Pseudo code


  if WINDOWS:
sources = "windows/*.c"
  elif LINUX:
sources = "linux/*.c"


Run

^ Basically, you see even more crazy stuff on Pythons `setup.py` whatsoever. 


Re: Nim lang for beginners?

2019-12-03 Thread juancarlospaco
The Nim book is also really nice. If you are just starting, ignore Pointers and 
MetaProgramming for now, practice basic constructs, thats like making a Python 
"Hello World" using CTypes. ;P 


[C backend] Environment of closure on stack

2019-12-03 Thread foldl
Hi all,

Env-s are allocated on heap by `newObj`. Is it possible to put them on stack? 
There are some cons, such as closure can't live out of a function's scope. But, 
in the case of truly embedded systems with only several KiB RAM with 
`-gc:regions`, env-s on stack is good enough, ^_^


Re: Nim extension libs for python

2019-12-03 Thread Araq
You can bundle different C codes via `niminst` but I'm not sure how useful that 
is for Python interop. But please keep me in the loop, it's definitely a 
usecase we seek to support well.


What's wrong with pull requests auto checks?

2019-12-03 Thread foldl
They seem to be unstable and untrustworthy.


Re: Error running nim hello world from snap installation

2019-12-03 Thread enthus1ast
Looks like nimble is out of date. I would try to update nimble or nim tools in 
general


Re: Nim lang for beginners?

2019-12-03 Thread SolitudeSF
[https://narimiran.github.io/nim-basics](https://narimiran.github.io/nim-basics)/


Error running nim hello world from snap installation

2019-12-03 Thread fabian20ro
Here are the the commands I ran on my Ubuntu 18.04:


$ sudo snap install nim-lang nim-lang-docs
$ mkdir hello-nim
$ cd hello-nim
$ nim-lang.nimble init
(chose binary and c)
$ nim-lang.nimble run .
 Error: Could not read package info file in 
/home/myuser/stuff/hello_nim/hello_nim.nimble;
...   Reading as ini file failed with:
... Invalid section: .
...   Evaluating as NimScript file failed with:
... /tmp/nimblecache/nimscriptapi.nim(7, 8) Error: cannot open 
file: strformat


Run

Any idea how I can fix this?


$ nim-lang.nim -v
Nim Compiler Version 1.0.4 [Linux: amd64]
Compiled at 2019-12-02
Copyright (c) 2006-2019 by Andreas Rumpf

git hash: 0117460b6a74c2b4e846841200a30c1e19551c85
active boot switches: -d:release

$ nim-lang.nimble -v
nimble v0.11.0 compiled at 2019-12-02 22:18:38
git hash: 4007b2a778429a978e12307bf13a038029b4c4d9


Run


Nim extension libs for python

2019-12-03 Thread Jonesmartinze
I've been looking at using nim to create extension modules for python. I would 
typically do this using cython and C/C++ with the workflow: Write in python -> 
profile -> re-write slow functions in cython -> compile to shared object (via 
c). Using the nimpy lib, I've been doing essentially the same thing with nim, 
which after initial set-up actually seems easier!

But I'm confused about how to approach distribution of the extensions as python 
libraries. With cython-written extensions, I would:

create a sourse distribution of .py and .c files. The end user builds this so 
it matches their system architecture/OS.

and/or create platform specific wheels for the most obvious platforms from .py 
and .so/.pyd

and/or create general wheel from .py and .pyx files, with a cython dependancy.

With nim, the generated .c is platform specific, does this means 1) is out?

Creating a nim dependancy for 3) doesn't seem feasible to me, even if the end 
user was willing to install nim (cython is a pypi package, so the installer can 
grab it and put it in the correct place automatically).

So that just leaves 2), creating all the combinations (e.g. 22(!) for numpy) of 
binaries for platform-specific wheels.

Are there any better methods to do this? The only nim extension pypi libraries 
I've seen (e.g. faster_than_requests) are not cross-platform enough even for my 
limited uses (Linux and windows 32 and 64 bit)


Nim lang for beginners?

2019-12-03 Thread WhiteleeMartinze
Does anyone know of beginner Nim tutorials… or knows how to use it and could 
create some? All of the tutorials I have seen assume that you’re coming over 
from another language and thus don’t need certain concepts explained. Also 
example code that looks like it wouldn’t work on its own (never-defined 
variables? I could be wrong).

I have done a couple of Python scripts (working with images), and a while ago I 
did the required visual basic stuff in a programming+interactive media class 
(also Maya Embedded Language and Google App Inventor).

Because of what little I’ve done being higher level (or abstracted altogether), 
I’m completely lost when it comes to compiler stuff, pointers, metaprogramming 
(I have the feeling I just said something similar to “squares, diamonds, 
rectangles, and quadrilaterals”), interacting with other languages, etc.


Re: How to Maintain a Nim Chinese Community

2019-12-03 Thread PMunch
Recently discovered this site: [https://nim-cn.com](https://nim-cn.com) which 
appears to be a translated version of the main page. As for a forum I don't 
think there is anything like that, but as others have said it is possible to 
use this open source forum and just set up a new version.


Re: Advent of Nim 2019 megathread

2019-12-03 Thread tradfursten
Here is my repo. Solving in nim and then doing some in Elixir as well 
[https://github.com/tradfursten/advent_of_code_2019](https://github.com/tradfursten/advent_of_code_2019)


Re: Nim is the friendliest language to start

2019-12-03 Thread PMunch
For web framework using Jester + Karax is a fairly solid combination. Or if you 
don't want a single page application then Jester + your web DSL of choice.