Re: can not run nimedit

2019-02-12 Thread twetzel59
Hmm, I can't tell from here what the problem is, aside from the fact that it is 
a segmentation fault.

Does it seem to always crash in the same procedure? If so, I suspect it is a 
fixable bug. Keep in mind that `nimedit` isn't as well supported as other IDEs.


can not run nimedit

2019-02-12 Thread tbutton
I compiled nimedit 
[https://github.com/Araq/nimedit](https://github.com/Araq/nimedit). added dlls: 
sdl2.dll, sdl2_ttf.dll from this site: 
[https://www.libsdl.org/download-2.0.php](https://www.libsdl.org/download-2.0.php).
 nimedit does not works. when I start nimedit, it writes 


Tracebar list(most recent call list)
nimedit.nim(1203) nimedit
nimedit.nim(1127) mainProc
nimedit.nim(547) loadTheme
nimscriptsupport.nim(127) loadTheme
nimscriptsupport.nim(73) getGlobal
nimscriptsupport.nim(37) getGlobal
SIGSEV:illegal slotage access. (attempt to read from nil?)


Run

why? please help me


how run aporia on windows

2019-02-12 Thread tbutton
hello, i want to use aporia for programming on nim, but aporia does not starts. 
[https://github.com/nim-lang/Aporia#dependencies](https://github.com/nim-lang/Aporia#dependencies).
 i did all by following manual, but aporia writes 


:\Users\tbutton\Desktop\Aporia-master>aporia
   could not load: libglib-2.0-0.dll

Run

no one libglib-2.0-0.dll from web does not works. where i can find 
libglib-2.0-0.dll for aporia, for programs compiled with nim?


Re: Is there a way to make kind of like an override named block?

2019-02-12 Thread solo989
Now with string. 


import macros
import tables

var overrides {.compiletime.} = initTable[string,string]()
macro override(aStr : static[string], b: untyped) : untyped =
  var x = genSym(nskTemplate)
  overrides[aStr] = x.strVal
  result = quote do:
template `x`() : untyped =
  `b`

macro section(aStr : static[string], b : untyped) : untyped =
  if aStr in overrides:
let templateName = ident(overrides[aStr])
result = quote do:
  `templateName`()
  else:
result = b




override "redbox":
  echo "Hello"

section "redbox":
  echo "Goodbye"

section "whatever":
  echo "Hello World!"


Run


Re: Is there a way to make kind of like an override named block?

2019-02-12 Thread treeform
Do you know if I can make it work with strings? Some how to turn string into a 
symbol in a template?


template override(a: string, b : untyped) : untyped =
  template {a cast from string}() : untyped =
echo a
b

template section(a, b : untyped) : untyped =
  when compiles({a cast from string}()):
a()
  else:
echo a
b

override "redbox":
  echo "Hello"

section "redbox":
  echo "Goodbye"

section "whatever":
  echo "Hello World!"


Run


Mix of varags & seq confusion

2019-02-12 Thread teras
Hello people, new user of nim here and I am already excited! I have the 
following scenario, for test purposes, and I think I'm missing something here, 
or, in other words, how to make the compiler get what I mean?


proc test(names:varargs[seq[string]]) = discard
proc test(names:varargs[string]) = discard

test "hello", "world"  # works
test @["hello"], @["world"]  # works
test @["hello", "world"]  # compiler error, I get an "ambiguous call"


Run

In my eyes this is not an "ambiguous call", since this is clearly a seq and not 
a varags. And this is obvious for me, since the two types are not 
interchangeable. So what I am missing here?


Re: Jester memory usage strangeness

2019-02-12 Thread Araq
Ah, probably your FD limit is high, 0.19.4 allocates a big seq upfront in order 
to never need reallocations, devel on Linux does not do this anymore.


Re: Unexpected async behaviour?

2019-02-12 Thread lemonboy
It's not a bug, it's a feature :) You probably missed 
[this](https://nim-lang.github.io/Nim/manual.html#closures-creating-closures-in-loops)
 part of the manual where it is explained that closures capture variable by 
reference. In your example the inner `serve` captures `c` by reference and, as 
a result, you're always listening on the last accepted connection. To solve 
this problem you can just create a local copy of `c` and use it.


Re: Jester memory usage strangeness

2019-02-12 Thread mratsim
If it's fixed on devel, it's possible to do a git bisect to track what fixed 
the issue.

There are months of commits though and several are a pain during bisections 
because you need to rebootstrap Nim (not nil changes from August especially) so 
it might not be worth it.


Re: Fuzzy matching on table keys

2019-02-12 Thread cblake
What mashigan wrote may well be best suited to your exact purpose. Another 
possibility at least worth a shout out is `collections/critbits` which 
implements an efficient `keysWithPrefix`. For more fuzzy still than prefix 
matching, you could also do some kind of efficient edit distance-based thing, 
but data-structures to (attempt to) optimize that are complicated. (There is 
`std/editdistance`, though).


Re: Jester memory usage strangeness

2019-02-12 Thread rifabio
Hi Araq,

  1. Thank you for this. I had no idea. Is there a place where I can find those 
information? Sadly, didn't changed the problem.
  2. My question was also: _how and where_ I report a problem that shows only 
on some machines? (I have two VPS and both has the same memory usage).



I also tried asynchttpserver with similar results (~20MB vs ~500kB):


import asynchttpserver, asyncdispatch

var server = newAsyncHttpServer()
proc cb(req: Request) {.async.} =
  await req.respond(Http200, "Hello World")

waitFor server.serve(Port(8080), cb)


Run

Lastly I switched to nim devel and everything is okay. Memory usage is same on 
laptop and server. So imho there's something wrong with 0.19.x and I'd love to 
help, just don't know how!


Re: Fuzzy matching on table keys

2019-02-12 Thread mashingan
Add `hash` function and equality operator `==` for custom key.


import tables, hashes

type
  Fn = proc (args: varargs[string]): int
  FnSignature = tuple
name: string
arity: int
argTypes: seq[string]

proc hash(fns: FnSignature): Hash = fns[0].hash
proc `==`(a, b: FnSignature): bool = a[0] == b[0]

var signatures = newTable[FnSignature, Fn]()

signatures.add(("print", 1, @["any"])) do (args: varargs[string]) -> int:
  discard

echo signatures[("print", 1, @["string"])]("whatev")


Run


Re: Newbie question about reading asynchronous text file line by line

2019-02-12 Thread moerm
The problem is that there seems to be no check for EOF.

This here works:


import asyncdispatch, asyncfile, os

proc main() {.async.} =
  var filename = "test.txt"
  var file = openAsync(filename, fmRead)
  let fileSize = file.getFileSize()
  while file.getFilePos() < fileSize:
let line = await file.readLine()
if line.len == 0: break
echo line
  
  file.close()

waitFor main()

Run


Fuzzy matching on table keys

2019-02-12 Thread lqdev
Hello,

I want to perform fuzzy matching on table keys. What I mean by that, is:


import tables

type
  Fn = proc (args: varargs[string]): int
  FnSignature = tuple
name: string
arity: int
argTypes: seq[string]

var signatures = newTable[FnSignature, Fn]()

signatures.add(("print", 1, @["any"])) do (args: varargs[string]) -> int:
  discard

echo signatures[("print", 1, @["string"])] # should return the first added 
element, because ``any`` describes any type


Run

>From what I know about hash tables, it's not as simple as adding an equality 
>operator overload to `FnSignature`. How do I achieve what I'm talking about?


Re: Newbie question about reading asynchronous text file line by line

2019-02-12 Thread mrhdias
I have created an issue [10641](https://github.com/nim-lang/Nim/issues/10641)


Re: "nim cpp -d:release --noCppExceptions" fails

2019-02-12 Thread masnagam
@Araq Thank you for your advice. I have created an issue 
[10652](https://github.com/nim-lang/Nim/issues/10652).


Re: Screencast Series Ideas

2019-02-12 Thread miran
> This is a big issue that I've been thinking about. I have an okay-ish 
> tabletop mic,

One think you could/should do is put a towel underneath your mic-stand. It 
reduces vibrations, killing some loud unpleasant keyboard sounds.


Re: What are the files in .nimble/bin

2019-02-12 Thread dom96
Try opening these files with a text editor, they're scripts.


Re: The portable way to find nimbase.h or system.nim location

2019-02-12 Thread slangmgh
Good. :)


Re: Jester memory usage strangeness

2019-02-12 Thread Araq
  1. Compiling with `--opt:speed --stackTraces:off` is the better idea for 
servers.
  2. There are no known memory leaks in Nim's stdlib or GC for the 0.19.x 
series, so I'm afraid you need to report a program that allows us to reproduce 
the issue.