ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.31.1 | Fund Crystal's development: http://is.gd/X7PRtI | GH: https://github.com/crystal-lang/crystal | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/ | Gitter: https://gitter.im/crystal-lang/crystal
dostoyevsky has quit [Quit: leaving]
dostoyevsky has joined #crystal-lang
<FromGitter> <sam0x17> @Daniel-Worrall was that while running `shards install`? I've experienced that before on alpine with specific sets of shards, haven't gotten around to reporting it yet
dostoyevsky has quit [Quit: leaving]
dostoyevsky has joined #crystal-lang
dostoyevsky has quit [Quit: leaving]
dostoyevsky has joined #crystal-lang
dostoyevsky has quit [Client Quit]
dostoyevsky has joined #crystal-lang
alex``` has quit [Ping timeout: 252 seconds]
dostoyevsky has quit [Quit: leaving]
dostoyevsky has joined #crystal-lang
alexherbo2 has joined #crystal-lang
alexherbo2 is now known as alex```
alex``` has quit [Ping timeout: 250 seconds]
Vexatos has quit [Quit: ZNC Quit]
Vexatos has joined #crystal-lang
teardown has quit [Quit: leaving]
Raimondi has quit [Read error: No route to host]
Raimondi has joined #crystal-lang
Raimondi has quit [Read error: No route to host]
Raimondi has joined #crystal-lang
DTZUZO has joined #crystal-lang
Raimondi has quit [Ping timeout: 240 seconds]
Raimondi has joined #crystal-lang
chachasmooth_ has quit [Ping timeout: 246 seconds]
chachasmooth has joined #crystal-lang
f1reflyylmao has joined #crystal-lang
f1refly has quit [Ping timeout: 246 seconds]
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 264 seconds]
Raimondii is now known as Raimondi
return0e has joined #crystal-lang
return0e_ has quit [Read error: Connection reset by peer]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Remote host closed the connection]
_whitelogger has joined #crystal-lang
<FromGitter> <Souravgoswami> ```code paste, see link``` ⏎ ⏎ @Daniel-Worrall , same problem here. When that issue is raised, I just disable the GC for the time being before assigning a very large array, then I reenable it, which doesn't cause memory leaks if you are aware of what you ar doing... [https://gitter.im/crystal-lang/crystal?at=5dd0f28e4adf071a84443bf2]
return0e has quit [Read error: Connection reset by peer]
return0e has joined #crystal-lang
early has quit [Quit: Leaving]
early has joined #crystal-lang
alex``` has joined #crystal-lang
Stephie is now known as Stephanie
Stephanie is now known as Stephie
alex```0 has joined #crystal-lang
alex``` has quit [Ping timeout: 240 seconds]
<blassin> can I write a macro that takes a number n and returns `LibNCurses::Attribute::ColorPair{{n}}` ?
<blassin> if so, how? I tried, but the number I pass in a variable gets expanded to `LibNCurses::Attribute::ColorPairindex`
<hightower2> Btw, what project are you working on blassin? Anything already available publicly?
<blassin> not yet ;) it's a Z-Machine interpreter
<blassin> my Grand Project is to make a "Learn Crystal ebook by writing an emulator" ebook or something
<blassin> and learn while doing it, too
<blassin> * I meant "Learn Crystal by writing an emulator" ebook
<blassin> never wrote a macro before, though, and the docs are a bit sparse
<hightower2> What's the call you would like to call normally, if it wasn't a macro?
<blassin> the NCurses bindings need to specify color pairs as `LibNCurses::Atrribute::ColorPair1` (1,2,3... up to 255)
<blassin> so I want to replace having to call `LibNCurses::Attribute::ColorPair1` with `color_pair(1)`
<hightower2> Yeah the basic variant would be just macro(n) LibNCurses::Attribute::ColorPair{{n}} end . I think you already have this, right?
<blassin> yeah, I have ` macro color_pair(number)
<blassin> end`
<blassin> LibNCurses::Attribute::ColorPair{{number}}
<blassin> but when I call it with `color_pair(index)` I get `Error: undefined constant LibNCurses::Attribute::ColorPairindex`
<blassin> (index is a var holding the number)
<hightower2> You get literal word "index" printed?
<hightower2> or undefined constant LibNCurses::Attribute::ColorPair1 ?
<blassin> on the error message, yeah - no such color pair exists, so it bombs out
<blassin> `Error: undefined constant LibNCurses::Attribute::ColorPairindex`
<blassin> I'd like it interpret the index var before running the macro
Nekka_ has joined #crystal-lang
Nekka has quit [Read error: Connection reset by peer]
Nekka_ is now known as Nekka
<hightower2> so this works per-se . Now just the issue is your specific use of this
<hightower2> are you calling this macro from regular code or another macro?
<blassin> that outputs a string, not the constant right?
<hightower2> No it's a constant, you see the quotes just because I used "p" to print it, which inspects the value
<blassin> oh ok
<FromGitter> <AmberSaber> /usr/local/Cellar/llvm/9.0.0_1: 6,839 files, 3.7GB, built in 295 minutes 9 seconds
<hightower2> (and because I enclosed the string in quotes manually, as you see in the macro)
<hightower2> are you calling this macro from regular code or another macro?
<blassin> regular code
<blassin> but it's giving me a string and not a constant
<blassin> `Error: instance variable '@colors' of Zircon::VideoCard::Window must be LibNCurses::Attribute, not String`
<hightower2> You have another mistake somewhere which is causing this, i.e. it's not caused by the macro functionality
<hightower2> Macro will literally insert the macro text in the position where you call it
<hightower2> Can you show more code? (Ideally something that you extract and paste on https://play.crystal-lang.org/ )
<blassin> I'll try
<hightower2> also try showing us how your @colors = (or any line where you define value of @colors) looks like
<hightower2> Also from your description, if the ncurses bindings don't have a method which gives you the color pair based on index (i.e. if they don't have some method like #color_pair_from_index(n)), then you might get this working by creating an array of 256 values, and then just looking up that array yourself
<blassin> my exact error
<hightower2> ah yes, you can't call macros in runtime.. they are expanded at compile time. You can solve this with the idea from above, which is that instead of an Enum you can build an array of 256 elements
<hightower2> and then just the index in the array is the color pair you want
<blassin> thing is, the color pairs are created at runtime, right? I do `LibNCurses.init_pair(1, black, blue)` (black and blue are Ints)
<blassin> so if I build them at runtime... I'm confused
<blassin> they're not preset on nCurses, I define them myself
<blassin> the lib just has 256 slots for them
<hightower2> so that's even simpler then
<hightower2> so calling LibNCurses.init_pair(1, black, blue) will give you the right pair in runtime, but you just want to have them pre-created once you decide what the color pairs need to be?
<blassin> I have preset pairs - one for the game window, one for the debug window, one for CPU logger messages, etc
<blassin> I just want to refer to them at runtime when I created the proper windows / strings, etc
<blassin> *create
<hightower2> right... so you don't need macros at all I would say.. Just use an array in which you add pairs, and when you want to look them up by index, just do a lookup in the array
<hightower2> Does that seem workable?
<blassin> but the lib needs me to pass `LibNCurses::Atrribute::ColorPair1` which is a constant
<blassin> should I have all constants I use in an array?
<blassin> seems... verbose :D
<blassin> but I guess it makes sense - the macro runs at compile time, right?
<blassin> not runtime
<hightower2> yes
<hightower2> unless you can somehow bind to the constants in C, you need to copy them over
<blassin> what if I have a macro to build my array at compile time?
<blassin> then I don't have to be so verbose
<blassin> argh, the macro can't access instance vars of course
<blassin> oh well, verbose it is :|
<blassin> thanks anyway, hightower2
<blassin> hightower2: my final solution https://carc.in/#/r/818t
<FromGitter> <Daniel-Worrall> @sam0x17 @Souravgoswami
<FromGitter> <Daniel-Worrall> The alpine docker uses edge which ships with shards 0.9.0 which is resolved in master having tested building it myself. The best way yo avoid it is by more granularly specifying your versions as it is failing when checking for conflicts.
<FromGitter> <Blacksmoke16> blassin: what was the goal there?
<blassin> to which do you refer?
<FromGitter> <Blacksmoke16> with that carc.in link
<blassin> I wanted to use the index from `#each_with_index` to somehow magically create the `LibNCurses::Atrribute::ColorPair{index}` and not have it on the hash "by hand"
<blassin> I meant "refer to" instead of "create" the color pair constant
<blassin> since LibNCurses already creates them with a macro
<blassin> but that can't be done at compile time, my bad :|
<blassin> so verbose it is
<FromGitter> <Blacksmoke16> yea using a macro at runtime doesnt work
<blassin> yeah, it'd be cool to somehow be able to refer to it, but I guess it's my Ruby brain talking here :D
<blassin> I get I could maybe make a CONSTANT with the colors at compile time and save time there
<blassin> but meh
<blassin> if I had 200 pairs I'd invest more iin uit
<blassin> *in it
<hightower4> Well, there is. You could use a macro which populates you an array of 256 elements, each referring to one cosntant. And then you access them by array index.
<hightower4> Or alternatively you can just check what the values of those constants are
<blassin> yeah, I'm building it now as an instance var but I could do that
<FromGitter> <Blacksmoke16> could prob add a method to the enum
<blassin> for sure the bindings could be a bit friendlier
<blassin> I've opened a PR on them, maybe I can open more in the future when I optimize the code a bit more
_whitelogger has joined #crystal-lang
<hightower4> Do I see it right that procs can't have default values for arguments?
<FromGitter> <Blacksmoke16> i think thats right yea
<hightower4> That's interesting, do we know what the technical reason is?
DTZUZO has quit [Ping timeout: 240 seconds]
ht_ has joined #crystal-lang
DTZUZO has joined #crystal-lang
<hightower4> Hey give me some general idea here... Basically, I would need to produce Procs from string definitions in runtime.
<hightower4> I could of course have just one proc that always runs, parses the string, and does what is instructed.
<hightower4> But I'd prefer to write some meta function which produces optimized Procs that correspond to each string definition specifically.
<FromGitter> <Blacksmoke16> got an example?
<hightower4> Yes,for example "start %p1%d end" should convert to a ->(args : Array(String|Int|Bool)) { print "start"; out = [] of String; out.push arg[1]; print(out.join ""); print "end"; }
<hightower4> And the logic (triggered by %'s) can be from simple (pushing/popping arguments from stack) to more advanced (conditionals, comparisons, etc.)
<hightower4> Such as, %?...%t...%e...% would be an example of an if with then(t) and else(e) parts
ht_ has quit [Remote host closed the connection]
ht_ has joined #crystal-lang
<FromGitter> <didactic-drunk> @Blacksmoke16 Can you tell how many references there are to a variable within a macro? I think i'm looking for something rustish.
<FromGitter> <phangs> @Blacksmoke16 may I ask for help, I followed your tutorial here https://dev.to/blacksmoke16/creating-a-json-api-with-athena--granite-510i
<FromGitter> <phangs> manually followed the steps as well as cloned the github source, but both had same error, In src/blog.cr:2:1 ⏎ ⏎ 2 | Granite::Adapters << Granite::Adapter::Pg.new({name: "my_blog", url: "postgres://dbadmin:password@localhost:5432/blog?currentSchema=blog"}) ⏎ ⏎ ``` ^----------------``` ... [https://gitter.im/crystal-lang/crystal?at=5dd177d25eb2e813db400b5d]
<FromGitter> <phangs> tried googling for the error and tried using master branches, still to no avail
<FromGitter> <Blacksmoke16> new version of granite had some breaking changes @phangs see https://github.com/amberframework/granite/releases/tag/v0.17.0
<FromGitter> <Blacksmoke16> @didactic-drunk like a local variable? if so, then no
<FromGitter> <didactic-drunk> @Blacksmoke16 I'm trying to optimize for a case where ownership is unique to avoid locking. It must be unique across functions, instance variables, constants, etc. It's fine if it's passed off to a function as long as the ownership remains unique.
<FromGitter> <Blacksmoke16> hmm
<FromGitter> <Blacksmoke16> dunno
Flipez0 has joined #crystal-lang
Flipez has quit [Read error: Connection reset by peer]
dannyAAM has quit [Quit: znc.saru.moe : ZNC 1.6.2 - http://znc.in]
dannyAAM has joined #crystal-lang
alex```0 has quit [Read error: Connection reset by peer]
alex```0 has joined #crystal-lang
alex```0 has quit [Quit: The Lounge - https://thelounge.chat]
ht_ has quit [Remote host closed the connection]
alexherbo2 has joined #crystal-lang