Re: Happy New Year! Version 0.19.2 released!

2018-12-31 Thread bevo009
Happy New Year everyone!

[my old account wouldn't accept my password reset, so also testing the new 
forum account :) ] 


Re: Happy New Year! Version 0.19.2 released!

2018-12-31 Thread kaushalmodi
Awesome! Happy New Year! 


Default value for missing JSON fields

2018-12-31 Thread jegfish
I am trying to write a wrapper for a JSON API and I want to map its JSON 
objects to custom Nim objects. I am having trouble figuring out what to do with 
fields that aren't always provided in the JSON objects.


import json

type
  Type = object
# Normal field, always in the JSON object
normal: string
# Field that isn't always there, should have a default of false when it 
isn't
default: bool

let easy = to(parseJson("""
  {
"normal": "some string",
"default": true
  }
"""), Type)
let hard = to(parseJson("""
  {
"normal": "some string"
  }
"""), Type)
doAssert easy.default == true
doAssert hard.default == false


Run

Obviously this code will raise an error for the "hard" variable, but I would 
like to find a way around this. I have looked at the [options 
module](https://nim-lang.org/docs/options.html), but since I am trying to make 
this wrapper easy to use, I don't want my end users to deal with Option types. 
If it helps, I believe all of the possibly missing fields in the API end up 
defaulting to zero values like false or nil.


Re: Nim development blog

2018-12-31 Thread Araq
> For example, the discussion about GDB support and the state of GDB front ends 
> was very interesting, but I did not understand the final conclusion about the 
> state of GDB support. Does the latest Nim support better variable printing? 
> Was the project abandoned? Araq gave up on lldb, but Arne did some GDB python 
> integration, what was the final result of that?

`tools/nim-gdb.py` and `bin/nim-gdb` is in devel.

> I'm personally very interested in the state of destructors, but it is unclear 
> to me how finished that feature is. From what I know, the feature itself is 
> implemented, but in alpha state. How far along is new string and seq 
> implementation. When is that expected to arrive? Where is it being worked on 
> (some secret local branch on Araq's pc, lol)?

It's in devel, unusable, but behind the `--gc:destructors` switch. Beta quality 
is expected to arrive end of January.

> I have the same questions regarding the incremental compilation. 
> Bootstrapping with incremental is awesome, and the discussion was very 
> insightful, but what is the next step for this feature, and when / where is 
> incremental being worked on?

Same story, behind an `--incremental:on` switch but not hidden in a branch. 
Next steps:

  * Writing tests for it.
  * Make the AST reloads lazy in order to improve performance.
  * Make the C codegen cache its results too, currently only the frontend 
processing is cached.



Unknown release date.

> This dev blog is probably not the best place for that info, but It highlights 
> something I wish Nim had: A clear high level roadmap and status about what is 
> currently being worked on. I don't think github issues is good enough for 
> this. It requires something more curated and more prominently advertised (on 
> the main nim website probably).

Will think about this, in the past the roadmap we had was hardly maintained and 
github issues are but I'm sure we'll find something that works better. 


Re: Happy New Year! Version 0.19.2 released!

2018-12-31 Thread shashlick
Great work and awesome gift for the new year!

Tell all your friends who have asked for stability or 1.0 that the first 
official sustaining release was just posted. 


Re: Happy New Year! Version 0.19.2 released!

2018-12-31 Thread cdome
Fantastic, thank you. Happy New Year everyone 


Happy New Year! Version 0.19.2 released!

2018-12-31 Thread Araq
Many thanks to all the contributors who made these releases possible and Nim 
thrive. I'd like to thank @narimiran in particular for doing the backports. 
This is a bugfix release, no new features, no known regressions (but we'll soon 
know more...). However, there are rumors that with this release the `nimpretty` 
tool finally became useful. Enjoy!


Re: Convincing my friend about Nim

2018-12-31 Thread Araq
Maybe show him `nimforum`'s source code or any other project that's DSL-heavy, 
readable and concise.


Re: Convincing my friend about Nim

2018-12-31 Thread rect0x51
I have this feeling that the particular quote of Araq will become really famous 
and be remembered. So happy I was the one asking! :D


Re: Convincing my friend about Nim

2018-12-31 Thread SolitudeSF
Tell him that triple-digit iq is required to understand nim's greatness


Re: Convincing my friend about Nim

2018-12-31 Thread ggibson
I need a work break so this is a bit long :p If your friend isn't just having 
fun with you, then I wouldn't try explaining it, but focus on accepting the 
difference to stay friends. This squabble happens a lot in the young tech 
crowd, but really any young crowd. Your friend is adopting what sounds like the 
attitude of someone who is afraid and doesn't yet know how to deal with it. 
That might sound strong, but most things we do are guided by fear or other 
primal emotions. Guessing they are in secondary school or early university, it 
may take them another 5-10 years (that's being generous) to develop the 
personal awareness and introspection to ask themselves why they are having this 
reaction. Only then could you have a reasonable conversation with them. Some 
possible reasons for that fear may be your friend is afraid to branch out from 
C#, because learning [all of] C# is such a monumental task they couldn't 
imagine doing more (it is a bloated language after all). Or perhaps they are 
afraid you will learn stuff they won't know and they like to have an upper hand 
with you. Or maybe they're afraid all their effort in learning C# is wasted 
(it's not) if there's actually other newer cooler languages they "should've" 
been focusing on. There are many possibilities, but I would bet they are afraid 
of something. Cheers.


Type instantiation for `==` func

2018-12-31 Thread e
My first Nim library, so newbie warning... The library is a persistent balanced 
tree data structure that can be used as a map or a set. It's mostly working and 
tested, but I ran into trouble trying to make a generic == to match the 
built-in Nim set equality operator. Since the comparison is on keys only (type 
K), the type of the values does not need to match (U and V here).

So, this works...


func `<=`*[K,U,V](s1: BBTree[K,U], s2: BBTree[K,V]): bool {.inline.} =
result = isSubset(s1, s2)

Run

but this gives **Error: cannot instantiate: 'V'**


func `==`*[K,U,V](s1: BBTree[K,U], s2: BBTree[K,V]): bool {.inline.} =
result = isSubset(s1, s2) and len(s1) == len(s2)

Run

Note that the type declarations are identical. Even if I make the bodies of the 
two functions identical, Nim still gives an instantiation error for the second 
one. Is there something special about == that is preventing this from working? 


Re: Convincing my friend about Nim

2018-12-31 Thread trtt
Tell him the truth: C# is a kitchen-sink language for microsoft fans which is 
less expressive than nim and it also has a slower and bloated runtime.


Re: Could not load libwren.so

2018-12-31 Thread lqdev
So I decided to link the lib statically, doing the following steps:

  1. In my `nim.cfg` I added `--dynlibOverride:wren`
  2. In my source code I added this:




when sizeof(int) == 4:
  when defined(windows):
const wrenDynlib = "libwren-32.dll"
  elif defined(macosx):
const wrenDynlib = "libwren-32.dylib"
  else:
const wrenDynlib = "libwren-32.so"
elif sizeof(int) == 8:
  when defined(windows):
const wrenDynlib = "libwren-64.dll"
  elif defined(macosx):
const wrenDynlib = "libwren-64.dylib"
  else:
const wrenDynlib = "libwren-64.so"
{.link: currentSourcePath.splitPath.head / wrenDynlib .}


Run

There's probably a cleaner way btw, but I did this for testing.

ld doesn't return any errors, but my application itself does: 


/home/[user]/Coding/Nim/rapid/src/rapid: error while loading shared 
libraries: libwren.so: cannot open shared object file: No such file or directory
Error: execution of an external program failed: 
'/home/[user]/Coding/Nim/rapid/src/rapid '


Run


Re: Convincing my friend about Nim

2018-12-31 Thread shashlick
Opinions are a dime a dozen, no guarantee that any opinion is superior. If you 
do have strong opinions, enjoy them while they last.


Re: Convincing my friend about Nim

2018-12-31 Thread juancarlospaco
I never seen C# outside of MS Windows and related.

Just say that indentation brackets on Nim are written like `#{` and `#}` ;P


Re: Convincing my friend about Nim

2018-12-31 Thread sky_khan
Tell him he is right on all matters.

[https://tanndera.com/pin/the-secret-to-eternal-happiness](https://tanndera.com/pin/the-secret-to-eternal-happiness)/


Convincing my friend about Nim

2018-12-31 Thread lqdev
Hello,

First of all, I don't want to hate on other languages, or anything. I don't 
have anything against other languages' syntaxes, and I'm OK with people using 
them. But I have a friend who has recently "turned against me" – when I started 
using Nim, he started being really angry (no, really, he just started saying 
I'm stupid, etc) that I'm not using a normal (multiple quotes 
intentional) language. His main argument is Nim's syntax, even though he's 
never really tried to code in the language. He's pretty much a C# fanboy, he 
says the syntax is perfect and "it can run on many platforms" (I strongly 
disagree with that).

My main argument is that if he'd finally start coding in an ergonomic language 
like Python or Nim, he'd finally feel how easy it is to write and read code in 
it. What he dislikes the most, is the indentation-based syntax, and a few other 
"weirdnesses" you don't see in typical languages.

First of all, he states that not having such an indentation-based syntax allows 
for more freedom, even though he doesn't indent his code badly. I think this 
argument is just stupid, taking into account all of his programming practices.

But the main deal is about the syntax features themselves. I'm going to use 
this code sample to describe the problems he has with the syntax: 


type
  Box[T] = object
value: T

proc box*[T](value: T): Box[T] =
  result = Box(value: value)


Run

First of all, he really dislikes the lack of brackets, and the "misuse" of 
them. As I said, he's really used to C#, and thinks the generics syntax is 
stupid. His problem with it is the use of squared brackets `[T]` instead of 
angled brackets ``. I thought it was a weird decision too, but later found 
out it didn't really clash with the rest of the language and worked really 
well. Pretty much all of his jokes now rely on this argument, even though it's 
a preference and he shouldn't hate the language just because his preferences 
are different.

Next up, an "invalid" argument. He says macros are dumb, and you could just 
write code normally without them. I sort of agree with him, but no. Macros are 
really useful, especially when you have to write a ton of repetitive code when 
you want to embed a scripting language for your application, or something 
similar.

His last argument is that Nim is not very popular. I left it for last, because 
it's not an argument – you can't judge something by how popular it is.

I tried approaching him with a quote from Araq:

> Nim's target audience is the enlightened/misguided programmer who doesn't 
> understand why there should be more than one programming language.

And yet, he keeps being stubborn about his opinion.

How can I convince him to at least stop hating the language so much, or to 
change his decision and try out the language?


Re: Could not load libwren.so

2018-12-31 Thread shashlick
I did the same with nimbass.

[https://github.com/genotrance/nimbass/blob/master/nimbass.nimble](https://github.com/genotrance/nimbass/blob/master/nimbass.nimble)

Not much choice beyond tweaking LD_LIBRARY_PATH at runtime. It's part of the 
reason most of the nimgen wrappers compile in the code. 


Re: Could not load libwren.so

2018-12-31 Thread dom96
Have you tried this?


LD_LIBRARY_PATH="$(pwd)" ./binary


Run


Re: Could not load libwren.so

2018-12-31 Thread Araq
Use `--dynliboverride` to disarm the `.dynlib` pragmas and link statically. 


Re: Could not load libwren.so

2018-12-31 Thread lqdev
I don't want to rely on the end-user to compile and install `libwren.so` 
themselves, that's why I wanted to provide the lib with my application. Could 
static linking work there? If so, how can I achieve it with a wrapper that uses 
the `dynlib` pragma everywhere?


Re: Could not load libwren.so

2018-12-31 Thread Araq
How dynamic libs are resolved is an OS specific detail, it never works by 
putting it into `src/`, copy it to `/usr/lib` or tinker with LD_LIBRARY_PATH.


Could not load libwren.so

2018-12-31 Thread lqdev
Hello,

I'm trying to use @geotre's Wren wrapper for Nim, but I can't get dynamic 
linking to work. Here's my folder structure with the relevant files:


.
└── src
├── lib
│   └── wren
│   ├── info.txt
│   ├── LICENSE
│   ├── readme.md
│   ├── src
│   │   ├── wren
│   │   │   └── libwren.nim
│   │   └── wren.nim
│   └── wren.nimble
├── libwren.so
└── rapid.nim


Run

The wrapper's `libwren.nim` file depends on the `libwren.(dll|dylib|so)` 
dynamic library, and I'm putting it into my `src` folder, as you can see above. 
The wrapper unfortunately isn't available on Nimble, so I had to include it in 
my `lib` folder. `libwren.so` has been compiled from the official repo: 
[https://github.com/wren-lang/wren](https://github.com/wren-lang/wren), using 
the command `make shared`, on a 64-bit machine.

Now, the problem is, my application runs into an error: 


libwren.so: cannot open shared object file: No such file or directory
could not load: libwren.so


Run

This is the program's output when compiled with the `-d:nimDebugDlOpen` switch 
(Nim also says `libpcre.so.3` is missing, but I'm not going to use PCRE in my 
final application so I stripped it from the output).


Re: TDD reference project

2018-12-31 Thread mratsim
You can look into the [unittest](https://nim-lang.org/docs/unittest.html) module

I'm not really using TDD, but I try to always have a test for general and edge 
cases every time I had a new public proc or type in 
[Arraymancer](https://github.com/mratsim/Arraymancer).

The runners are done in the [nimble 
file](https://github.com/mratsim/Arraymancer/blob/v0.5.0/arraymancer.nimble) 
with CI on Nim devel and latest table for [Linux, 
Mac](https://github.com/mratsim/Arraymancer/blob/v0.5.0/.travis.yml) and 
[Windows](https://github.com/mratsim/Arraymancer/blob/v0.5.0/.appveyor.yml). 
This includes serial, parallel, OpenCL, Cuda, stability and probabilistic tests.

I don't need that much mocking because I'm favoring a stateless approach.

For comprehensive tests with mocking, you can check 
[Nimbus](https://github.com/status-im/nimbus/blob/d556cf764188e60fe4ac802965ce74153a02f51b/tests/test_vm_json.nim#L28-L67)
 and the corresponding [JSON 
tests](https://github.com/status-im/nimbus/tree/d556cf764188e60fe4ac802965ce74153a02f51b/tests/fixtures).
 The tests are for a blockchain virtual machine. Basically we setup a VM, load 
the current state from the JSON files, execute the next transaction, and verify 
that the end state is as expected.

In short with have either proc, templates or macros that setup the VM mocking 
with the fixtures in a JSON file.

Both Arraymancer and Nimbus use and extend the unittest module for their 
specific use-case. 


TDD reference project

2018-12-31 Thread novikov
Looking for a correct way to set up my project to apply TDD. I need a test 
runner, mocking framework and coverage report to do this properly. Some things 
I have already figured out but it takes a lot of time that I'd be happy to 
spend writing application code.

**Is there an example project out there with 100% code coverage?**

I try to move my project from C to some modern programming language. The 
project has unit tests in C. But creating mocks manually is tedious and slows 
development down. 
[https://github.com/mem-memov/net/tree/master/graph](https://github.com/mem-memov/net/tree/master/graph)

At work I use PHP 7.2 and PHPUnit framework which is a great tool. I had an 
idea that something like this should exist for Nim or D.