How do I get the fields/attributes of an object type at run time?

2021-04-15 Thread halloleo
Thanks @Hlaaftana! When I see your change, it is obvious, but I was banging my head against the keyboard instead... And I guess, fieldPairs is exactly what I was looking for!

How to disable logging from db_postgres?

2021-04-15 Thread Araq
> I tried to register void logger, but it won't help The message comes from Postgres itself, not from our Nim wrapper.

How to disable logging from db_postgres?

2021-04-15 Thread alexeypetrushin
The `db_postgres`, see example below, prints `NOTICE` messages, is there a way to disable it, so the output would be clean? The printed message: NOTICE: relation "users" already exists, skipping Run Example that produces it: import db_postgres let d

Generic type parameters and inheritance

2021-04-15 Thread boia01
Here's a working example without refs: type Foo = object of RootObj Bar = object of Foo Baz[T: Foo] = object myAttribute: T # define your own initializer proc initBaz[T: Foo](attr: T): Baz[T] = result.myAttribute = attr

"invalid type ... in this context" error

2021-04-15 Thread dullbananas
I have this in the main module: import ./elm type State = object elmProgram: elm.Program portToElm: elm.SubPort[portMessages.Incoming] # Error is with this function proc newState( elmProgram: elm.Program, ): S

string split by {';'}

2021-04-15 Thread jyapayne
@masiarek2, what @GamzWithJamz is saying is that your string has control characters in it, and indeed no split is occuring, you just have some carriage returns and a newline in your string. You can see that split does nothing by doing this: import strutils var s = "foo\rba

Error: invalid token: trailing underscore

2021-04-15 Thread rb3
I have this problem in my interop library as well. Right now for symbol names like `_Mesh`, I use `$Mesh` in Nim and replace the `$` with `_` for use with the `importcpp` pragma.

string split by {';'}

2021-04-15 Thread masiarek2
I tested a NEGATIVE test case. I was expecting that no split will happen - yet, split does happen unexpectedly ...

string split by {';'}

2021-04-15 Thread GamzWithJamz
If you just echo the string `s` on it's own you will see you get the same output. This is because you have various control sequences in the string which command the terminal to do something other than print a character. The `r` in the string causes a carriage return, meaning the terminal will mo

Generic type parameters and inheritance

2021-04-15 Thread GamzWithJamz
If you remove all `ref` keywords, you cannot use `new` anymore to construct the object, as that requires a `ref` object. Without the `new` keyword, I could not get the object to construct properly as a generic. At a minimum, you need to define `Baz` as a `ref object` and that will work fine.

Generic type parameters and inheritance

2021-04-15 Thread GamzWithJamz
But yes, I misspoke in saying you need `ref` for inheritance. In this case, the child type does need to be a `ref` though.

string split by {';'}

2021-04-15 Thread masiarek2
include prelude var s = "foo\rbar\cbaz\lend" for e in split(s, {';'}): echo e # output: baz end # expected: "foo\rbar\cbaz\lend"

Migrating from v 1.0: "raise effects differ"

