Re: Struggling with writing an iterator
I have read that before. I don't quite understand all of it in relation to how to write an iterator and call it. However, I went and put back the {.closure.} in my iterator and it works if I call like this: var stream = pricestream for p in stream("oanda", EUR_USD): ... Run What I don't understand is something like this: iterator walkDir*(dir: string; relative=false): tuple[kind: PathComponent, path: string] {. tags: [ReadDirEffect].} = ... when nimvm: for k, v in items(staticWalkDir(dir, relative)): yield (k, v) ... #And walkDir is called just like just like a proc and it contains no {.closure.} for file in walkDir(datapath / source / $instrument / "Prices"): paths.add(file.path) ... Run Thanks for at least getting me working even if lack understanding. I don't understand why the intermediate step of assigning the iterator to a variable and then providing the variable with the parameters. Thanks again.
Re: Struggling with writing an iterator
Looks like you just need a first class iterator. [https://nim-lang.org/docs/manual.html#iterators-and-the-for-statement-first-class-iterators](https://nim-lang.org/docs/manual.html#iterators-and-the-for-statement-first-class-iterators)
Struggling with writing an iterator
I am writing an iterator which calls walkDir and iterates over all of the files in the dir creating objects from those files. I have a proc which reads the file and creates a seq of the objects. It works fine. Amazingly so, on my machine Nim will read one of these files and create almost 400k objects in 40ms. I want an iterator which iterates over each of these files, serving each of its objects one at a time. iterator pricestream*(source: string, instrument: Instrument): Price = ## Iterator for all historic prices for the source, and instrument. var paths: seq[string] for file in walkDir(datapath / source / $instrument / "Prices"): paths.add(file.path) paths.sort(system.cmp[string]) for path in paths: for price in pricesFromCsv(path): yield price # If I call like this: var stream = pricestream("oanda", EUR_USD) for p in stream: ... # I get this: # ntplayground.nim(46, 27) Error: attempting to call undeclared routine: 'pricestream' # If I call like this: var stream = pricestream for p in stream("oanda", EUR_USD): ... # I get this: # ntplayground.nim(47, 18) Error: type mismatch: got # but expected one of: # iterator items[T](a: set[T]): T # ... Run Any help in understanding how to write and call an iterator (this iterator) would be greatly appreciated.
Re: Trouble when splitting in a CLI application
parseopt of course can extract the argument too import parseopt let cmdline = "config create \"a configuration\"" var opt = initOptParser(cmdline) for kind, key, val in opt.getOpt(): case kind of cmdArgument: echo "argument: ", key else: discard Run
Re: Trouble when splitting in a CLI application
Perfect <3
Re: Trouble when splitting in a CLI application
> There is a way using strutils or regex package to split on whitespace but > ignoring space in quoted arguments ? You could use: [https://nim-lang.github.io/Nim/parseopt.html](https://nim-lang.github.io/Nim/parseopt.html)
Re: Trouble when splitting in a CLI application
I dont think it's solve my problem, it's not option with `--my_opt=value` it's more like `cmd args`
Re: Trouble when splitting in a CLI application
Use parseCmdLine()
Re: Nim Advocacy & Promotion Strategies
My bad trying to be sarcastic on the internet. > I don't know what you mean by "wrench code from the hands of open-source > software projects who dare to use proprietary software". You may have noticed that I copied the language from your illustrative non-source and made some replacements: proprietary software owners -> open-source software projects copyright law -> patent/property laws GPL software -> proprietary software My intention was to show that the phrase "to wrench code from the hands of" is not really true and overly dramatic in BOTH cases. Nobody is forced to use GPL code and then suffer consequences, just like nobody is forced to pollute their open-source project e.g. with dependencies to proprietary libraries, which would make it useless to many of its users. > There are 100+ languages more popular than Nim, and many are catching up with > the features, but Nim can have unique selling points they can never compete > on. I frankly don't care that much about Nims popularity, as long as it's big enough to survive and improve. Being relatively small actually helps with swift sweeping moves like the new runtime, and keeps the politics-level low. Nim should be the best it can technologically and not rely on political/legal points. Nobody has a problem with technical quality, but what you think is a big win in the legal/political field could actually turn off other people. > And now the lack of Ehmkeian political correctness witch-hunt drama is an > additional bonus. To be honest, I find both license evangelism and CoC preaching pretty annoying. Keep the politics out of it where possible.
Default path for loading function from dynamic library
Hello given the following function: proc createConfig*(configName: cstring; returnedConfig: ptr ptr Config): ReturnedValue {. cdecl, importc: "createConfig", dynlib: "libalbinos.so".} Run libalbinos.so is installed in /usr/local/lib/libalbinos.so which is in the default search path from gcc. is it possible without switching LD_LIBRARY_PATH=path ./my_app to ./my_app directly ? my library is installed by CMake which choose the path on different system for ubuntu it's will be /usr/local/lib but on fedora for exemple it will be /usr/lib. So i dont want to force the path in the dynlib specifier.
Trouble when splitting in a CLI application
Hello I am doing a CLI (shell-like) application and I have a problem when I split my arguments milerius@inspiron:~/Documents/EIP/albinos/albinos-editor$ LD_LIBRARY_PATH=. ./albinos_editor --cli Usage: help (show this message) exit (quitting the app) clear (clear the screen) config create (create a config with the given name) config load (load config from the key in the given file) setting update (update setting with the given name to the given value) albinos-editor> config create "a configuration" Run In the example above I have a quoted argument. I use the strutils split function to get my arguments in an array. while true: var cline = replxx_input(repl, prompt); if cline == nil: styledEcho(fgMagenta, "Quitting CLI mode...") break let line = $cline if line.len == 0 or isSpaceAscii(line): continue let args = line.unindent.splitWhitespace Run But in fact i get something like ["config", "create", "a", "configuration"] but i want something like ["config", "create", "a configuration"] There is a way using strutils or regex package to split on whitespace but ignoring space in quoted arguments ?
nim-terminaltables
[terminaltables](https://github.com/xmonader/nim-terminaltables) is used to generate terminal tables (ascii or unicode ones) with customizable styles there're some examples in the repo ^_^ Please feel free to open issues or contribute in any suitable way, maybe even better choice for the characters used in the drawing
Re: xmldomparser on frontend - compile to javascript
proc newDOMParser(): JsObject {.importcpp:"new DOMParser()", nodecl.} proc fetchEPG(): void {.async.} = var res = await fetchText("/epg.xml") var parser = newDOMParser(); var xmlDoc = parser.parseFromString(res,"text/xml"); log xmlDoc EPG = xmlDoc Run Then you can do something like: EPG.getElementsByTagName("programme") Run
Re: xmldomparser on frontend - compile to javascript
OK, xmldomparser use stream and streams are not available for JS backend. htmlparser library too. How I can parse xml on frontend in nim with compile js? thanks
Re: xmldomparser on frontend - compile to javascript
nim -v Nim Compiler Version 0.19.9 [Linux: amd64] Compiled at 2019-05-18 Copyright (c) 2006-2019 by Andreas Rumpf active boot switches: -d:release
Re: xmldomparser on frontend - compile to javascript
>From `streams.nim`: when not defined(js): type StringStream* = ref StringStreamObj ## A stream that encapsulates a string. ## ## **Note:** Not available for JS backend. # (...) proc newStringStream*(s: string = ""): owned StringStream = ## Creates a new stream from the string `s`. ## ## **Note:** Not available for JS backend. Run
wNim fork with ZeeGrid control
I forked wNim and added the Zeegrid control if anyone is interested. > ZeeGrid is created by by David Hillard > ([http://www.kycsepp.com/](http://www.kycsepp.com/)) GitHub link: [https://github.com/bunkford/wNim](https://github.com/bunkford/wNim) Documentation: [https://bunkford.github.io/wNim/wZeeGrid.html](https://bunkford.github.io/wNim/wZeeGrid.html)
Re: Shared library for Android
Hi Sergey! If you have Android NDK installed, it should be possible. I did this for a simple "hello world" app, see: [https://github.com/akavel/hellomello/#build-steps](https://github.com/akavel/hellomello/#build-steps) (part of a [bigger project](https://forum.nim-lang.org/t/4840)). Also, another recent thread about cross-compilation may prove helpful to you: [https://forum.nim-lang.org/t/4845](https://forum.nim-lang.org/t/4845). Hope it helps!
Re: method call syntax for more than one argument?
You can probably use a `forth` macro that would do: forth: c.b.a.f Run
Re: I think we can really do better...
I actually think it's easier to optimize Nim for scientific computing like I did for the Julia challenge: [https://nextjournal.com/sdanisch/the-julia-challenge](https://nextjournal.com/sdanisch/the-julia-challenge) For example my [matmul implementation](https://github.com/numforge/laser/blob/bf751f4bbec3d178cd3a80da73e446658d0f8dff/benchmarks/gemm/gemm_bench_float32.nim#L418-L465) would be as fast as Julia Native Threads in [Kostya's matmul benchmark](https://github.com/kostya/benchmarks#matmul) (Julia Native Threads uses the OpenBLAS library written in assembly in backend).
Re: xmldomparser on frontend - compile to javascript
What is your nim compiler version ? (`nim -v`)
Re: Disadvantages of static proc parameters?
In that case ^ is a library function and will be in a different module from where it's used. So you need either `static` or `{.inline.}` so that respectively Nim VM or the C compiler does constant folding. Also while C compilers certainly does constant propagation of add, mul, or/and/xor, shifts, I'm not sure they do that for the power function.
method call syntax for more than one argument?
You know how a.f is equivalent to f(a)? Would it be possible, using macros, to write b.a.f to represent f(a,b), or c.b.a.f to represent f(a,b,c), and so on for any number of arguments? (It makes sense to do b.a.f instead of a.b.f because doing the former is like partially applying f to a, and then applying b to that.) Essentially you could call functions Forth-style by putting the arguments before the function.
Re: Is there a 'protected' or module-local scope modifier?
I still need to export the types and I'm not going to create another layer of wrappers just for that. This is not about fool-proofing but about not exposing the internal state for no reason.
xmldomparser on frontend - compile to javascript
Hello, why I parse xml (or html) on frontned. If I compile module which import _xmldomparser_ # main.nim from xmldomparser import loadXML ... Run and compile it into javascript _nim js main.nim_ I get this error **~ /.nimble/pkgs/xmldomparser-0.1.0/xmldomparser.nim(145, 11) Error: undeclared identifier: 'newStringStream'** thanks
Re: I think we can really do better...
> But I would say that your suggested text is also too long. Yes, I was indeed struggling with the text length, but I was not able to make it shorter without leaving important topics out. The text does not fit on a single page unfortunately, but it can be read very fast. For my personal task I would like to see a text in such a form on the first page, because it gives a complete overview. But I have noticed that most programming language pages have nearly no informative text on the first page, but a link called something like "What is Nim". Maybe that is indeed the better solution, and it may work better for mobile.