RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.21.0 | Fund Crystal's development: http://is.gd/X7PRtI | Paste > 3 lines of text to https://gist.github.com | GH: https://github.com/crystal-lang/crystal | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/ | Logs: http://irclog.whitequark.org/crystal-lang
<jabb> for the sake of style, would you say control should be CTRL or Ctrl?
<jabb> IF i were to shorten it
<Papierkorb> Shorten for what? For e.g. showing a key combo in a help page?
<jabb> for code
<jabb> enumeration
<Papierkorb> so an identifier for use in code?
<jabb> yes
<Papierkorb> CTRL would indicate to most an abbreviation (with each character meaning a whole word), which CTRL is not, so Ctrl.
<Papierkorb> or `ctrl` if it's a method or variable
<jabb> thats what i was thinking
<Papierkorb> Though I'd never use CTRL, for me it'd be `Ctrl` even if every char would expand to a whole word, never liked that style
soveran has quit [Remote host closed the connection]
<jabb> can you have uninitialized struct data
<jabb> "property x = uninitialized Int32"
elia has quit [Quit: Computer has gone to sleep.]
<Papierkorb> No
<Papierkorb> (Or, it would surprise me)
<Papierkorb> jabb: What do you need it for?
<jabb> delayed initialization
<jabb> if it's a fairly large struct it would just be a gigantic new() call
<Papierkorb> Use the yielding version of the `getter` macro: `getter expensive : Int32 do 1 + 2 end` will call the block once on-demand, and memoize the value
<Papierkorb> Or, use nilable values
<Papierkorb> You can use `property!` to build a non-nil getter
<Papierkorb> Well, `getter!` exists too
zaiste has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
snsei has joined #crystal-lang
<sija> @jabb actually you can, although it'll not work with `property/getter/setter` macros
<jabb> sija: how do you do it?
<sija> `@x = uninitialized Int32`
<jabb> what's the purpose of a propery macro?
<jabb> why not just use @x?
<sija> these macros create methods to access such variable
<jabb> i thought you can access instance variables already
<sija> not outside of the class, no (except undocumented and test-only foo.@x notation)
<sija> you can declare @x as uninitialized in constructor too
soveran has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Changing host]
<jabb> sija, thanks
<jabb> also, how do i cast an int to an enum?
<jabb> i have enum Foo : UInt8, and i have a variable x : UInt8
<sija> Foo.new(x)
<jabb> gotcha, just saw that
<jabb> ty
<sija> cheers
soveran has quit [Ping timeout: 260 seconds]
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
pawnbox has joined #crystal-lang
<jabb> instead of asserting, just raise?
pawnbox has quit [Ping timeout: 255 seconds]
<crystal-gh> [crystal] kostya opened pull request #4081: use GC.malloc_atomic to allocate objects without pointers (master...gc_atomic) https://git.io/vykfu
bjz has joined #crystal-lang
snsei has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
pawnbox has quit [Ping timeout: 260 seconds]
soveran has joined #crystal-lang
soveran has quit [Ping timeout: 260 seconds]
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
pawnbox has joined #crystal-lang
pawnbox has quit [Ping timeout: 240 seconds]
pawnbox has joined #crystal-lang
pawnbox has quit [Ping timeout: 240 seconds]
bjz has joined #crystal-lang
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
bjz_ has joined #crystal-lang
bjz has quit [Ping timeout: 268 seconds]
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
kellabyte_ has joined #crystal-lang
avdi_ has joined #crystal-lang
kiliankoe_ has joined #crystal-lang
pabs__ has joined #crystal-lang
jsaak has joined #crystal-lang
tilpner_ has joined #crystal-lang
mjblack- has joined #crystal-lang
leex_ has joined #crystal-lang
kellabyte has quit [Ping timeout: 252 seconds]
avdi has quit [Ping timeout: 252 seconds]
kiliankoe has quit [Ping timeout: 252 seconds]
pabs has quit [Ping timeout: 252 seconds]
mjblack has quit [Ping timeout: 252 seconds]
jsaak_ has quit [Ping timeout: 252 seconds]
wmoxam has quit [Ping timeout: 252 seconds]
leex has quit [Remote host closed the connection]
mjblack- is now known as mjblack
wmoxam has joined #crystal-lang
kiliankoe_ is now known as kiliankoe
kellabyte_ is now known as kellabyte
avdi_ is now known as avdi
tilpner has quit [Ping timeout: 252 seconds]
tilpner_ is now known as tilpner
soveran has joined #crystal-lang
soveran has quit [Ping timeout: 260 seconds]
bjz_ has quit [Ping timeout: 240 seconds]
bjz has joined #crystal-lang
snsei has quit [Ping timeout: 240 seconds]
soveran has joined #crystal-lang
soveran has quit [Ping timeout: 260 seconds]
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
Guest42326 has joined #crystal-lang
Guest42326 has left #crystal-lang [#crystal-lang]
akwiatkowski has joined #crystal-lang
Qchmqs has joined #crystal-lang
bjz has joined #crystal-lang
akwiatkowski has quit [Ping timeout: 260 seconds]
pawnbox has joined #crystal-lang
<jaitaiwan> Hey fam, just wanted to say I'm really excited about the direction crystal is heading.
jabb has quit [Ping timeout: 268 seconds]
<FromGitter> <sdogruyol> @jaitaiwan yeah, we are too :)
akwiatkowski has joined #crystal-lang
akwiatkowski has quit [Ping timeout: 260 seconds]
soveran has joined #crystal-lang
soveran has quit [Changing host]
soveran has joined #crystal-lang
soveran has quit [Ping timeout: 240 seconds]
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 268 seconds]
Raimondii is now known as Raimondi
dom96 has quit [Changing host]
dom96 has joined #crystal-lang
Kilo`byte has quit [Ping timeout: 240 seconds]
Kilo`byte has joined #crystal-lang
bjz_ has joined #crystal-lang
bjz has quit [Ping timeout: 260 seconds]
jabb has joined #crystal-lang
soveran has joined #crystal-lang
pawnbox has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
pawnbox has quit [Ping timeout: 240 seconds]
pawnbox has joined #crystal-lang
bjz_ has quit [Ping timeout: 240 seconds]
bjz has joined #crystal-lang
zaiste has joined #crystal-lang
<FromGitter> <schoening> @sdogruyol is there a way to make a request to an external api server?
<FromGitter> <dreyks> @schoening does `HTTP::Client` fit your needs?
<FromGitter> <schoening> I bet it does. I am gonna read through the api
<FromGitter> <schoening> thx @dreyks
<FromGitter> <schoening> Well... yeah, looks like it does. Ugh, why didn't i look first, then ask -_-'
<FromGitter> <dreyks> :smile:
zaiste has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<crystal-gh> [crystal] ysbaddaden opened pull request #4082: Fix: Check return pointer of LLVMGetStructName [#4078] (master...fix-llvm-type-get-struct-name-segfault) https://git.io/vykW7
splitty_ has joined #crystal-lang
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
splitty__ has quit [Ping timeout: 260 seconds]
akwiatkowski has joined #crystal-lang
Philpax has joined #crystal-lang
jabb has quit [Ping timeout: 255 seconds]
Philpax has quit [Read error: Network is unreachable]
Philpax has joined #crystal-lang
akwiatkowski has quit [Ping timeout: 268 seconds]
soveran has quit [Remote host closed the connection]
poikon has quit [Ping timeout: 240 seconds]
soveran has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Changing host]
poikon has joined #crystal-lang
<FromGitter> <l3kn> @jabb I think the difference would be that assert only has an effect when compiled in some debug mode
<FromGitter> <l3kn> You could build your own assert macro: https://play.crystal-lang.org/#/r/1oc1
<Papierkorb> Does someone know where the compiler figures out which methods to compile (with which argument types), and then actually builds them?
jabb has joined #crystal-lang
jabb has quit [Ping timeout: 255 seconds]
zaiste has joined #crystal-lang
olbat has quit [Ping timeout: 240 seconds]
<FromGitter> <Dohxis> Hello, I am a new guy on Crystal community just started to learn the language, it looks really nice. Maybe someone could help with tutorials?
<Papierkorb> Dohxis, just ask
<FromGitter> <Dohxis> I am not looking for any specific thing just the overall tutorial to begin with the language,
<FromGitter> <tekjar> Hi. How do I add unit tests to my library? Can someone pls point me to some docs/blogs
<Papierkorb> tekjar, look into spec/
<Papierkorb> has been auto-generated for you if you used `crystal init`
vegai has left #crystal-lang [#crystal-lang]
<FromGitter> <l3kn> @Dohxis https://learnxinyminutes.com/docs/crystal/ should help you learn the syntax
<FromGitter> <sdogruyol> there's this http://www.crystalforrubyists.com/
zaiste has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Philpax has quit [Ping timeout: 255 seconds]
olbat has joined #crystal-lang
zaiste has joined #crystal-lang
zaiste has quit [Client Quit]
Philpax has joined #crystal-lang
<FromGitter> <tekjar> Papierkorb: Thanks
<FromGitter> <Dohxis> How should I iterate through a string?
soveran has quit [Remote host closed the connection]
<Papierkorb> iterate how? for each character?
<FromGitter> <Dohxis> yes
<FromGitter> <Dohxis> wow thanks!
snsei has joined #crystal-lang
elia has joined #crystal-lang
<FromGitter> <tekjar> Hi. How do I print contents of IO::Memory as Slice of bytes?
<FromGitter> <fridgerator> @Dohxis this is also pretty useful : https://github.com/askn/crystal-by-example
<Papierkorb> tekjar, https://crystal-lang.org/api/0.21.0/IO%2FMemory.html#to_slice%3ABytes-instance-method
<FromGitter> <tekjar> Papierkorb: Thanks again :)
onionhammer has quit [Quit: WeeChat 1.0.1]
elia has quit [Quit: Computer has gone to sleep.]
onionhammer has joined #crystal-lang
<FromGitter> <tekjar> Hi. How to print `Bytes` in hex format on console? I'm not sure how to figure out these details from docs
Philpax has quit [Ping timeout: 240 seconds]
Philpax has joined #crystal-lang
pabs__ is now known as pabs
<Papierkorb> tekjar, in the link I gave you, click on the resulting type "Bytes", you'll see it's an alias for Slice. Click `Slice`. Now Ctrl-F "hex" and search the doc page.
<FromGitter> <tekjar> Papierkorb: Ahh thanks alot
Qchmqs has quit [Remote host closed the connection]
jabb has joined #crystal-lang
snsei has quit [Remote host closed the connection]
soveran has joined #crystal-lang
soveran has joined #crystal-lang
jrichards has joined #crystal-lang
jrichards has quit [Client Quit]
elia has joined #crystal-lang
elia has quit [Client Quit]
jrichards has joined #crystal-lang
rt_ has joined #crystal-lang
<rt_> Hi. How do I convert Bool to UInt8?
<rt_> There seems to be no to_u8 method for Bool
<RX14> rt_, why do you want to do that?
<rt_> I need to write a u8 to IO based on flag status.
mhib has joined #crystal-lang
<rt_> Spec says that I should write 0 for false and 1 for true
<RX14> well i'd typically go for the simple solution
<RX14> bool ? 1 : 0
<rt_> Oh cool. I forgot that it is an expression
<rt_> Still
<rt_> to_u8 might look better :)
<RX14> well, I think associating bool with 1/0 is outdated
<Papierkorb> lazy hack is using Bool#hash .. which may change and then your code breaks :D
<RX14> (don't do that)
<rt_> Ohh. Ok
mhib has quit [Quit: Leaving]
soveran has quit [Remote host closed the connection]
kubaxvx has quit [Quit: WeeChat 1.6]
kubaxvx has joined #crystal-lang
<Papierkorb> Does Crystal still support LLVM3.5?
<Papierkorb> Wasn't that the one producing broken code in --release mode?
Raimondi has quit [Quit: WeeChat 1.6-dev]
<FromGitter> <fazibear> Hi, any ideas how to convert ["a", "b"] to char** ?
soveran has joined #crystal-lang
soveran has joined #crystal-lang
bjz has joined #crystal-lang
<Papierkorb> fazibear, `args = ["a", "b"]; LibFoo.do_it(args.map(&.to_unsafe).to_unsafe)` - The `args` array must be kept alive by you until it's not used anymore.
zaiste has joined #crystal-lang
Raimondi has joined #crystal-lang
zaiste has quit [Ping timeout: 255 seconds]
jrichards has quit [Quit: Leaving...]
<sija> `["a", "b"].map &.at(0)`
<sija> ah, i misread your q, sorry
fazibear has joined #crystal-lang
<fazibear> thanks! Works great
<fazibear> One more question: How to cast Pointer(Void) to Float ?
<fazibear> that was easy: .as(Pointer(Float64))
<Papierkorb> you can also write `.as(Float64*)`
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
bjz has joined #crystal-lang
<fazibear> got problems with allocating array with one element ?
A124 has quit [Ping timeout: 240 seconds]
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
rt_ has quit [Quit: Page closed]
soveran has quit [Remote host closed the connection]
soveran has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Changing host]
soveran has quit [Remote host closed the connection]
CompanionCube has left #crystal-lang [#crystal-lang]
VectorGraphics has joined #crystal-lang
<VectorGraphics> Hey, is it possible to use Process.run() concurrently? Would that work in a fiber?
<RX14> VectorGraphics, what do you mean by concurrently?
<RX14> there's process.new which starts the process and returns a handle
CompanionCube has joined #crystal-lang
<RX14> and process.run which starts a process and blocks until it's done
<RX14> neither of them block the whole application
<RX14> just the current fiber
<VectorGraphics> I'll check out process.new. I have some long-running commands that I want to execute and not have the application wait while other things are happening
<RX14> it might turn out easiest to coordinate using channels and fibers though
CompanionCube has quit [Quit: ZNC - http://znc.in]
CompanionCube has joined #crystal-lang
<VectorGraphics> I didn't know about channels yet. Thank you
<RX14> thing with Process.new is you can't select on it yet
<RX14> (yet)
<RX14> actually you probably can
<RX14> could*
<RX14> with a bit of stdlib weaking
<RX14> but thats advanced~
<VectorGraphics> What do you mean select on it?
<RX14> basically you provide a set of calls which block
<RX14> and the first one which would return is used
<RX14> for example
<RX14> select; when foo = file.read; when file.write(bar); end
<RX14> thats not how files work at all but you get the idea
CompanionCube has left #crystal-lang [#crystal-lang]
<VectorGraphics> Ah
<VectorGraphics> I don't think I'll be doing quite that. I'm basically exploring what it would take to have a queue (array) with commands, and then have the system run each command as it can handle them via process. Once those are ready to return, their result would be processed further by the application and stored somewhere
<RX14> basically take an array of commands and execute them in parallel?
<VectorGraphics> Yeah
<RX14> the simplest way would be array.map { |command| Process.new(command) }.each { |process| process.wait }
<RX14> but that executes them all at the same time
<RX14> no parallelism limit
<VectorGraphics> Cool
<RX14> with a large array you'd just swamp the scheduler with processes
<VectorGraphics> That makes sense
<RX14> otherwise i'd spawn N fibers, then have a queue
<RX14> each fiber would pull a command, use Process.run on it
<RX14> push the result to an array
<RX14> then you'd push to a channel after every command finishes
<RX14> then call recieve commands.size times in the "main" fiber
<FromGitter> <dreyks> when you say "pull a command" is this also a receive?
<RX14> yeah that would work... maybe
<RX14> actually you'd probably have problems with unbuffered channels with that
<RX14> get into a dreaded deadlock
<RX14> you'd actually take your list of commands and take n random slices
<RX14> each slice (Enumberable#slice, not to be confused with Slice) would then be a normal array
<RX14> which the fiber would just use each on
<RX14> for example:
<RX14> in that one they slice up the units array into n slices
<RX14> spawn a fiber which just crunches through them in parallel
<RX14> then each fiber sends a value down the channel when it's done
<RX14> so you would recieve n_fibers.times
<VectorGraphics> Interesting
<RX14> concurreny is hard :)
<RX14> crystal gives you a really good toolbox but you can still get yourself in a twist
pawnbox has quit [Remote host closed the connection]
<VectorGraphics> Hey, I get into twists pretty easily in code already. Complications are almost guaranteed :P
pawnbox has joined #crystal-lang
CompanionCube has joined #crystal-lang
CompanionCube has quit [Remote host closed the connection]
<RX14> don't we all :P
<VectorGraphics> Haha
pawnbox has quit [Ping timeout: 240 seconds]
VectorGraphics has quit [Quit: Leaving]
soveran has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Changing host]
soveran has quit [Ping timeout: 260 seconds]