2021-04-15 Thread Hlaaftana
The [write](https://nim-lang.org/docs/io.html#write%2CFile%2Cstring) proc in `stdout.write` can raise IOError. Since this error does not inherit Defect, and the library you're using requires the `writer` callback only raise Defects, you have to handle this error or raise it as a Defect.

Generic type parameters and inheritance

2021-04-15 Thread bpr
The following should work. It may not be what you want though, which I believe is 'subtyping in the generic constraints', right? type Foo = object of RootObj Bar = object of Foo Baz[T: Foo | Bar] = object myAttribute: T let baz = Baz[Foo]()

Generic type parameters and inheritance

2021-04-15 Thread Yardanico
You actually don't you need "ref object" with inheritance only for methods, you can inherit objects without "ref" just fine.

Tables and hashes

2021-04-15 Thread timothee
=> PR

Generic type parameters and inheritance

2021-04-15 Thread GamzWithJamz
Also I should add that you need to use `ref object` for object inheritance

Generic type parameters and inheritance

2021-04-15 Thread GamzWithJamz
I have no idea why this fixes it exactly. I had to use the `new(result)` line to create the object rather than a normal object constructor like `Baz[Bar]()`

Generic type parameters and inheritance

2021-04-15 Thread GamzWithJamz
I got your code working by creating a constructor method type Foo = ref object of RootObj Bar = ref object of Foo Baz[T: Foo] = ref object myAttribute: Foo proc newBaz[T: Foo](): Baz[T] = new(result) let baz = Baz[Foo]() # com

Getting started with the Foreign Function Interface - calling library functions

2021-04-15 Thread shirleyquirk
> Yes, that's probably true - I was being lazy and trying to save myself from > typing 150.cuchar - with that set up I could just type 150. I get it, and as you say, probably premature optimization, and given the issue with cuchar it's a bit tricky. I think the best thing, since you're using cv

Generic type parameters and inheritance

2021-04-15 Thread hnicke
Hello nim community! I'm pretty new to programming in nim and so far I pretty much enjoy it. Yesterday I ran into a newbie problem and I bet someone here can help me out. I'm tying to allow a type `Baz` to accept for attribute `myAttribute` all types and subtypes of `Foo`. type

Perceus: Optimized Ref Counting For Koka

2021-04-15 Thread bpr
Koka itself looks interesting, especially the effect system. Thanks for the link! I expect it's not yet a practical programming language, is it? Microsoft has some good PL people, and projects; [F*](https://www.fstar-lang.org/) is another one I like. OCaml is also growing an effect system, ther

Getting started with the Foreign Function Interface - calling library functions

2021-04-15 Thread abudden
> seems crazy to me. 3 words to describe 3bytes? what's the benefit? Yes, that's probably true - I was being lazy and trying to save myself from typing `150.cuchar` \- with that set up I could just type `150`. I hadn't spent any time experimenting to see if it would work with other data sizes as

Getting started with the Foreign Function Interface - calling library functions

2021-04-15 Thread shirleyquirk
type rgbColour* {.bycopy.} = object r*: int g*: int b*: int Run seems crazy to me. 3 words to describe 3bytes? what's the benefit? `std/colors` exists I personally use type Colour = object r*,g*,b*,a*: uint8

Versions 1.4.6 and 1.2.12 released

2021-04-15 Thread treeform
Everyone who worked on this release, Thank you!

winrm fails to build

2021-04-15 Thread gianniperez
Greetings, I've tried building winim using the below nimble command and if fails for some unknown reason atm, please advice- the verbose parameter doesn't really give much info afaik PS C:UsersusernameDownloadswinim> nimble install winim --noSSLCheck --verbose Reading official package list

Migrating from v 1.0: "raise effects differ"

2021-04-15 Thread quokka70
I am coming back to Nim after a while away and am starting by updating my project from v1.0 to 1.4. I have made a few small changes to my code (like changing `strutils.isNilOrWhitespace` to `isEmptyOrWhitespace`) but I'm stuck on another issue. My project uses the chronicles logging library. Wh

Getting started with the Foreign Function Interface - calling library functions

2021-04-15 Thread abudden
Thank you again @shirleyquick \- that's incredibly useful and it feels like it's all making a lot more sense to me now. I've now written a python script that takes advantage of the consistent naming and parses the (well-formed) nim code generated by c2nim and generates a wrapper for some of the

lost thread? (Fastest method for writing and loading cached binary object data to file)

2021-04-15 Thread rockcavera
I was searching for something on the forum these days and a thread also appeared in the search, but this thread was inaccessible (possibly deleted?). Unfortunately, this option to delete threads ends up removing possible aids. The option to delete a thread had to be restricted to administrators,

conditional expressions don't work in a formatted string

2021-04-15 Thread shirleyquirk
please try to break it! i'm sure there's edge cases I haven't found curly brackets can also be used, backslash escaped, so that table/json constructors can be used: import tables,strformat let (foo,bar) = (3,4) assert&"""{ toTable( \{"foo": foo, "bar": bar \} ) }""" == """{

lost thread? (Fastest method for writing and loading cached binary object data to file)

2021-04-15 Thread pietroppeter
You are right, there is indeed a trash button! I never noticed that the author can remove a thread (or a post). I imagine it was the author then that removed the thread.

Idea: Nim Online Conference

2021-04-15 Thread Gendo
Nowadays these online conferences became something normal. I am a little sick of all this online stuff.

lost thread? (Fastest method for writing and loading cached binary object data to file)

2021-04-15 Thread PMunch
Isn't there a delete button on your thread next to the like, flag, and reply buttons? I seem to have one that on my threads..

lost thread? (Fastest method for writing and loading cached binary object data to file)

2021-04-15 Thread pietroppeter
This morning I replied to a thread that seems to have disappeared: subject was "Fastest method for writing and loading cached binary object data to file". You can still see my answer in the search: The thread instead is unreachable:

Versions 1.4.6 and 1.2.12 released

2021-04-15 Thread miran
These are small patch releases for both versions, and we recommend everybody to upgrade.

Creating generic procs with a template

2021-04-15 Thread robertsteven
Can I adjust this template to my design?

Interesting post from D forum

2021-04-15 Thread Araq
It's a probably a good idea and could simplify our type system and compiler. Right now `void` surely is annoying to support in the compiler. :-)

How do I get the fields/attributes of an object type at run time?

2021-04-15 Thread Hlaaftana
`myInfoAttrs` is a runtime address, you cannot use it at compile time (in the static block). You can still create the seq at compile time: import sugar, macros type MyInfo* = object fname*: string cname*: string ctype*: string

Interesting post from D forum

2021-04-15 Thread xigoi
Would it be a problem to make `tuple[]` a discardable type, since it carries no information?

How do I get the fields/attributes of an object type at run time?

2021-04-15 Thread halloleo
I am starting to dabble into type introspection. I have the following test program: import sugar, macros type MyInfo* = object fname*: string cname*: string ctype*: string var myInfoAttrs: seq[string] static:

Fastest method for writing and loading cached binary object data to file

2021-04-15 Thread pietroppeter
This looks like a good use case to try: / Disclaimer: I have not tried using the library

Fastest method for writing and loading cached binary object data to file

2021-04-15 Thread mikkom
Hello, I have a large set of numeric (financial) data that I want to store to disk for caching. I have the original data in text format so it doesn't matter if the cache file is not long-term interoperable if fields of the object are changed. Basically the structure of the data is the following