Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Apr 04 2021 12:26
    @dom96 banned @acroobat
  • Mar 03 2017 15:52
    @dom96 banned @Octopoda7
  • Feb 12 2017 23:57
    @dom96 banned @zzz125
  • Dec 23 2016 19:43
    @dom96 banned @Izrab
Elegantbeef
@elegantbeef:matrix.org
[m]
func isObject*[T](val: typedesc[T]): bool = T is (object or ref object)

echo int.isObject
That's valid
And it is the same as echo static(int.isObject)
Isofruit#5120
@_discord_180601887916163073:t2bot.io
[m]
squint but how do I know that this is compiletime when I absolutely positively want it to be compiletime
Elegantbeef
@elegantbeef:matrix.org
[m]
You look at the code you're running and if it's 100% static it's the compiler will do it at compile time
Plus in Nim types only exist at compile time
Ah shit i'm wrong 😄
T2_ = isObject__test50_6(); oh noes a call to return false!
Isofruit#5120
@_discord_180601887916163073:t2bot.io
[m]
But even if it doesn't do stuff, having the compiletime annotation gives me the ability to communicate that I intentionally want this thing to be compile-time and not that it's a happenstance that it's compiletime
Elegantbeef
@elegantbeef:matrix.org
[m]
Eh you do you
I dont see that as a benefit really
Isofruit#5120
@_discord_180601887916163073:t2bot.io
[m]
And given that I have the memory of a very wise goldfish (meaning stuff sticks around my head for 5 days instead of 5 minutes) I need to plan ahead to communicate with future me
Elegantbeef
@elegantbeef:matrix.org
[m]
It's surprising that Nim doesnt statically evaluate this though
given that it statically evaluates other things
Like
const str = ""
if str[0] == 'a':
  ##
Compile time error
I guess the difference is the procedure could do stuff at runtime as such it needs it
Forest#2913
@_discord_909883978717204561:t2bot.io
[m]
Yeah can't figure out how to fix this, did a bit of tinkering for the last 30 or so minutes, and every time it's either a coloured pic of the mask, or a flat coloured pic https://hastebin.com/ubalilipeg.nim
Elegantbeef
@elegantbeef:matrix.org
[m]
So in the case you turned that into a template isObject(a: typedesc): bool = a is (object or ref object) you'd get static evaluation
Isofruit#5120
@_discord_180601887916163073:t2bot.io
[m]
That mostly just loses out to my general rule to use a proc when a proc can do it and only a template when a proc makes no sense.
And evaluating A to B is a perfect proc usecase
MagneticSpark#5831
@_discord_145348808417607680:t2bot.io
[m]
I started learning nim today, and I noticed there were multiple vscode extensions available. One of them has more downloads, but it's not the one linked in the official "Nim basics tutorial". Which one is the "official"?
huantian#4880
@_discord_300050030923087872:t2bot.io
[m]
Then one by saem
MagneticSpark#5831
@_discord_145348808417607680:t2bot.io
[m]
Ok, I'll get that one then, thanks!
dom96#7486
@_discord_132595483838251008:t2bot.io
[m]
There is no "official" one
only different preferences among the Nim devs
Generic#5192
@_discord_249581140363575297:t2bot.io
[m]
the developement on the pragmatic one is basically dead though
and the other one/s are iirc mostly oriented around PMunch's lsp server
so for most people it's definitely the best choice
(full disclosure I was a contributor to the pragmatic one until it died and made since then several PRs to the saem one)
dom96#7486
@_discord_132595483838251008:t2bot.io
[m]
I don't need much to be happy: just syntax highlighting really. Everything else just gets in my way, so the pragmatic one is just fine
Generic#5192
@_discord_249581140363575297:t2bot.io
[m]
the saem one has even a few fixes for that
dom96#7486
@_discord_132595483838251008:t2bot.io
[m]
what other features do you use?
Generic#5192
@_discord_249581140363575297:t2bot.io
[m]
I use nimsuggest in smaller projects and linting via nim check
both also received fixes in the saem extension
Isofruit#5120
@_discord_180601887916163073:t2bot.io
[m]
Is there a way I can say "accept an object, but not one with inheritance"?
2 replies
For a generic proc param
Rainbow Asteroids#8788
@_discord_250376950147842048:t2bot.io
[m]
why?
1 reply
Avahe#7555
@_discord_778498877464117248:t2bot.io
[m]

Forest (@_discord_909883978717204561:t2bot.io)

import pixie

let
  image: Image = readImage "./sheep.png"
  mask: Image = readImage "./mask.png"

var color = parseHtmlColor("#86F0E5").rgba
color.a = 100

mask.fill(color)
image.draw(mask, blendMode = ColorBlend)

image.writeFile "test.png"

Maybe something like this? Then remove the black color from mask.png, make it transparent, and it'll only apply color to the sheep

1 reply
You don't need to set the alpha if you don't want to, either
Isofruit#5120
@_discord_180601887916163073:t2bot.io
[m]
As in, I'm relying on the columns on row to be in the order of the fields on the type
Like, first field on the type is to be filled with the first column of data on the row
Forest#2913
@_discord_909883978717204561:t2bot.io
[m]
Simpler*
Thanks!
Avahe#7555
@_discord_778498877464117248:t2bot.io
[m]
No prob 🙂
Avahe#7555
@_discord_778498877464117248:t2bot.io
[m]
I have a bit of duplicate code I'm hoping I could reduce using templates (maybe will require a macro, hoping not): https://play.nim-lang.org/#ix=47ll
Basically, I'm doing the same exact thing as this function but with "height" instead of "width". The only thing that really needs to happen, in substituting out child.width for child.height. Is there a simple way to sub out those calls with a template or something?
1 reply
Elegantbeef
@elegantbeef:matrix.org
[m]
https://github.com/beef331/oopsie/blob/master/src/oopsie.nim#L11-L33 i think works, dont recall how tested it is
Isofruit#5120
@_discord_180601887916163073:t2bot.io
[m]
Nice to know! Thanks!
Elegantbeef
@elegantbeef:matrix.org
[m]
You used a template and the world was better
Avahe#7555
@_discord_778498877464117248:t2bot.io
[m]
Yeah, was trying to the whole time, but took me a bit to figure out how
Well, I used a template inside a proc