<FromGitter>
<redcodefinal> Hi guys, I noticed a potential issue or maybe I'm just being stupid. From my understanding when you roll a signed int over it should go from being (binary) 31 1's to negative 31 1's. I've noticed that the overflow in the Int32 for crystal actually goes to (binary) -10000000000000000000000000000000 or -2147483648. Am I making a mistake here? https://play.crystal-lang.org/#/r/1d5t
<FromGitter>
<jwoertink> I love people like this ^
<FromGitter>
<jwoertink> My head explodes just thinking about stuff like that
tomchapin has joined #crystal-lang
<FromGitter>
<jwoertink> What does `Invalid memory access (signal 11)` mean?
Philpax has joined #crystal-lang
tomchapin has quit [Ping timeout: 265 seconds]
tomchapin has joined #crystal-lang
Philpax has quit [Ping timeout: 250 seconds]
<FromGitter>
<cjgajard> I don't know exactly, but I've reached signal 11 accessing uninitialized vars `x = uninitialized String; puts x` ⏎ and with infinite recursion `def foo; foo; end; foo`
<FromGitter>
<jwoertink> I got it from passing a Hash in to a method. I ended up making the hash a Bool, and it went away
Philpax has joined #crystal-lang
tomchapin has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
Philpax has quit [Ping timeout: 250 seconds]
pawnbox has joined #crystal-lang
<FromGitter>
<cjgajard> @redcodefinal Crystal uses (~number + 1) for negative integers. That is hard to read (example: `15_i8` is "00001111" in memory, while `-15_i8` is "11110001" ) because of that, I suppose, `to_s` checks if the number is negative, and displays "-number_as_positive" when it is negative
kulelu88 has quit [Quit: Leaving]
vikaton has quit [Quit: Connection closed for inactivity]
ome has joined #crystal-lang
onethirtyfive has joined #crystal-lang
lacour has quit [Quit: Leaving]
onethirtyfive has quit [Remote host closed the connection]
Fichtenstein has joined #crystal-lang
mark_66 has joined #crystal-lang
Philpax has joined #crystal-lang
<FromGitter>
<International> when using macros, is there any way of seeing the code that gets sent to the compiler? something equivalent to seeing how C code looks after the preprocessor preprocessed it
<BlaXpirit>
International, use {% debug() %} inside a macro to output its result
<BlaXpirit>
redcodefinal, um basically everything is correct
pawnbox has quit [Read error: Connection reset by peer]
<FromGitter>
<iDev0urer> Can libs be split into multiple files the same way you would a class or module?
<FromGitter>
<International> thank you @BlaXpirit
<FromGitter>
<International> has any encountered this issue: `Program received and didn't handle signal TRAP (5)`? I get it when running `crystal spec`
<FromGitter>
<International> nvm, i forgot a debugger statement somewhere :)
<FromGitter>
<johnjansen> anyone got a good way to timeout a block of code after `x` seconds
<FromGitter>
<johnjansen> my brain is frozen
<BlaXpirit>
iDev0urer, yes
<BlaXpirit>
johnjansen, there really isn't a generic way to do that
<FromGitter>
<johnjansen> i need to come up with a good plan, for now just to timeout a `Process` but this will come up over and over
<Papierkorb>
johnjansen, what's the block doing? Waiting on IO? Calculating stuff?
<FromGitter>
<johnjansen> in this case unzipping a very large file … i need to (for the time being) shell out to do the work, but occasionally something is hanging in the process (i dont know what (YET)) … anyway, this is a recurring theme so i want to think through the whole concept of timeouts, getting a starting point will help engage the brain
<FromGitter>
<johnjansen> ;-)
<BlaXpirit>
johnjansen, processes is the only thing that can be timed out reliably. should be very easy
<Papierkorb>
johnjansen, you can't kill a fiber just like you can't reliably kill a thread (in other programming languages)
<Papierkorb>
johnjansen, you could check for a "cancel" boolean to be set every once in a while in your zip tool
<FromGitter>
<redcodefinal> Is there a way to do an enumerable step? I need to start at 0 and increment by 0.1 until it's 1
ruby_ has joined #crystal-lang
mhib has joined #crystal-lang
<FromGitter>
<International> is the bountysource integration not working? i tried now, and a few times in the past to contribute, but i keep getting errors
<FromGitter>
<johnjansen> `(0..10).map{ |i| i / 10.0 }` … `.step` might be around somewhere too
<FromGitter>
<redcodefinal> I did the thing, now how do I shard it up
kulelu88 has joined #crystal-lang
<FromGitter>
<redcodefinal> Oh also, is there a way to make a private block instead of individually making every method I need private private
<BlaXpirit>
redcodefinal, no such way
<BlaXpirit>
well actually you could make a macro to transform all methods inside it, but..... don't
<FromGitter>
<redcodefinal> @FromIRC lame ill get to typing
<FromGitter>
<redcodefinal> @BlaXpirit lame I'll get to typing
mhib has quit [Quit: Leaving]
onethirtyfive has quit [Remote host closed the connection]
<RX14>
@redcodefinal it's one extra word on your method definition... It's really not that big of a deal.
<FromGitter>
<redcodefinal> @RX14 yeah it's just im spoiled by ruby's ```private:``` blocks
<RX14>
Plus code is read many more times than it is written, and having a large "private block" where the beginning and ends of it may be off your screen is certainly not readable
<FromGitter>
<redcodefinal> @RX14 depends, I usually group my methods by visibility. So if you see a private block everything after it is going to be private. Protected is very rarely used in Ruby, so usually everything is either public or private
<RX14>
yes
<RX14>
but how can you tell if your method is private if the start of the bkock is off the screen
<RX14>
the same applies for class << self
<FromGitter>
<redcodefinal> @RX14 Don't write code that goes of the screen <;P
<RX14>
yeah right
<RX14>
now it's in 400 files
<RX14>
is that any better?
<FromGitter>
<redcodefinal> @RX14 I actually really like the ```class << self``` paradigm but thats just me.
<Papierkorb>
redcodefinal, as does almost every ruby developer
<FromGitter>
<redcodefinal> @RX14 if you have 400 files worth of code in one file then yes lol
<RX14>
well you can't fit much code into one screen...
<RX14>
I dislike `class << self` because it's another place that you have to look to find out about the method
<FromGitter>
<redcodefinal> @RX14 I just try to compartmentalize code
<RX14>
where in crystal all the information is contained in the method declaration
<RX14>
there's no ambient context
<FromGitter>
<redcodefinal> @RX14 also ```class<<self ``` comes in handy when you are only defining class level methods/variables
<Papierkorb>
Crystal also allows you to reopen a class later and add or even override methods. if you're in for readability, that's the worse offender than a private block like ruby or C++ allows it.
<RX14>
@redcodefinal you can `extend self` for that
<Papierkorb>
redcodefinal, and as you're indenting the def further, it's also visible that "something's up"
<RX14>
reopening classes is pretty rarely used though
<FromGitter>
<redcodefinal> I think like most of the "black magic" in ruby it has it's place
<Papierkorb>
different people like different things. No "standard code formatter" will ever change that.
<FromGitter>
<redcodefinal> I really like using it when I am only defining class level stuff inside a class to ensure that it's clear that the class is simply class level methods
<FromGitter>
<redcodefinal> Plus Ruby gives me the tools to not repeat myself
<FromGitter>
<redcodefinal> might as well use them
gloscombe has quit [Remote host closed the connection]
<FromGitter>
<raydf> Hi everyone, does anybody knows about a template engine in crystal parsed at runtime? without macros?
<RX14>
@redcodefinal i think that repetition is a useful tool which should be used correctly
<RX14>
@raydf crustache or temel seem to be what you'd want
<FromGitter>
<raydf> @RX14 , thanks, crustache looks like a nice one
<FromGitter>
<redcodefinal> How do I get a shard on CrystalShards.xyz?
<RX14>
upload it to github
<FromGitter>
<redcodefinal> @RX14 and crystalshards.xyz will just know?
<RX14>
yeag
<RX14>
it uses the github api
<FromGitter>
<redcodefinal> fancy and good to know
pawnbox_ has quit [Remote host closed the connection]
<FromGitter>
<redcodefinal> So I got a weird error.
<FromGitter>
<redcodefinal> Oh cause it's hiding the real type gotcha
<Papierkorb>
Yeah Float is a superclass of those two
<FromGitter>
<johnjansen> it also implied auto scaling up and down :-)
<Papierkorb>
Shameless self promotion: I just published the BitTorrent client library I'm currently working on at https://github.com/Papierkorb/torrent - Oh and it's very WIP, expect the API to be unstable.
<FromGitter>
<redcodefinal> @Papierkorb Nice. I'm working on a Perlin Noise library myself
<FromGitter>
<sdogruyol> @redcodefinal your avatar is cool, i liked it
<FromGitter>
<redcodefinal> @sdogruyol thanks man I made it myself with some pixels
<FromGitter>
<sdogruyol> yeah i like pixel art stuff
<FromGitter>
<sdogruyol> nice job
<FromGitter>
<johnjansen> very nice @Papierkorb add it to travis and stick a badge on it ;-) then we know if its ready by its status
<Papierkorb>
johnjansen, I switched to Spec2 mid-way, so before I enable travis I have to rewrite the Spec "1" tests. They do run fine, but if they fail things get awkward..
<FromGitter>
<johnjansen> :-)
bjz has joined #crystal-lang
<maxpowa>
Am I missing something or does TCPSocket not have a way to bind to a specific (local) address?
<maxpowa>
It looks like UDPSocket has implemented bind(host, port) but TCPSocket doesn't appear to have an equivalent.
<BlaXpirit>
maxpowa, maybe u need TCPServer? just guessing from what i vaguely remember
<maxpowa>
TCPServer can be used as a client?
<BlaXpirit>
maxpowa, ummm no
<maxpowa>
I'm connecting to a remote server, but want to bind to a specific IP on the local device.
<BlaXpirit>
and TCPSocket can't be used as a server
<FromGitter>
<zatherz> not really "ported", more like "fixed"
<FromGitter>
<zatherz> it was just using the old casts, `var as Type`
<FromGitter>
<zatherz> `crystal tool format` fixed most of those, then I just hand-fixed the rest
<maxpowa>
It's not only used for servers
<maxpowa>
it's also used for clients that are concerned about what ip they're connecting to a remote ip with.
<maxpowa>
Like I said, UDPSocket already has it implemented, it just doesn't appear to be in TCPSocket
<Papierkorb>
BlaXpirit, you can bind an outgoing socket onto a interface to insure it *will* use that interface for all communication and not use the systems routing table to decide which interface to use
<maxpowa>
^
sustained has quit [Read error: Connection reset by peer]
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<FromGitter>
<redcodefinal> Ok so another weird issue. ⏎ ```crystal
<FromGitter>
<redcodefinal> lol
<FromGitter>
<redcodefinal> stupid enter key
<FromGitter>
<redcodefinal> but essentially if I run this ⏎ ```get_perlin_noise(1)``` ⏎ it somehow makes it to the ```when 2``` clause instead of the ```when 1``` clause
<FromGitter>
<redcodefinal> also my puts at the top isnt showing up and I don't know why
<BlaXpirit>
redcodefinal, what's there not to understand?
<FromGitter>
<redcodefinal> @cjgajard took in a splat of ints, and it properly routed to the right when
<FromGitter>
<redcodefinal> @BlaXpirit Why would the execution jump to the ```when 2``` clause when args.size would be equal to 1
<BlaXpirit>
redcodefinal, but it seems like it doesn't??
<FromGitter>
<cjgajard> def foo(*args); end; foo(1) #=> args is infered to be Tuple(Int32) ⏎ def foo(*args); end; foo(1, 2) #=> args is infered to be Tuple(Int32, Int32) ⏎ def foo(*args); end; foo(1); foo(1, 2) #=> args is infered to be Tuple(Int32) | Tuple(Int32, Int32)
<FromGitter>
<zatherz> escape your asterisks
<FromGitter>
<zatherz> with \\
<FromGitter>
<zatherz> alternatively, use \`\`\`
<FromGitter>
<redcodefinal> @BlaXpirit It doesn't. Look at the ```get_perlin_noise``` code. It cases ```args.size``` which if a ````Tuple(Int32)``` is ```args``` the ```args.size``` is 1. Am I wrong so far?
<FromGitter>
<redcodefinal> @BlaXpirit If that is true, then the proper ```when``` clause should be ```when 1``` not ```when 2```
hako_ has joined #crystal-lang
<FromGitter>
<redcodefinal> @BlaXpirit Alternatively would making overloads of the ```get_perlin_noise``` method fix this issue?
<FromGitter>
<zatherz> a tuple is compiletime, so it's bounds are checked at compiletime, not runtime
<FromGitter>
<redcodefinal> @zatherz so are you saying that Crystal will prebake the answer to args.size?
<FromGitter>
<zatherz> no, it doesn't know what `size` is
<FromGitter>
<zatherz> as it can be anything
<FromGitter>
<redcodefinal> @zatherz hmm
<FromGitter>
<zatherz> it can return 15 when the actual size is 0
<FromGitter>
<zatherz> if you override it
<FromGitter>
<zatherz> @redcodefinal this is definitely something you should use overloads on
<BlaXpirit>
redcodefinal, I still have no idea what the problem is. everything seems correct
<FromGitter>
<zatherz> using splats in this way is hacky when you have actual overloading
<FromGitter>
<redcodefinal> Yeah I'm porting methods I wrote in Ruby and I am still learning the Crystal way, thanks for the help @BlaXpirit and @zatherz
<FromGitter>
<zatherz> yeah, that's very ruby-like
<FromGitter>
<zatherz> but very crystal-unlike :P
<FromGitter>
<zatherz> is there a way to disable text emoticons from turning into emojis
<BlaXpirit>
ah, the [0] is broken, that's... yeah
<FromGitter>
<redcodefinal> to be honest I've been wanting that feature in ruby because I think it's dumb that I need to case it out like that
<BlaXpirit>
zatherz, there is absolutely no way to do that in gitter
<FromGitter>
<zatherz> yeah
<FromGitter>
<redcodefinal> but ruby doesnt really support overloads in any context so I've learned to get by without them
<BlaXpirit>
but i do hacks in my bridge bot :p
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<FromGitter>
<zatherz> `to_u32` for UInt32, `to_u64` for UInt64, `to_i8` for Int8, etc
<FromGitter>
<redcodefinal> ah thats neato
<FromGitter>
<zatherz> Papierkorb: is that for sure the full output?
<Papierkorb>
zatherz, it is the full file as was given by $ crystal spec spec/torrent/bencode/lexer_spec.cr > wtf
<Papierkorb>
however, github decided to add line breaks
<FromGitter>
<zatherz> Papierkorb: `crystal -v`?
<Papierkorb>
Crystal 0.19.4 (2016-10-07)
<FromGitter>
<zatherz> Papierkorb: could you please try `crystal spec spec/torrent/bencode/lexer_spec.cr 2>&1 > wtf`?
<Papierkorb>
line 98 is semantically what I have in the _spec.cr - Too bad that spec2 doesn't support doing [..].each{ it("..."){ .. } } like in RSpec
sustained has quit [Remote host closed the connection]
<Papierkorb>
zatherz, crystal does not write anything to stderr
<Papierkorb>
that's literally everything it tells me
<FromGitter>
<zatherz> Papierkorb: is the code public somewhere?
<Papierkorb>
Another gem from today was "type must be Pointer(Array(UInt32)), not Pointer(Array(UInt32))" - Though I was not able to reproduce this one. It happened with a StaticArray(ArrayAlias, SOME_CONST) in a class while building the default #inspect(io). Trying in `play` didn't yield something useful, there it always worked fine
<Papierkorb>
zatherz, that's my WIP, see line 98 in the gist for what I do
<FromGitter>
<zatherz> oh, just noticed that you linked the gist
<FromGitter>
<zatherz> well yeah that's fucked
<FromGitter>
<zatherz> Papierkorb: I don't know spec2 at all, so I can't really help. I'd suggest reporting it to spec2 first
<Papierkorb>
Spec2 is basically benchmarking the compiler or something. Spec "1" worked fine
<FromGitter>
<zatherz> you're defining a matcher called `match`. register_matcher does a `def match`
<Papierkorb>
To be frank, if you have a syntax error in the spec, the error reporting is awful
<FromGitter>
<zatherz> it may be a collision related to that
<FromGitter>
<zatherz> try `register_matcher(_match)` or something like that just to test the theory
<Papierkorb>
zatherz, match(..) works fine for other specs
<FromGitter>
<zatherz> you mean `register_matcher(match)`?
<Papierkorb>
I'm not the author of spec2, nor do I use #register_matcher myself
<FromGitter>
<zatherz> I see
<FromGitter>
<zatherz> Papierkorb: could you try to reduce the whole project to the minimum required to trigger the error? remove any other specs that do work, and reduce the actual code
<Papierkorb>
zatherz, I found 4 bugs in the last hours, the above one being reproducable, one being a spec2 bug, and two where I have no clue how to reproduce
<FromGitter>
<zatherz> `testtesttest_spec.cr` is that code of course
<Papierkorb>
Are you on Crystal 0.19.4 (2016-10-07) too with spec2 at that commit? I'm on Linux x64
<Papierkorb>
Crystal was installed from the ArchLinux repository
<FromGitter>
<zatherz> Papierkorb: spec2 `eef5144d86f3aadf95811ffc0450be389db36fed`, crystal Crystal 0.19.4+51 [66f6970] (2016-10-22), Crystal from `crystal-git` in the AUR built on 22.10.2016
<Papierkorb>
will try with crystal-git
bjz has quit [Ping timeout: 268 seconds]
matp has quit [Read error: Connection reset by peer]
matp has joined #crystal-lang
<Papierkorb>
jeez, wish I would'
<Papierkorb>
ve skipped the verification step. Don't care much about that right now -.-
<BlaXpirit>
Papierkorb, much easier to just keep a folder
<BlaXpirit>
git pull && make
<Papierkorb>
zatherz, whatever it was, it's fixed in the recent git
<crystal-gh>
[crystal] maxpowa opened pull request #3495: Allow TCPSocket to bind to specific local address (master...tcpsocket-bind-local) https://git.io/vXZBS
sustained has quit [Remote host closed the connection]
<FromGitter>
<redcodefinal> Question. I wrote a method in Ruby to pull values randomly from an Array using perlin noise. The method looks like this. ⏎ ```code paste, see link``` ⏎ In Ruby Arrays can hold any type, it doesn't matter, and can return any type of value so this works well. I need to write a similar method for Crystal. However, since Crystal wants you to type things, I'm not sure how to make this happen. Can Crystal's Array be used as
<FromGitter>
... an umbrella to catch all the other Array types ( like Array(Int32) or Array(String))? What about the return value? Theoretically, any Array of any type could go into it, and any type could come out. Would I make the return type a Generic of some sort? [https://gitter.im/crystal-lang/crystal?at=581a6acfe097df7575621711]
<Papierkorb>
johnjansen, wish "add a badge" fulfilled :3
A124 has quit [Read error: Connection reset by peer]
<FromGitter>
<redcodefinal> @BlaXpirit how would the call to that look? Would this be right? ⏎ ```x = [1,2,3] ⏎ get_perlin_item(0, x)``` ⏎ or would I need to specify the Generic type T when calling the method? [https://gitter.im/crystal-lang/crystal?at=581a6bc2e462097a30ff1271]
<BlaXpirit>
it just works. like that, yes
A124 has joined #crystal-lang
<FromGitter>
<redcodefinal> @BlaXpirit Ah sweet thanks for the suggestion, I'm going to go dig into the Indexable API Docs
<BlaXpirit>
though now that i think about it the implicit T is deprecated. https://carc.in/#/r/1d89 will be the only way to have this T in the future