Learning Nim: Macros and Pattern Matching [video]

2021-03-21 Thread DavidKunz
Thank you for the hint, @nfle, I will keep that in mind next time!

echo () vs echo()

2021-03-21 Thread Yardanico
`echo ()` means "call echo with an empty tuple" `echo()` means "call echo with no arguments"

Learning Nim: Macros and Pattern Matching [video]

2021-03-21 Thread ynfle
Nice video! `return` is generally reserved for an early exit from a proc/func/template/macro and instead assigning to the implicitly initialized `result` variable or implicit return is used.

Nimble download/install sequence improvement

2021-03-21 Thread r3c
Made some mockup [here](https://gist.github.com/JDragan/e53f159c73d4402c8543865e5dc327f9) It downloads the .nimble file and extracts the dependencies. If the package dependencies were in `packages_official.json` it would be a lot faster

Nimble download/install sequence improvement

2021-03-21 Thread cblake
You should look at how [nimp](https://github.com/c-blake/nimp) implements dumpIni/dumpScript. Also fetching just the version control head of `.nimble` will give you today's requires but not yesterday's or last years. Someone should maybe study how dynamic those are over the years.

Learning Nim: Macros and Pattern Matching [video]

2021-03-21 Thread Yardanico
By the way, you can use std/ prefix to import stdlib modules, that way they wouldn't clash with your own modules, like import std/macros # multiple modules import std/[strutils, parseutils] Run

Learning Nim: Macros and Pattern Matching [video]

2021-03-21 Thread DavidKunz
Thanks for the tip, Yardanico, that would have saved me!

Learning Nim: Macros and Pattern Matching [video]

2021-03-21 Thread DavidKunz
This is part 2 of an ongoing series of my efforts to learn the programming language Nim. I give you a quick overview on how to create a simple macro using pattern matching as well as pragmas and reflection functions.

array sample slower than indexing into rand(size-1)

2021-03-21 Thread shirleyquirk
it's that `size` is `const` for i in 0..

echo () vs echo()

2021-03-21 Thread masiarek2
echo () echo() echo () produces this: () () Is it consistent with SOMETHING? We get two pairs of brackets (first and third). Why the middle one (second) is not producing anything? Why is first producing ().

Nimble download/install sequence improvement

2021-03-21 Thread dom96
Yes, this can definitely be done and eventually we should get to a point where it is possible. The only question is deciding how to do it and having someone implement the necessary changes to make it work. An API in nimble.directory (or another service) is a good option to speed up the downloa

How can I quote a type with a sequence of strings

2021-03-21 Thread DavidKunz
Thanks for the hint @ynfle, that looks promising! So many hidden gems in Nim...

How can I quote a type with a sequence of strings

2021-03-21 Thread ynfle
Do you just want to computer something at compile time? You can, alternatively use a `static` expression. Check out the manual [here](https://nim-lang.org/docs/manual.html#statements-and-expressions-static-statementslashexpression).

How can I quote a type with a sequence of strings

2021-03-21 Thread shirleyquirk
since you're not actually manipulating AST with the macro, you probably just want a `static:` block or `const` instead to initialize your somethings

How can I quote a type with a sequence of strings

2021-03-21 Thread DavidKunz
Hi @ynfle, thanks a lot! However, I'd like to create a sequence of `Something` in the macro itself (a loop, creating many `Something` and filling the `manyStrings` property), then in the `quote` I only want to return this sequence, [like this](https://play.nim-lang.org/#ix=2TFi).

How can I quote a type with a sequence of strings

2021-03-21 Thread DavidKunz
Update: Looks like [it works](https://play.nim-lang.org/#ix=2TFi) when I'm using `const` instead.

How can I quote a type with a sequence of strings

2021-03-21 Thread ynfle
Try this:

array sample slower than indexing into rand(size-1)

2021-03-21 Thread HJarausch
In `random.nim`, _sample_ is function which consists of result = a[r.rand(a.low..a.high)] Run So, I think it is the function call overhead which makes the difference, especially since there is no **inline** pragma.

How can I quote a type with a sequence of strings

2021-03-21 Thread DavidKunz
Hi, Consider this code: import macros type Something = object manyStrings: seq[string] macro MyMacro(): untyped = var something = Something() return quote do: `something` let x: Something = MyMacro() # type mismatch: got but expe

array sample slower than indexing into rand(size-1)

2021-03-21 Thread doofenstein
opps right I have similar results, for me it's 0.7 and 0.07 I misread the number by one magnitude haha

array sample slower than indexing into rand(size-1)

2021-03-21 Thread peheje
I am getting even larger difference between sample and rand(size-1) with flto passed to C time taken sample: 1.021981 time taken rand: 0.098158 nim c -r -d=danger --passC:-flto --passC:-ffast-math hue.nim Nim Compiler Version 1.4.4 [MacOSX: amd64]

Norm & Functions

2021-03-21 Thread DavidKunz
I would discourage the second option because it has severe performance penalties for many database rows. Let SQLite do the work and only transfer the relevant data to your app.

array sample slower than indexing into rand(size-1)

2021-03-21 Thread dawkot
Copying the proc into the same file makes the difference go away on my machine.

array sample slower than indexing into rand(size-1)

2021-03-21 Thread peheje
Hi, I am experiencing that the [sample](https://nim-lang.org/docs/random.html#sample%2CopenArray%5BT%5D) function is more than two times slower than manually indexing into rand(size-1): import sequtils import random import times proc main() = const

array sample slower than indexing into rand(size-1)

2021-03-21 Thread doofenstein
I can reproduce the slowness by approximately the same factor. Though when building with lto enabled (--passC:"-flto") sample is for some reason even a bit faster.

Documentation: Method Call Synatx and Inverse Index

2021-03-21 Thread DavidKunz
Absolutely, I just configured autocompletion, works good in some cases. I use the Nim language server together with Neovim's native LSP client lua << EOF require'lspconfig'.nimls.setup{} EOF Run ...but as a Nim beginner I definitely need to read the docs :)

Nimble download/install sequence improvement

2021-03-21 Thread shirleyquirk
that might look something like the crates.io [index](https://github.com/rust-lang/crates.io-index/tree/snapshot-2020-11-20) I cloned a snapshot branch out of interest, it was a 90MB download, `du -h` shows 502MB. this is for ~39k packages. [this article](https://medium.com/@sdboyer/so-you-want

Documentation: Method Call Synatx and Inverse Index

2021-03-21 Thread shirleyquirk
configuring autocomplete in your ide is a better solution, though it'll only show you matching routines from modules you've already imported.

Nimble download/install sequence improvement

2021-03-21 Thread cblake
Sure, sure. Maybe I was unclear. I was mostly thinking about evolution over time where today package A-1.0 requires B>2.0 but tomorrow A-1.1 requires B>2.3. Seems like because of that we'd need a global view of both version & requires.

Nimble download/install sequence improvement

2021-03-21 Thread haxscramper_
To get 100% reliability for parsing `.nimble` it is necessary to have full repo cloned - but that is another topic of having absolutely unconstrained turning-complete language that can easily do _anything_ just when you install the package. Which is the source of major pain regardless, and it wi

Norm & Functions

2021-03-21 Thread moigagoo
Could you please specify what problem you're solving? Do you want to get an average value of a certain column across multiple selected rows? Norm doesn't have an interface for `AVG` yet, feel free to create an issue. PRs are very welcome too! However, there are ways to work around that, with an

Nimble download/install sequence improvement

2021-03-21 Thread cblake
A centralized package index that defers all version/dep metadata to the packages is nice & flexible, but is also costly. Maybe I'm wrong, but as I understand it, you would need to clone each whole repo anyway to get all versions of its `.nimble` file..expensive to build the graph for the whole

Documentation: Method Call Synatx and Inverse Index

2021-03-21 Thread DavidKunz
@shirleyquirk, this is really cool, thanks for the info!

Documentation: Method Call Synatx and Inverse Index

2021-03-21 Thread shirleyquirk
I threw together a poc implementation of this on Rosetta code a while back, if it's actually useful maybe it's worth making a bit more robust.

Norm & Functions

2021-03-21 Thread Clonk
Using `select` will select a Model instance. But you can execute sql queries with `exec` : db.exec(sql"""SELECT col FROM my_table;""" Run

Documentation: Method Call Synatx and Inverse Index

2021-03-21 Thread DavidKunz
Hi, I really love the method call syntax (`obj.meth(args)` instead of `meth(obj, args)`). But I have problems finding the right methods of a particular object in the [index](https://nim-lang.org/docs/theindex.html), therefore my question: Is there an 'inverse' index with methods grouped by obj

Nimble download/install sequence improvement

2021-03-21 Thread haxscramper_
I think so too - it could, and _should_ cache results. And implementing this part of package manager as an API has its own benefits too (like not having to reimplement package manager dependency resolution for tooling that needs to read package dependencies for example). Even more - I did some

Norm & Functions

2021-03-21 Thread DavidKunz
I think he tries to produce a query like this: SELECT avg(col) FROM my_table; Run

Norm & Functions

2021-03-21 Thread Clonk
> I can't see any ways of calling a function when I select What do you mean ? Selecting in Norm is like this : var db = open(dbName, "", "", "") defer: close(db) var modelInstance : ModelType = newModelType() # See readme for Model type definition & initialization db.s

Nimble download/install sequence improvement

2021-03-21 Thread shirleyquirk
Once that manifest has been evaluated, though, couldn't nimble.directory cache the results and provide them over some API? Or am I being naiive and is there no one to one mapping from a package version to a dependency graph, since nimscript. If that's the case then followup question: wtf?