How to escape colon in the '&' macro in strformat ?

2021-05-24 Thread stbalbach
This hack works (1.4.0) import strformat, re proc colon(): char = ':' echo &"""{re.replace("hello" & colon() & " world", re.re("hell"), "X")}""" Run FWIW (1.6 doesn't build for me via choosenim - will wait for stable to catch up)

c2nim -- minor update

2021-05-24 Thread Araq
> How does it mesh with nimterop? Nimterop doesn't support C++ and produces platform specific Nim code. Well, wether it's platform specific depends on the C code, I guess. Nimterop is usually much easier to use.

c2nim -- minor update

2021-05-24 Thread Araq
> I still don't understand why not use LLVM as in dlang and get perfect parsing > of C, C++ and many other languages. I simply improve what we have, PRs to use clang's parser instead are welcome. Talk is cheap.

Accessing object in seq of parent type

2021-05-24 Thread fengkehh
Technically you can do it by using "of" to do a type check: import sequtils import tables type MyBaseType = ref object of RootObj TypeA = ref object of MyBaseType name: string # method foo(this: MyBaseType) {.base.}

nimsuggest, neovim, nim.nvim trouble

2021-05-24 Thread lotzz
long story short I am using the neovim plugin, [nim.nvim](https://github.com/alaviss/nim.nvim) but It says it uses nimsuggest >= 0.20.0. I cant figure out for the life of me how to get the version number of nimsuggest, and it could just be a problem with the plugin. if anyone has either a fix,

Add total ratings for all Candidates (STAR Voting)

2021-05-24 Thread masiarek2
ggplotnim installed without any hiccups. I started looking at your solution - but my brain exploded. I need 2 month to learn how ggplotnim works :-). Thank you!

c2nim -- minor update

2021-05-24 Thread elcritch
> designated initializers Thank you! It’s the most common issue I find importing C apis.

Add total ratings for all Candidates (STAR Voting)

2021-05-24 Thread Vindaar
While not exactly the kind of solution you strictly want, I wanted to try to implement this in a dataframe kind of way, using the `ggplotnim` dataframe. Two small annoying things, but works well otherwise. The solution should give you some idea on how to implement the final step of the computat

c2nim -- minor update

2021-05-24 Thread treeform
I wish there was non need to parse C/C++ and dynamic or static libraries could just have a binary API that describes the functions and the structure it takes. Some one back in the 80s or 90s could have made it work that way... but it just not how the world works. Maybe COM could have solved thi

Is there a way to stream json?

2021-05-24 Thread treeform
I deal with a large amounts of json. It's bad design to have it all in one file. It's best to have in daily, hourly or even per second files. They are usually compressed too. Moreover, its usually json separated by newlines (line by line as @enthus1ast suggests) so really all you need to do is t

How to read GeoLite2 mmdb files?

2021-05-24 Thread mrhdias
I'm trying to use the c2nim tool to translate the c library to Nim, but it gives an error. Any ideas on how to fix this? $ c2nim maxminddb.h /home/hdias/devel/maxmind/libmaxminddb/main/include/maxminddb.h(90, 50) Error: token expected: ; but got: [identifier] Run

Add total ratings for all Candidates (STAR Voting)

2021-05-24 Thread masiarek2
Add total ratings for all Candidates (STAR Voting). In future this is going to be read from a file... # Voting Simulation: Candidates in file header: A, B, C - "STAR Voting Method" # followed by line items - voter ballots - e.g.: # - first line 0,2,5 (zero star vote for A,

c2nim -- minor update

2021-05-24 Thread gavr
I still don't understand why not use LLVM as in dlang and get perfect parsing of C, C++ and many other languages. Heavy dependency? But c2nim is a separate thing, not a part of the language, and it's not very difficult to get LLVM nowadays.

CPU Benchmark test via Nim-compilation

2021-05-24 Thread inv2004
Thank you for few modern processor. Updated the picture

Is there a way to stream json?

2021-05-24 Thread enthus1ast
Maybe off topic but: if you control the json source, i would go with jsonl (json line by line).

Is there a way to stream json?

2021-05-24 Thread kobi
Hi, I don't know if it's possible to parse json this way, perhaps yielding after every JObject ... Anyway, Is there a library or a way to do that? Some jsons in today's world, are really really huge, and to parse it all beforehand likely eats GB of ram

Accessing object in seq of parent type

2021-05-24 Thread kobi
it's not the way to do it. the types are already "fixed" at compile time. static typing. Maybe you can show us what you're trying to create, and we'll show possible ways to do that.

c2nim -- minor update

2021-05-24 Thread kobi
How does it mesh with interop?

How to read GeoLite2 mmdb files?

2021-05-24 Thread mrhdias
Just starting to Use the MaxMind GeoLite2 does anyone know how to read the content of GeoLite2-*.mmdb files from Nim?

Accessing object in seq of parent type

2021-05-24 Thread xigoi
What you're trying to do is not possible. Nim does not store type information at runtime, except for inheritable objects.

Open file > 2GB on raspi OS 32

2021-05-24 Thread rgorenc
Hi to all, As I'm quite fresh to Nim, having problem to open and read txt files bigger then 2Gb on raspiOS 32 bit. I'm getting response like this: Error: unhandled exception: cannot open: ./big_2.4gb_file.txt [IOError] I had similar problem with Clozure Lisp, 32 bit version that can't open fil

c2nim -- minor update

2021-05-24 Thread mantielero
I know it is my lack of knowledge here, but `c2nim` tend to show errors like: Error: token expected: ; but got: [identifier] Run It would be nice if the error messages were a bit more informative. I think it would be nice if it always produced an output (trying to pro

Accessing object in seq of parent type

2021-05-24 Thread konradmb
> Do not use cast unless you're doing Quake-fast-sqrt level stuff. I know, I'm not sure if `rType()` is possible. > The thing is, you can't make a method that returns the value of each of your > objects, because what would be the return type of such a method? That's why I'm trying to get runtim

Accessing object in seq of parent type

2021-05-24 Thread fengkehh
I would just make your methods all return float: method getValue(this: DigitToken): float = return float(this.value) Run since you don't lose information doing that anyway.

Accessing object in seq of parent type

2021-05-24 Thread xigoi
Do **not** use `cast` unless you're doing Quake-fast-sqrt level stuff. The thing is, you can't make a method that returns the `value` of each of your objects, because what would be the return type of such a method?

cosmonim hello world - No such file or directory

2021-05-24 Thread ggibson
@Yardanico I'm still poking at this - do you have any compiler insights as to how I could introspect why this isn't working on a particular linux distribution?

httpclient request with host different from url

2021-05-24 Thread konradmb
Hmmm, I get only one Host header locally with netcat: POST / HTTP/1.1 Connection: Keep-Alive content-length: 20 content-type: application/json host: other-url.com user-agent: Nim httpclient/1.4.4 {"data":"some text"} Run Code:

Accessing object in seq of parent type

2021-05-24 Thread konradmb
Hmmm, somewhat yes, this would be it. type Token* = ref object of RootRef position*: int DigitToken = ref object of Token value: uint NumberToken = ref object of Token value: float var digits: seq

c2nim -- minor update

2021-05-24 Thread Araq
> Are you still mentally healthy after trying to handle the Most Vexing Parse? Yeah, I'm fine. c2nim always needs more polish but its basic parsing strategy aged really well -- custom preprocessor + parser with backtracking.

Accessing object in seq of parent type

2021-05-24 Thread fengkehh
Have you tried with a value access method? method getValue(this: Token): int {.base.} = echo "interface!" raise method getValue(this: DigitToken): int {.base.} = return this.value Run etc. Haven't tried it myself and since your return ty

Accessing object in seq of parent type

2021-05-24 Thread konradmb
Yeah, sure, but sometimes you can use genericity, like in this case. I've checked how C# behaves, and it spits out runtime type (child one). This code is now more of a thought-experiment, to check if Nim is capable of patterns from OOP, than an actual use-case. I started to hate OOP because of

Accessing object in seq of parent type

2021-05-24 Thread xigoi
What are you even trying to do? If the `value` is sometimes an int and sometimes a float, you'll have to somehow branch your code anyway to handle the different types.

c2nim -- minor update

2021-05-24 Thread geotre
Don't worry, everyone who hā̤̓̍͘s worked on the most vexing pā̤̓̍͘rse is st̲̂̓ͩ̑ill completely sane ā̤̓̍͘nd ɾҽαʅʅყ p̞̈͑̚͞ḣ̖̻͛̓'ṇ̤͛̒̍ĝ̽̓̀͑l̙͖̑̾ͣư̡͕̭̇ỉ͔͖̜͌ ḿ̬̏ͤͅĝ̽̓̀͑l̙͖̑̾ͣw̦̺̐̐͟'ṇ̤͛̒̍ā̤̓̍͘f̵͖̜̉ͅḣ̖̻͛̓ C̵͉͋̔͞t̲̂̓ͩ̑ḣ̖̻͛̓ư̡͕̭̇l̙͖̑̾ͣḣ̖̻͛̓ư̡͕̭̇ R͉̜̎͡͠'l̙͖̑̾ͣy҉̃̀̋̑ẹ̿͋̒̕ḣ̖̻͛̓ w̦̺̐̐͟g

httpclient request with host different from url

2021-05-24 Thread IzidoroBaltazar
How can I route http request through different host? With python requests I can do following: URL = "https://example.com"; headers = {"host": "other-url.com"} res = requests.post(URL, json=body, headers=headers) Run In nim when I try to do similar.

Accessing object in seq of parent type

2021-05-24 Thread konradmb
Oh, you're right! That's what I was missing. C# needs cast too. 😅 Ok, so, can I get the "real" runtime type of this object and cast it programmatically?

CPU Benchmark test via Nim-compilation

2021-05-24 Thread inv2004
Hello, I was thinking about new CPU, found different benchmarks, but decided that the only interesting for me - is it Nim's compilation time. That is why I decided to create couple of scripts which bench just two commands from Nim's repo: `./build_all` and `./koch temp -d:release` Github:

Accessing object in seq of parent type

2021-05-24 Thread xigoi
I tried the equivalent code in C# and it indeed didn't work:

Accessing object in seq of parent type

2021-05-24 Thread xigoi
The seq is of type `Token`, which doesn't have a `value` field. I'm pretty sure the equivalent C# code wouldn't work either.

Nim 2.0 -- thoughts

2021-05-24 Thread SolitudeSF
no

Accessing object in seq of parent type

2021-05-24 Thread konradmb
Hi, I've got this code (: type Token* = ref object of RootRef position*: int DigitToken = ref object of Token value: uint NumberToken = ref object of Token value: float var digits: seq[Token]

c2nim -- minor update

2021-05-24 Thread doofenstein
great, I just threw some headers at it and it required significantly less fixup then previously!

Why union type for proc argument fails to compile?

2021-05-24 Thread shirleyquirk
here's how to get the sugar example to compile. a) turn discard statement into an expression by parenthesizing. b)explicitly specify `log`'s type import sugar proc exec*(message: proc (log: string): void): void = discard exec((log:string) => (discard))

Nim 2.0 -- thoughts

2021-05-24 Thread kragil
I think Nim needs to get bit simpler and feel more familiar for your average programmer. I mean at first it looks like a really simple and easy language, but when you start looking at some more complex examples you soon find cryptic (for the lazy & uninitiated) pragmas and you get demotivated (

c2nim -- minor update

2021-05-24 Thread xigoi
Are you still mentally healthy after trying to handle the Most Vexing Parse?

How to get the compile time as a const string?

2021-05-24 Thread aEverr
There is already a constant with the compile time

How to get the compile time as a const string?

2021-05-24 Thread leeooox
Thanks, this did solved my problem. CompileDate/CompileTime is what I am looking for

How to get the compile time as a const string?

2021-05-24 Thread leeooox
Hi All, I want to record the executable compile time to be hard coded. eg. If the executable is complied on May, 24th. It should be always May, 24th. import times const compileTime = "Release Date : " & $now().format("-MM-dd") Run However, the compiler give an