Re: Library isolation (diamond dependencies)

2019-02-24 Thread CavariuX
Hi, NimGL developer here.

@chr This is an interesting issue but you should have no problems if you are 
not import stb/image from nimgl modules since that way it would not be 
compiling the stb_image twice. If you need to have both for whatever reason I 
could add a definition to toggle the compilation of the extra C file, please 
let me know if I can improve the lib in any way.

@Araq Can I do something to improve in this regard?


Re: How to speed up the upload of a big file with asynchttpserver!

2019-02-24 Thread mrhdias
Hi @dom96, I did an experiment (see 
[https://github.com/mrhdias/EnigmaHTTPServer](https://github.com/mrhdias/EnigmaHTTPServer))
 to decode the multipart/data request body by doing the cache of the body. I do 
not know if it's the best approach, but it works and it's fast for large files. 
But for me it is a temporary solution until I have a better one. 


Re: Noob question: proper way to read binary files byte by byte

2019-02-24 Thread cblake
You can also use `memfiles`. There writing/reading is the same as accessing 
memory. Besides being possibly simpler presenting an "as if you already read 
the whole file into a buffer" view, it may also be much more efficient, 
especially for byte-at-a-time operation where other APIs might do a lot of 
behind the scenes work on a per-IO basis. Of course, to be usable as a 
`MemFile`, the data needs to be random access (e.g. on the disk as opposed to a 
network socket or pipe or some other unseekable input).


Problem with templates in multiple files

2019-02-24 Thread cdunn2001
My code used to work. **msgpack4nim** was updated for nim-0.19.4, and now my 
code fails. But I don't think it's a bug in **msgpack4nim** , and I don't think 
I'm doing anything unexpected. I think there might be a fundamental problem 
with how Nim handles templates across multiple files now.

[https://github.com/jangko/msgpack4nim/issues/30](https://github.com/jangko/msgpack4nim/issues/30)

Does anybody have a solution? Or an idea?


Re: [Review request] for rosetta code challenge "Lexical Analyzer"

2019-02-24 Thread greenfork
`lexbase` is totally the case! In the challenge it is also suggested to use one 
variant as a "raw" version and one with a lexing support from the language. I 
also wrote a version which reads one character at a time and it became very 
dirty very fast as well as it was hard to debug it, so the 2nd, current version 
is with `re` :)

Actually it's overwhelming how much support Nim has for parsing grammar, 
there's `lexbase`, `re`, `pegs`, `strscans`.


Re: Noob question: proper way to read binary files byte by byte

2019-02-24 Thread r3c
[check this 
out](https://bitbucket.org/DraganJanushevski/q3bsp/src/cee3bf04b30414672939c0ffde25011ec026a822/src/coreBSP/bspfile.nim#lines-18)


Re: Noob question: proper way to read binary files byte by byte

2019-02-24 Thread mashingan
use [atEnd](https://nim-lang.org/docs/streams.html#atEnd%2CStream) to check 
whether it's ended or not and use 
[getPosition](https://nim-lang.org/docs/streams.html#getPosition%2CStream) for 
its current position.


import os, streams

var fs = newFileStream(paramStr(1), fmRead)

while not fs.atEnd:
  var one_char = fs.readChar()
  echo one_char


Run


Re: [Review request] for rosetta code challenge "Lexical Analyzer"

2019-02-24 Thread leorize
Great work!

Personally I think you should build one using `lexbase` instead of `re` as `re` 
seems to be too big just for this (the C version is written in plain C without 
`re`).

Actually if I could find sometime I'd try to build a `lexbase` version as it 
seemed fun :)


Noob question: proper way to read binary files byte by byte

2019-02-24 Thread vimal73700
Hi all,

What is the best way to read a binary file byte by byte?


import os, streams

var fs_pos = 0
var fs = newFileStream(paramStr(1), fmRead)

while true:
  var one_char = fs.readChar()
  echo one_char
  if (one_char == '\0'):
echo "breaking at " & $fs_pos
break
  fs_pos += 1


Run

streams.readChar() returns the same '0' for a null byte as well as EOF. Please 
advise.


Online Nim Compiler

2019-02-24 Thread aditya12
https://www.welookups.com/php/php_exception.html


Qt Creator 4.9 Beta has Nim support (code completion)

2019-02-24 Thread zarican
Change log in Qt Creator 4.9 Beta has an item


Nim Support
  *Added code completion based on `NimSuggest`


Run

Although it seems limited to code completion, it is still good news for Nim's 
popularity.

Change log 
[here](https://code.qt.io/cgit/qt-creator/qt-creator.git/tree/dist/changes-4.9.0.md?h=4.9)

In addition, it has now language server protocol for generic programming 
language support.

[https://blog.qt.io/blog/2019/02/21/qt-creator-4-9-beta-released/](https://blog.qt.io/blog/2019/02/21/qt-creator-4-9-beta-released/)


Re: Library isolation (diamond dependencies)

2019-02-24 Thread Araq
Having thought about this more, I think we can simply use the checksum of the C 
file in order to detect duplicates and then link only one version in the end...


defining `==` breaks Option

2019-02-24 Thread drewp

import options

type
  Base = ref object of RootObj
  A = ref object of Base
  B = ref object of Base
opt: Option[A]

proc `==`(x: A, y: B): bool = false

proc initA(): A =
  new result

proc initB(): B =
  new result
  result.opt = none(A)
  echo "saved none"

let x = initB()
assert x.opt.isNone()


Run

This assert fails , making it look like Option is misbehaving. If I set Option 
to none(), it ought to test as isNone, right? Somehow my == definition breaks 
it, but I don't think A==B should do anything to the workings of Option[A]. :(