by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Mar 03 2017 15:52
    @dom96 banned @Octopoda7
  • Feb 12 2017 23:57
    @dom96 banned @zzz125
  • Dec 23 2016 19:43
    @dom96 banned @Izrab
Vindaar
@Vindaar
If you have some code you want to produce from what kind of input, I
I'm happy to try to help
From IRC (bridge bot)
@FromIRC
<miran> ok, let me make an example, just a sec
<TheLemonMan> don't forget about "quote"
Vindaar
@Vindaar
good point, that's even more useful :)
From IRC (bridge bot)
@FromIRC
<miran> under the line is what i'm trying to do curently
<miran> TheLemonMan: i have seen quote do here and there, but haven't used/understood it yet
Vindaar
@Vindaar
quote do basically allows you to write normal Nim code and have that converted to the NimNode representation
From IRC (bridge bot)
@FromIRC
<TheLemonMan> yeah, but it allows you to plug various pieces (NimNodes) from the outer scope
Mamy Ratsimbazafy
@mratsim
think of it as interpolating compile-time with run-time
just like &”My fixed and {interpolated} string"
Vindaar
@Vindaar
hehe, I should let smarter people than me talk :D
miran: I assume that Shape and the kind enum would already be defined, yes?
From IRC (bridge bot)
@FromIRC
<miran> yes, they are defined, as is calcArea proc
From IRC (bridge bot)
@FromIRC
<miran> i did this in my macro: http://ix.io/1mpn and a is IntLit - don't know how to pass that to a proc which creates an instance of Shape, there is no IntLit type!?
Vindaar
@Vindaar
using quote do, something like what you did there and a lot of hardcoded things (:P), you can do something like this: http://ix.io/1mps/nim
From IRC (bridge bot)
@FromIRC
<miran> thanks @Vindaar! from a quick look, it seems like toNimIdent is what i need
<miran> and it seems this quote do is something i really need to start using :⁠)
Vindaar
@Vindaar
yes, it's really helpful
From IRC (bridge bot)
@FromIRC
<miran> OMG, this quote do is magic!!
<miran> sorry dumpAstGen, i now have a new best friend!
Kaushal Modi
@kaushalmodi
miran: Please enlighten with a blog post or something :)
I need to bookmark this conversation for now
From IRC (bridge bot)
@FromIRC
<miran> @kaushalmodi: once i get more familiar with it — i'll do it
Vindaar
@Vindaar
and it's good to keep in mind that you can just define compile time procs, which handle certain parts of the code you construct by having them work on NimNode. e.g. refactoring the above to: http://ix.io/1mpu/nim
From IRC (bridge bot)
@FromIRC
<miran> i'll post my coplete code when i finish it, so y'all can take a look (and give me advice what to change :⁠))
Vindaar
@Vindaar
:)
From IRC (bridge bot)
@FromIRC
<miran> i managed to do it!!! wooohooo!
<miran> @Vindaar thank you very much for the example, it was very helpful!
Vindaar
@Vindaar
cool, glad I could be of service :D
From IRC (bridge bot)
@FromIRC
<miran> here it is: http://ix.io/1mpv/
<miran> and with some comments to see what each proc does: http://ix.io/1mpw/
Vindaar
@Vindaar
nice!
From IRC (bridge bot)
@FromIRC
<miran> procs were created with dumpAstGen, don't know if this was the way to go, or there is some simpler way to do these things
Vindaar
@Vindaar
and the types defined like this make a lot more sense :D
dm1try
@dm1try

this is a minimum reproducable example without dependencies to see what I mean with leaks: https://gist.github.com/tim-st/30eb88b2a96fdd77623be945dff5fc2a

yep, I'm playing around with this code and notice that on every request there is at least 3 allocations for response body (each of them ~equal a body size) and the memory only for 2 of 3 allocations is deallocated later

used logAlloc = true and call GC_full_collect before each request
razuit
@razuit
is it possible to import a const with .importc? Looking at importing a const from a C .h header file without redefining it
Mamy Ratsimbazafy
@mratsim
yes but only as a var
Ghost
@ghost~5a1ecef8d73408ce4f80e118
@dm1try very good catch, exactly my feeling when I recognized it had the same ram grow curve like no gc at all
I tried GC_full_collect already didnt change
razuit
@razuit
@mratsim how would that look like?
Mamy Ratsimbazafy
@mratsim
var foo {.importc “Cname”, header: “path/to/header.h”.}
Daniel Sokil
@s0kil

Hello, What is a good example of when to use reference types vs non-reference types?

Here is a non-ref object:

type
    Person = object
        name: string
        age: int

var person: Person
person.name = "Daniel"

Here is a ref object:

type
    PersonObj = object
        name: string
        age: int
    PersonRef = ref PersonObj # reference type

proc setName(name: string, person: PersonRef) =
    person.name = name

var person1 = PersonRef()
setName("Daniel", person1)

Why should I use one over the other? They both seem to be achieving the same thing.
Since ref object is live on the heap, and non-ref is on the stack, Is that the only difference?

E. P. Morgan
@glassofethanol_twitter
So ref allocates heap storage?
Daniel Sokil
@s0kil
"Traced references point to objects of a garbage collected heap, ..."
https://nim-lang.org/docs/manual.html#types-reference-and-pointer-types
E. P. Morgan
@glassofethanol_twitter
Ah I see
Vindaar
@Vindaar
@DanielSokil aside from potential performance differences, it makes a big difference regarding mutability of the underlying object
Daniel Sokil
@s0kil
@Vindaar Could you please further explain what you mean by: "mutability of the underlying object"?
Luke Parker
@kayabaNerve
If I pass an object from A to B and alter it in B, the one in A is also altered