RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.24.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
Poetifox is now known as Poeticode
qard has joined #crystal-lang
qard has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
greengriminal has joined #crystal-lang
<FromGitter> <watzon> What would be the easiest way to fix floating point math? I don't care about it being super accurate, but I don't want to have a number like 0.001000000000047740 when it should just be 0.001
<FromGitter> <watzon> Is there a way to just format the float so that it only shows the amount of decimal places Floats are accurate to?
greengriminal has quit [Quit: This computer has gone to sleep]
redIcey has joined #crystal-lang
redIcey has quit [Client Quit]
aarongough has joined #crystal-lang
<FromGitter> <watzon> I guess I can just do this `"%.10g" % 0.001000000000047740`
<aarongough> Hey guys! I have what may be a dumb question, but googling for the answer has eluded me... What's the purpose of `Object#.not_nil!`?
<FromGitter> <watzon> It asserts that something is not nil and allows you to bypass the compiler's nil checking
<FromGitter> <watzon> But if the object does end up being nil it will throw an error
<aarongough> Ah ok.. I might submit a PR for the docs to clarify, I am using a regex with named captures, and all the docs have code like `string.match(regex).not_nil!["capture"]
<aarongough> It was very non obvious from the docs what it was supposed to do :D
<aarongough> Thanks for the quick response!
<FromGitter> <bew> You should handler the case where the regex does not match (will return nil)
<FromGitter> <watzon> No problem. I like to help where I can haha.
<FromGitter> <watzon> And @bew is correct. Definitely don't use `not_nil!` unless you have to. If something could be nil you should handle that possibility.
vivus has quit [Quit: Leaving]
<aarongough> @bew Right so something like `string.match(regex).not_nil?["capture"]?` and then check for nil
<aarongough> @watzon so the issue is that without `not_nil!` I always get the error: undefined method '[]' for Nil
<FromGitter> <watzon> Right. You need to do a nil check instead. The problem is that `string.match` will return nil if nothing matches
<FromGitter> <watzon> so first you have to check if the result is nil, and then handle that possibility. The easiest way to do so is to have a fallback value, but that doesn't work for every case. So `str.match(/some-regex/) || "default"`
<FromGitter> <watzon> That way `my_var` is always of the type `String` and not (String | Nil)`
<aarongough> Ok, so `"foo far".match(/(?<first>foo)/)["first"]` throws `undefined method '[]' for Nil` because the return type of `match` is (MatchData|Nil)
<aarongough> I think I understand a bit better now, thanks!
<FromGitter> <marksiemers> Yes, one way you can take care of it is with an if statement: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5a6be1ffce68c3bc740c1ee3]
<FromGitter> <marksiemers> The compiler is smart enough to know that `match` won't be `nil` in the if branch
<aarongough> Interesting! Makes sense that I'd have to handle both possible return values, just trying to bridge the cognitive gap to the new language :D
duane has quit [Ping timeout: 256 seconds]
jnyw has joined #crystal-lang
aarongough has quit [Ping timeout: 260 seconds]
sz0 has joined #crystal-lang
qard has joined #crystal-lang
qard has quit [Remote host closed the connection]
qard has joined #crystal-lang
qard has quit [Quit: qard]
qard has joined #crystal-lang
sz0 has quit [Quit: Connection closed for inactivity]
qard has quit [Read error: Connection reset by peer]
qard_ has joined #crystal-lang
qard_ is now known as qard
qard has quit [Quit: qard]
qard has joined #crystal-lang
<FromGitter> <watzon> Yeah, really what we need in Crystal is good patten matching. Rust and Elixir both have very good pattern matching and it makes dealing with that stuff a breeze.
<FromGitter> <watzon> The Bool struct should definitely have a `to_i` method
Ven`` has joined #crystal-lang
Ven`` has quit [Ping timeout: 252 seconds]
<FromGitter> <watzon> So how can I take an object with the type `JSON::Any` and parse it into an object with a `JSON.mapping` on it?
<FromGitter> <watzon> Doing `MyJSONObject.as(OtherObject)` doesn't seem to be yielding results.
qard has quit [Ping timeout: 256 seconds]
aroaminggeek has quit [Quit: Textual IRC Client: www.textualapp.com]
<FromGitter> <watzon> Got it working with `from_json` and `to_json`. Seems really inefficient to convert JSON to a string and then parse it again though.
<FromGitter> <HCLarsen> Hey everyone. My newest Crystal Blog entry. I tackled TDD in Crystal with minitest.
<FromGitter> <watzon> Is it possible to compose objects with JSON::Any? For instance I have one object that has 10 fields and another object that shares 8 of those same fields. Can I combine them somehow?
alex`` has joined #crystal-lang
<FromGitter> <Dillybob1992> I finally did it, haha (https://i.gyazo.com/2d9328c4b732085fbd0f8a1e49812807.png). I want my $6 back now, lol jk
jnyw has quit [Quit: WeeChat 2.0.1]
ua_ has joined #crystal-lang
ua has quit [Ping timeout: 256 seconds]
sz0 has joined #crystal-lang
hightower3 has joined #crystal-lang
hightower2 has quit [Ping timeout: 246 seconds]
Yxhuvud has quit [Read error: Connection reset by peer]
Yxhuvud has joined #crystal-lang
<FromGitter> <asterite> watzon: why don't you parse directly into the final object? maybe you need to parse to a different type depending on something else. In that case I I recommend using `{type: String, converter: String::RawConverter}`. That will keep the raw string and from there you can parse it normally, and it should be the most efficient way (it's just parsed once)
sz0 has quit [Quit: Connection closed for inactivity]
<FromGitter> <watzon> @asterite yeah I figured it out haha
<FromGitter> <watzon> How do you compile with no gc? I'm trying to get a hello world as small as possible for size comparison.
linuksz has joined #crystal-lang
<linuksz> What's wrong with this code? https://play.crystal-lang.org/#/r/3gol
<RX14> linuksz, [nil] is an Array(Nil)
<RX14> ["string"] is an Array(String)
<RX14> so the method return Array(Nil) | Array(String)
<RX14> you can't do Array(String | Nil) + Array(Nil) because they're different types
<RX14> you can either explicitly force them to be Array(String | Nil) using [nil] of String | Nil
<RX14> or map(&.as(String | Nil))
<linuksz> I don't understand it. Why is this working? https://play.crystal-lang.org/#/r/3gos
<linuksz> It adds Array(String) and Array(Nil) to Array(String|Nil)
<oprypin> linuksz, it creates a new object https://crystal-lang.org/api/0.23.1/Array.html#%2B%28other%3AArray%28U%29%29forallU-instance-method
<linuksz> oprypin: what part of it?
<RX14> or map(&.as(String | Nil))
<RX14> oops
<RX14> that second example is weird though
<oprypin> linuksz, first example doesnt work because the `+` method accepts Array(U), not a union of types
<RX14> and so why does the second example work then oprypin
<RX14> if Array(Foo | Bar) + Array(Foo) works
<RX14> and Array(Foo | Bar) + Array(Bar) works
<RX14> then by definition
<RX14> Array(Foo | Bar) + (Array(Bar) | Array(Foo)) should work
<RX14> seems like a bug to me
<oprypin> but it doesnt because the type system is this way
<linuksz> Yes, this is what I don't understand. Is this a compiler bug?
<oprypin> it's a lack of an obscure feature, not a bug
<oprypin> the function signature accepts an Array, not a union, what's not clear?
<linuksz> oprypin: How can I work around this?
<oprypin> dont pass it a union
<RX14> oprypin, in my opinion it's just a bug:
<oprypin> {[nil] of (String|Nil)}.sample
<RX14> the compiler is failing to issue multiple-dispatch to the same method when the method uses forall
<oprypin> RX14, this is not about forall
<RX14> it is
<linuksz> oprypin: I don't know how the type inference of the compiler works, but doesn't it create two overloads?
<linuksz> e.g.: def something(String|Nil)
<linuksz> becames
<oprypin> no
<linuksz> something(String) and something(Nil)
<oprypin> i'm pretty sure it is actually something(String|Nil) all the way through
<oprypin> eh nevermind, i actually have no idea
<RX14> I thought I exampled it fairly simply above
<RX14> oprypin, what I meant was this works: https://play.crystal-lang.org/#/r/3gp0
<oprypin> linuksz, you're probably right because https://carc.in/#/r/3gp1
<RX14> oprypin, but this doesn't: https://play.crystal-lang.org/#/r/3gp2
<oprypin> RX14, OK good example, I had the same thought and I thought it wouldn't work
<oprypin> so you proved it
<RX14> why would you think that?
<RX14> crystal does multiple dispatch on reciever, method args, everything
<frojnd> I am looking for a "map" solution in crystal. Is there any similar functions?
<RX14> it's just failing to consider the forall as multiple dispatch targets
<RX14> frojnd, it's called map
<RX14> wait like
<RX14> the datatype or the function?
<RX14> frojnd, what do you mean by a map?
<frojnd> method
<RX14> Yeah its just map
<RX14> Examples in the docks
<frojnd> The map method takes an enumerable object and a block, and runs the block for each element, outputting each returned value from the block
<oprypin> https://crystal-lang.org/api/0.23.1/Enumerable.html#map%28%26block%3AT->U%29forallU-instance-method
<frojnd> RX14: I am blind,.. cannot find it in api or official
<RX14> >> [1,2,3].map { |a| a + 1 }
<RX14> Its because its in enumerable frojnd
<RX14> Hopefully fuzzy search will solve this
<frojnd> RX14: Aha... searech should be optimized though?
<frojnd> Thank you
<RX14> Search is only for types
<RX14> Not methods
<RX14> That's fixed in the next release
<oprypin> oh is it merged?
<RX14> Yeah
<frojnd> Superb :)
<oprypin> maan i'm behind on this
<oprypin> it's already live https://crystal-lang.org/api/master/Array.html#map%28%26block%3AT->U%29forallU-instance-method
<RX14> You could have ctrl-f on the array page frojnd
<RX14> Yup oprypin
<frojnd> RX14: I will untill it's pushed
<oprypin> not the best ordering by relevance tho
<RX14> i guess debot's ded though
<linuksz> oprypin: I thought the overloat thing by the error message:
<linuksz> Couldn't find overloads for these types:
<linuksz> - Array(String | Nil)#+(other : Array(String))
<linuksz> Doesn't the generic define both Array(String) and Array(Nil), similarly how RX14 did it with the 'add' method in https://play.crystal-lang.org/#/r/3gp0?
<RX14> yes, that's the bug
<RX14> that it doesn't see "both" overloads
<RX14> even though they're voth there
<RX14> both*
<linuksz> So should we create an issue?
<RX14> i guess
<crystal-gh> [crystal] MakeNowJust opened pull request #5648: Don't use heredoc inside interpolation (master...fix/crystal/dont-use-heredoc-inside-interpolation) https://git.io/vNMVT
<linuksz> oprypin: what do you think about RX14's examples?
<oprypin> [14:48:09] <oprypin> RX14, OK good example, I had the same thought and I thought it wouldn't work
<oprypin> [14:48:16] <oprypin> so you proved it
<linuksz> oprypin: oh, ok.
<linuksz> RX14: Could you create the issue? You have proved that it is a bug with your examples.
linuksz has quit [Quit: WeeChat 2.0.1]
hightower has joined #crystal-lang
<crystal-gh> [crystal] RX14 pushed 1 new commit to master: https://git.io/vNMPf
<crystal-gh> crystal/master ffda890 Ary Borenszweig: Spec: implement `be_a` and `expect_raises` without macros (#5646)...
<travis-ci> crystal-lang/crystal#ffda890 (master - Spec: implement `be_a` and `expect_raises` without macros (#5646)): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/334128217
<FromGitter> <Dillybob1992> "non-switchable non-generational Boehm GC. There is a way to live without allocations (use structs, slices and other value types), but all classes are GC-d. " what does this user mean by this? isn't classes being GC'd a good idea??
<oprypin> Dillybob1992, garbage collection is a known performance sacrifice but it makes the language much easier to use
<oprypin> and the currently used GC seems to be showing some problems
<FromGitter> <Dillybob1992> rx14 and paberiero explained to me some gc stuff yesterday. i still am quite confused on why the memory stays the same and doesn't go down, when it gets garbage collected. does the garbage collection just make it so that memory can be "used again", but doesn't "free the memory"?
<oprypin> sure
<FromGitter> <Dillybob1992> ok makes more sense
<FromGitter> <Dillybob1992> so it's very different "freeing memory" compared to "letting it be used again"
<RX14> "paberiero"
<FromGitter> <Dillybob1992> couldn't remember his name :P
aroaminggeek has joined #crystal-lang
<RX14> it's Papierkorb
<oprypin> Dillybob1992, it's "letting the current process use it again" vs "letting the OS use it again"
<RX14> @Dillybob1992 you can think of it as "pools" of memory
<FromGitter> <Dillybob1992> is there a way to ever de-allocate the memory though? i remember rx14 saying something about a method u can call
<RX14> obviously you're limited to the amount of ram in your system
<RX14> thats the pool of memory available to the OS
<RX14> and the kernel dishes out parts of RAM to itself and applications that want it
<RX14> applications can say "I need some memory"
<RX14> and "I don't need this memory any more"
<RX14> and all is well
<RX14> however, in crystal, we use a GC
<RX14> this GC maintains a seperate private pool of memory for itself
<RX14> it allocates objects out of this smaller seperate pool of memory that it asks the OS for
<RX14> so the GC asks the OS for larger chunks of memory
<RX14> then gives little bits of those chunks out for objects
<RX14> this increases performance because we don't want to go to the OS for every tiny object allocation
<RX14> (asking the kernel for more memory is expensive)
<RX14> the GC knows what part of it's internal pool of memory is unused, and which parts are used
<RX14> so it knows which parts of it's internal pool it can reuse for new objects
<RX14> when there's no more memory it asks the OS to expend it's pool
<RX14> however, the specific GC we're using never tells the os "i'm not using this part of my memory pool any more"
<FromGitter> <Dillybob1992> ohhhh... i see
<RX14> and so the amount of memory in the GC pool of memory never goes down, it always goes up or stays the same
<RX14> this means the GC sees large parts of it's internal memory pool as free and can allocate those to crystal objects
<RX14> however the OS never sees it as free again
<RX14> and so you don't see it when you look in say htop
<RX14> but there is a large portion of the "reserved" memory of the process that's free
<RX14> it's not that the OS doesn't know that
<RX14> does that help?
<FromGitter> <Dillybob1992> yes, just took a s/s of message log, appreciate it
<RX14> np
<FromGitter> <Dillybob1992> so just because crystal has that "reserved memory" some of it is still free to be used for other things. so it's not necessarily "actual ram being used", if you will? if i got that right
<RX14> it has the reserved memory -and it's reserved in that only crystal can use it
<RX14> however it's free for crystal to use even if you can't see that in htop
<RX14> htop doesn't know about the GC
<RX14> it can only tell you the pool size
<RX14> not how much of the GC memory pool is used
<FromGitter> <Dillybob1992> is it possible to tell the GC "i'm not using this part of my memory pool any more"? or would that be really expensive / void the entire use of a GC
<RX14> but you don't know about the memory pool
<FromGitter> <Dillybob1992> to the os***
<RX14> as far as you're concerned you just magically allocate objects and they're cleaned up
<RX14> the thing is, the memory pool is really fragmented
<RX14> so the memory pool has bits and pieces of it used all over the place
<RX14> and small holes in between which are unused
<RX14> you can't just tell the OS "these holes are free", you can only tell the OS that larger chunks of memory are free
<RX14> so its very difficult for the GC to do
<RX14> and due to... reasons the GC can't defragment the heap easily
<FromGitter> <Dillybob1992> i think i got it...
<FromGitter> <Dillybob1992> i hope
chaser93 has joined #crystal-lang
<FromGitter> <l3kn> @Dillybob1992 There is a rubyconf talk about why moving objects is so hard (in ruby, but the problems are probably the same), might be interesting for you https://youtu.be/8Q7M513vewk?t=18m28s
<RX14> @Dillybob1992 you don't reeally need to worry about any of this though
<RX14> it's super interesting
<RX14> but it's unlikely to affect how you use crystal much
<Papierkorb> Rather, it shouldn't affect you much
<Papierkorb> An optimization can easily turn into a deoptimization and/or worse code without necessity
<FromGitter> <Dillybob1992> im just thinking about if i get a peak of high users, crystal will need to allocate that memory for those new connections. then, when they all log off, the allocation will still be there. so now the Hosting provider will look at my server (has 96% ram usage), while i have 5 players online. i just don't know what i'm not getting
<Papierkorb> The hosting provider doesn't care, if you use 96% of your 512MiB, it's not their problem. If it's a problem to you is a different matter
<FromGitter> <Dillybob1992> true. its all my ram just feels weird thinking about that
<Papierkorb> But are you really already using half a gig of ram with 5k lurking connections?
<FromGitter> <Dillybob1992> that's what i dont get, since it's garbage collected im not
<FromGitter> <Dillybob1992> but the usage stays the same!
<FromGitter> <Dillybob1992> what is the Difference...
<Papierkorb> As RX explained above. My question goes towards why you need that RAM in the first place. Is the game state huge?
<Papierkorb> Are you storing *tons* of data per connection?
<FromGitter> <Dillybob1992> well, for my masterserver not so much, gameserver one will though. Example, the Player class has properties (hp, mana, level, rpg stats, etc) that all get memory allocated on Player.new. and increase if a lot of players connect. then, when the players log off, that memory will NOT be used because it'll be garbage collected, but it will show the amount of ram allocated? ⏎ ⏎ So, there is a difference
<FromGitter> ... between memory allocation, pool, and usage? so when you look at the "reserved ram" for crystal, that's just its memory pool, not necessarily actual "memory being used"?
<chaser93> can someone look at this? https://play.crystal-lang.org/#/r/3gqo/edit (its a question)
<Papierkorb> Dillybob1992, player state may be a few thousand variables for some kind of RPGs, but still in the low KiBs
greengriminal has joined #crystal-lang
<FromGitter> <Dillybob1992> lmao look what i found when searching 😄
<FromGitter> <Dillybob1992> i forgot the "lang" part :O
<FromGitter> <codenoid> morning
<FromGitter> <codenoid> it's illegal
aroaminggeek has quit [Quit: Textual IRC Client: www.textualapp.com]
duane has joined #crystal-lang
<FromGitter> <l3kn> chaser93: Maybe something like this https://play.crystal-lang.org/#/r/3gqy ?
<Papierkorb> Wow I finally found a use-case for a fallthrough in a switch statement. Amazing.
<oprypin> Dillybob1992, yeah those things are inevitable
<FromGitter> <bew> chaser93: you could check if the command starts with a +, and if it does check what the command is, in a case..when..end block
<FromGitter> <l3kn> chaser93: for "echo" to work, you would need to split the input first and then work with input[0]
<chaser93> i splitted it
<FromGitter> <l3kn> charser93: I meant before you use it in the `case`, something like`+echo foo`would not work because it is not equal to `"+echo"`
<chaser93> yea i will change that thx
<FromGitter> <Dillybob1992> actually, i thnk i found a solution
DTZUZU has quit [Ping timeout: 248 seconds]
<FromGitter> <bew> What do you want to use this for?
vivus has joined #crystal-lang
<FromGitter> <Dillybob1992> is there a way to deallocate the ram that class is used via a method? i can then just call it in finalize (when it gets gc'd)
vivus has left #crystal-lang [#crystal-lang]
<FromGitter> <bew> No, not from Crystal
<FromGitter> <bew> It would be the responsability of the GC to do that, but as explained before it is very difficult
<FromGitter> <Dillybob1992> i see, yeah was just thinking of finalize never saw that until now :O
DTZUZU has joined #crystal-lang
<FromGitter> <Dillybob1992> kemal looks so gooood http://kemalcr.com/guide/#http-parameters, look how easy it is to setup SEO urls
<FromGitter> <Dillybob1992> i want to switch to it, but need to re-write fluxbb in crystal, however should be really fun
greengriminal has quit [Quit: This computer has gone to sleep]
<FromGitter> <marksiemers> Is there a style preference for a class or module name for email? ⏎ `Email` vs `EMail` ?
<FromGitter> <marksiemers> I don't see it mentioned here: https://crystal-lang.org/docs/conventions/coding_style.html
alex`` has quit [Ping timeout: 256 seconds]
qard has joined #crystal-lang
alex`` has joined #crystal-lang
ua has joined #crystal-lang
ua_ has quit [Ping timeout: 248 seconds]
qard has quit [Quit: qard]
<FromGitter> <PlayLights_twitter> Why would be EMail?
<FromGitter> <codenoid> cuz he from kwnofguc land
<FromGitter> <codenoid> i prefer Email
<FromGitter> <codenoid> it's more beautiful
<FromGitter> <marksiemers> I was reviewing a PR and the author has `EMail` and another reviewer asked if it should be `Email`. I think `Email` looks better but I wanted to see if there was a definitive answer. ⏎ If it were `ElectronicMail` I would expect a capital 'M' and for other hyphenated words, I would expect camelcase: `StateOfTheArt`
<FromGitter> <marksiemers> So, I would guess the rule for hyphenated words is camelcase, but it doesn't look good for `EMail`.
<FromGitter> <codenoid> also `class Email` is more /ɛsˈθɛtɪks/
<FromGitter> <marksiemers> For the PR, before asking someone to change there code, I wanted to see if there was an agreed standard, so I could reference that, instead of just offering "I think `Email` looks better"
<FromGitter> <codenoid> +1 `class Email`
<FromGitter> <marksiemers> In the PR, it is actually used as a namespace, if that makes any difference: `EMail::Message.new`
<crystal-gh> [crystal] asterite closed pull request #5645: Class: add comparison operators (master...feature/class-comparison) https://git.io/vN1AU
<chaser93> is there any way to send an email with crystal? in ruby theres SMTP
dragonkh has joined #crystal-lang
<dragonkh> hi - if I have an instance of a class - and the class has an instance variable e.g. @name - is there any way I can get the content of the @name from the instance? e.g. myClass = MyClass.new ; puts myClass.instance_variables(:name) - or some such thing?
<dragonkh> oh - myClass.@name works
<FromGitter> <Dillybob1992> myClass.@name wat, looks like sorcery
<FromGitter> <Dillybob1992> til too :D
alex`` has quit [Quit: WeeChat 1.9]
<travis-ci> crystal-lang/crystal#bfd7c99 (master - Class: add comparison operators): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/334181583
chaser93 has quit [Ping timeout: 260 seconds]
<RX14> @Dillybob1992 it's "secret" syntax
<RX14> you're not meant to use it
<RX14> dragonkh, you shouldn't use that
<RX14> why not just use a getter?
<FromGitter> <Dillybob1992> "secret syntax"? got any more sauce on that
<RX14> @Dillybob1992 no because it's undocumented
<RX14> and you should *never* use it
<dragonkh> oh dear
<RX14> you 100% of the time want to define a getter
<FromGitter> <Dillybob1992> :(
<dragonkh> well I just wanted to access it for testing purposes
<RX14> not break the protection of OO and manually reach into an object
<FromGitter> <Dillybob1992> i feel like a cool hippy when i use sorcery code though
<RX14> dragonkh, that's one of the few times where it's acceptable
<FromGitter> <Dillybob1992> lolz
<RX14> you really need to print an ivar for puts debugging
<RX14> thats fair enough
<RX14> but never actually commit that code
<RX14> @Dillybob1992 debugging code is swice as hard as writing it
<RX14> so if you write code that you're just about smart enough to understand
<RX14> you'll need someone twice as smart as you to debug it
<RX14> so don't
<RX14> write simple and easy to understand code
<dragonkh> I really agree on that point
<dragonkh> engineers love to "engineer" solutions hehe
<FromGitter> <Dillybob1992> i agree...
greengriminal has joined #crystal-lang
greengriminal has quit [Client Quit]
<FromGitter> <jwaldrip> What happens if I set a version in my shard.yml that does not match the tag?
<RX14> stuff breaks
<RX14> "undefined behaviour"
<FromGitter> <jwaldrip> figured it wasn't good.
<RX14> ideally it'd just error out
<FromGitter> <watzon> Is it possible to fork a process by pid? Or to convert a process not created by Crystal to an instance of `Process`?
<frojnd> Was just wondering... is there a nice way to populate an array into hash in crystal? Like in ruby I would do smth like this: Hash[["A","B","C"].map.with_index.to_a] and I would get following hash: {"A"=>0, "B"=>1, "C"=>2} Is there any one liners for crystal?
<RX14> not really
<RX14> the types don't work out
<RX14> you can do
<RX14> Hash.zip(arry, array.each_index.to_a) though
<RX14> and that will get you an identical result
<frojnd> Thanx, gonna read .zip method now
<RX14> it takes two arrays
<RX14> so Hash.zip(a, b)
<RX14> you get {a[0] => b[0], ...}
<frojnd> That's exactly what I need
<oprypin> >> ["A","B","C"].each_with_index.to_h
<FromGitter> <jwaldrip> That being said a constructor from hash would be nice
<frojnd> When will fuzzy searchbe pushed? :)
<RX14> oprypin, bot'd dead
<RX14> @jwaldrip it could only deal with tuples
<FromGitter> <jwaldrip> y?
<RX14> @frojnd, it's in master
<oprypin> frojnd, https://carc.in/#/r/3grf
<oprypin> RX14, it's not fuzzy tho
<FromGitter> <jwaldrip> We have Hash.to_a right?
<RX14> @jwaldrip otherwise the keys and values would always be the same type
<RX14> oprypin, yes it is
<frojnd> oprypin: thanx
<oprypin> RX14, it's not fuzzy tho
<RX14> huh
<RX14> no it's not
<RX14> i thought it was
<RX14> that sucks
<RX14> it's still far far better than before
<frojnd> We used something like elastic search :p
<RX14> imagine having to set up elasticsearch
<RX14> it keeps me up at night
<RX14> most of those ""enterprise"" java applications tbh
<RX14> they always make it so much jarder than `java -jar Foo.jar`
<RX14> ...
<frojnd> hehe
<RX14> pun was a typo
<RX14> but a fortunate one
<FromGitter> <imonmyown> guys timezone everyone
<FromGitter> <imonmyown> what's the right way to run specs without launching the application?
<oprypin> frojnd, anyhow, you can use the new search in https://crystal-lang.org/api/master/
<RX14> @imonmyown put your startup code in a `MyApp.run` method
<RX14> have a file with the contents
<RX14> `require "./my_app"; MyApp.run`
<oprypin> imonmyown, never have the main file required when running specs
<RX14> and then that's your compile target
<RX14> then don't require that file when running specs
<frojnd> oprypin: thanx, it's way better now
<FromGitter> <imonmyown> @RX14 @oprypin thanks guys
<FromGitter> <Dillybob1992> https://github.com/kostya/benchmarks
<FromGitter> <Dillybob1992> brainf-word demo, crystal is a monster
<FromGitter> <Dillybob1992> and rank 2-3 in most others too. wtf is kotlin btw?
<FromGitter> <watzon> Kotlin is a language that runs on the JVM
<FromGitter> <imonmyown> one of officials for android
<FromGitter> <j8r> made by JetBrains, named from a russian city
<FromGitter> <watzon> Much better language than Java
<FromGitter> <watzon> But still runs on the JVM, so not really for me
<FromGitter> <Dillybob1992> thx, never heard of it until now
alex`` has joined #crystal-lang
<FromGitter> <imonmyown> guys if I use a generic class, say SomeClass(T), and if T is either Float32 or Float64, how do I specify a suitable T of zero?
<oprypin> imonmyown T.zero maybe
<FromGitter> <imonmyown> wow, it worked
<FromGitter> <imonmyown> thanks
<FromGitter> <imonmyown> well, you can't expect `one`, I guess :\
<FromGitter> <imonmyown> but then, seems that I don't need it
<RX14> @imonmyown you can
<RX14> the generic way for any number is
<RX14> T.new(1)
<RX14> all Int types have constructors accepting arbitrary Int
<RX14> .zero is nice but .new(5) works for all int types
<FromGitter> <imonmyown> @RX14, that is like amazing
<FromGitter> <imonmyown> I remember troubles with that in rust
<RX14> it's really simple lol
<RX14> just
<RX14> struct Int32; def self.new(int : Int); int.to_i32; end; end
<RX14> for all int types
<RX14> and the problem is solved
<FromGitter> <imonmyown> right, cool
<RX14> and thats built into the stdlib
<FromGitter> <imonmyown> you guys were talking about a GC, did you mean a parallel version if rust is considered?
<RX14> rust wouldn't make a difference to if its parallel or not...
<RX14> also it's extremely unlikely to be in rust
<RX14> it'll be written in boring old C
<RX14> because its boring
<RX14> and thats good
<FromGitter> <imonmyown> yeah :)
<FromGitter> <imonmyown> so some other than Boehm?
<FromGitter> <Dillybob1992> i tried rust, but went back to crystal :O
<oprypin> imonmyown, fun fact you could have clicked View source for .zero https://github.com/crystal-lang/crystal/blob/80a975cf0a98a4ce8464d0069145131667becd70/src/number.cr#L7
<FromGitter> <faustinoaq> > so some other than Boehm? ⏎ ⏎ @imonmyown check this https://github.com/ysbaddaden/gc
theTypeReducer45 has joined #crystal-lang
<FromGitter> <Dillybob1992> what's differences between that and boehms?
<FromGitter> <imonmyown> @oprypin seems like I need to learn to dig deepeer :shipit:
<RX14> @Dillybob1992 ysbddaden's one is extremely extremely unfinished
<RX14> so there's that
<RX14> but eventually *if* the new gc reaches full maturity
<RX14> it should be faster and precise
<FromGitter> <Dillybob1992> so crystal will become even faster possibly?
<RX14> yeah
<RX14> likely
<RX14> it's extremely likely that crystal will get faster
<FromGitter> <j8r> We are talking about the GC, so mostly for tasks requiring the GC extensively
<RX14> so
<RX14> most of them
<RX14> lol
<RX14> seriously
<RX14> you'd be very surprised
<FromGitter> <j8r> Indeed haha
<FromGitter> <Dillybob1992> i look through that github repo and i have no idea what any of that c code means, i feel really dumb
<FromGitter> <Dillybob1992> now, thanks
<FromGitter> <j8r> The use of a GC in Rust is optional, right?
<RX14> rust doesn't really have GC support
<RX14> there's a Rc box type I think
<RX14> but thats it
<FromGitter> <imonmyown> that's a design decision
<RX14> yep
<FromGitter> <j8r> It can handle OO without having a GC, we need to unfree manually so?
<FromGitter> <j8r> hum free
<FromGitter> <imonmyown> it checks for those things with lifetimes during compile time
<FromGitter> <Dillybob1992> i want to try rust again just for fun now
<FromGitter> <Dillybob1992> but i relly ike crystal...
<FromGitter> <imonmyown> so you have to specify lifetimes in certain complex cases when you need extra speed
<FromGitter> <imonmyown> (so to speak)
<FromGitter> <imonmyown> but you can do without them generally
<FromGitter> <imonmyown> with some extra cost
<FromGitter> <j8r> Why no Crystal do this, and get rid of tge GC? I suppose this can lead to even further performances
<FromGitter> <Dillybob1992> i have never seen that line of code before, wtf is ()() do
<FromGitter> <imonmyown> the language will become a pain in the ass
<RX14> @j8r because it requires those specific annotations
<FromGitter> <j8r> ho weird :/
<FromGitter> <imonmyown> like rust is at times
<RX14> it's like
<RX14> it's a very difficult and new concept for most people
<RX14> the ideal of crystal is to make the developer feel free
<RX14> THEN make them feel safe
<RX14> THEN optimize that as much as we can
<RX14> rust takes the approach of saying: "we CANT have a gc, we can't have a runtime, we must be embedable like C, how do we make thats afe"
<RX14> and lifetime annotations are what the came up with
<RX14> Crystal is an applications programming language
<RX14> Rust is a systems programming language
<RX14> they are for differenct things
<RX14> I wouldn't write a webapp in Rust
<RX14> I wouldn't write a dynamic library or kernel in Crystal
<RX14> it's just design decisions
<FromGitter> <Dillybob1992> what about a game server in rust?
<FromGitter> <j8r> You're right +1
<RX14> and as a side note, I'd still use crystal instead of ruby if crystal was slower than ruby
<RX14> because I wouldn't care
<RX14> its a better designed language
<RX14> @Dillybob1992 it's probably equally applicable to both
<FromGitter> <j8r> and if there is a problem, you can eventually fix it :)
<FromGitter> <Dillybob1992> man, i have to do `println!` each time WTF
<FromGitter> <Dillybob1992> compared to just p or puts
<FromGitter> <Dillybob1992> .........
<RX14> do you do that often?
<FromGitter> <Dillybob1992> yeah lol i like to print stuff all the time :O
<FromGitter> <imonmyown> @Dillybob1992 when clearing your earwax? ;)
<FromGitter> <Dillybob1992> ear endoscope arriving on 29th :D
<FromGitter> <Dillybob1992> gonna get all dem ear waxes out :)
<FromGitter> <imonmyown> you'll be clean soon :)
<FromGitter> <Dillybob1992> crystal clean
<FromGitter> <imonmyown> yeah
<FromGitter> <Dillybob1992> hahahaha
<RX14> did I really need to know about this?
<RX14> I'm glad i've already had dinner
<FromGitter> <Dillybob1992> 😄
theTypeReducer45 has quit [Ping timeout: 260 seconds]
alex`` has quit [Quit: WeeChat 1.9]
<FromGitter> <bew> Does anyone know the llvm triple to compile to AVR? I'm trying to do fancy stuff but can't get the triple to compile anything.. :(
<RX14> a) LLVM might not even have avr support
<RX14> b) crystal doesn't support it
<RX14> c) it's impractical to port crystal to it
<RX14> like 100% impractical
<FromGitter> <bew> a) it does, it has been added some time ago, and merged to master
<FromGitter> <bew> b,c) it's just an experiment
<FromGitter> <bew> http://lists.llvm.org/pipermail/llvm-dev/2016-November/107177.html (quote: The AVR backend has now finally been merged in-tree completely.)
<RX14> the triple is just "avr"
<RX14> it's not even a triple
<RX14> it's just "avr"
<FromGitter> <bew> wut, weird ^^ where did you found that?
<RX14> you realise you're going to have to modify the compiler right?
<RX14> the only reason windows worked without a compiler mod was because we already target x86
<RX14> changinc CPU architecure requires entirely new code
<FromGitter> <bew> cool, more things to learn :P
<FromGitter> <bew> you mean that the ABI will need to be changed?
<FromGitter> <bew> is there sth else?
<RX14> the -triple arg to clang
<FromGitter> <bew> thanks!
<FromGitter> <bew> RX14 do you know what kind of changes I would need to do to the compiler? (if I ever work on this)
<RX14> @bew yeah
<RX14> look at the arm PR that ysbaddaden made
<RX14> and extrapolate from that
<FromGitter> <bew> good idea! thanks
moei has quit [Quit: Leaving...]