Re: Advent of Nim 2019 megathread
I'm sticking to Nim this year too. [https://github.com/filipux/adventofcode2019](https://github.com/filipux/adventofcode2019)
Re: Me ha encantado El Lenguaje (Nim)
Just wanted to say that Youtube can already do this so it is certainly possible.
Re: How to implement long polling?
Yes, I can confirm it works! Thanks :) I remember now that I tried your ws library before and got it to work. Will check it out again.
How to implement long polling?
How would one implement long polling in a Nim web server? Basically I would like to collect requests in a list and, when some event occurs, return all at once. Non working pseudo code; return all when a client sends the message "shouldReturn": import asynchttpserver, asyncdispatch var server = newAsyncHttpServer() var requests:seq[Request] proc returnAll() = for req in requests: await req.respond(Http200, "Hello World\n") requests.clear() proc cb(req: Request) {.async.} = requests.add(req) if(req.body == "shouldReturn") returnAll() waitFor server.serve(Port(8080), cb) Run
Re: How to use extract string with contains a certain pattern?
Try this import httpClient import xmltree import htmlparser import strtabs var client = newHttpClient() var url = "https://www.instagram.com/p/B1oqkXKFlcD; var htmlsrc = client.getContent(url) let xml = parseHtml(htmlsrc) for meta in xml.findAll("meta"): if meta.attrs.hasKey("property") and meta.attrs["property"] == "og:image": echo "URL: ", meta.attrs["content"] Run
Re: Functional Programming in Nim
I assume you have tried the `sequtils` module from the standard library. Your examples should work with it. My only complaint with sequtils is that the functions don't work with iterators so your code gets sprinkled with toSeq().
Re: Advent of Code 2018 megathread
I know atleast three people who rage quit advent of code this year because of day 15. Day 16 was a lot of fun and I'm currently finding time to work on day 17 but I still have nightmares about goblins and elves :(
Re: Advent of Code 2018 megathread
Thank you, that means a lot :)
Re: Advent of Code 2018 megathread
Here is my repository: [https://github.com/filipux/adventofcode2018](https://github.com/filipux/adventofcode2018)
Re: storing table value in var changes behaviour
Coding in Nim gets easier every day but sometime I still stumble on the basics :) Thank you for your help!
storing table value in var changes behaviour
I have two pieces of code that I expect to produce the same result but they don't. import tables, times var t = initTable[int, seq[Duration]]() t.add(1, @[]) t[1].add(Duration()) echo t Run Result: `{1: @[0 nanoseconds]}` import tables, times var t = initTable[int, seq[Duration]]() t.add(1, @[]) var temp = t[1] temp.add(Duration()) echo t Run Result: `{1: @[]}` Can someone explain why storing a result in a temp variable can change the result like this?
Re: toSeq(countTable.values) doesn't work
You are right and I'm a fool for not providing the whole code. In my original code I imported `nre` and the following can be seen in the documentation for that library: : If you love sequtils.toSeq we have bad news for you. This library doesn't work with it due to documented compiler limitations. Run Thank you :)
toSeq(countTable.values) doesn't work
This works: var counter = initCountTable[char]() for v in counter.values: echo v Run Documentationation says `toSeq()` "transforms any iterator into a sequence" so I would except this to work: var counter = initCountTable[char]() echo toSeq(counter.values) Run Can someone explain why compilation fails with `Error: undeclared field: 'values'`
Re: What does asyncCheck do?
Thanks guys, it all makes sense now.
What does asyncCheck do?
I'm trying to get my head around asynchronous programming and created a simple test program to play around with. The following code compiles and runs but it never seems to reach the "Done waiting" part in the wait procedure and I don't understand why. Is that code never reached because of the asyncCheck in test()? In that case, what does asyncCheck do? proc wait(time:int){.async.} = await sleepAsync(time) echo "Done waiting:", time proc test(){.async.} = while true: asyncCheck wait(1000) waitFor test() Run
Re: Some questions about Nim compiler parameters
Thank you both, this helped alot!
Some questions about Nim compiler parameters
Hi there! Currently I compile my program with > nim c -d:ssl --threads:on app.nim I also have an **{.experimental.}** pragma inside app.nim which I assume could be replaced with another flag to the compiler. Right now I'm a bit confused about these flags and parameters. 1. Is there a pattern for when the parameter to the compiler should have no dash ( **c /compile**) one dash ( **-d:ssl** ) or two dashes ( **\--threads:on** )? 2. Can all these parameters be replaced with pragmas in the code? 3. Is it possible to keep the compiler options in a nim.cfg file? I still haven't found a help section about configuration files that explains what they can do. Thanks
Nim configuration files
Hi there! Currently I compile my program with > nim c -d:ssl --threads:on app.nim I also have an **{.experimental.}** pragma inside app.nim which I assume could be replaced with another flag to the compiler. Right now I'm a bit confused about these flags and parameters. * Is there a pattern for when the parameter to the compiler should have no dash ( **c /compile**) one dash ( **-d:ssl** ) or two dashes ( **\--threads:on** )? * Can all these parameters be replaced with pragmas in the code? * Is it possible to keep the compiler options in a nim.cfg file? I still haven't found a help section about configuration files that explains what they can do. Thanks
Re: Subrange field not initialized
Thank you, your code and comments taught me alot!
Subrange field not initialized
I'm hobby programmer and just started playing around with Nim and so far I'm very happy with it. Unfortunately I got stuck on a problem and can't seem to solve it. I want to add a subrange field to an object with the following code: type Keypad = ref object position: range[1..9] method new(this: type Keypad):Keypad = result = Keypad() result.position = 5 var keypad = Keypad.new() When I run it the compiler complains about "_Error: field not initialized: position_". I tried changing to **position: range[1..9]=5** but then I got "_Error: initialization not allowed here_" instead. What is the recommended way to solve this? (also, is this way of faking a constructor a good solution?)