ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.23.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
hightower3 has joined #crystal-lang
hightower4 has quit [Ping timeout: 240 seconds]
<FromGitter> <martinos> I have another question, is it possible to create an identity lambda in Crystal ?
vikaton has joined #crystal-lang
rohitpaulk has joined #crystal-lang
maxpowa has quit [Ping timeout: 240 seconds]
maxpowa has joined #crystal-lang
_whitelogger has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 248 seconds]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 246 seconds]
snsei has joined #crystal-lang
<watzon> What's the easiest way to turn `HTTP::Params` into JSON? Using `to_json` keeps giving me `no overload matches 'HTTP::Params#to_json' with type JSON::Builder`
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
<FromGitter> <jasonrobot> @watzon checkout the JSON.mapping macro ⏎ https://crystal-lang.org/api/0.23.1/JSON.html#mapping-macro
<FromGitter> <jasonrobot> that will define the overload that the compiler is complaining about not finding
<FromGitter> <jasonrobot> as well as a bunch of other useful methods too. It's rad. (There's also a DB.mapping macro for DBs too)
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 248 seconds]
rohitpaulk has joined #crystal-lang
snsei has joined #crystal-lang
<watzon> @jasonrobot already used `JSON.mapping`. That's how I got `to_json` on my model
<watzon> I think I figured it out though. I had to do `params.to_h.to_json`
<FromGitter> <jasonrobot> Oh I see! Ya my mistake, misread that.
<FromGitter> <jasonrobot> That is cool to know though, params.to_h.to_json . I'll probably need that soon...
<watzon> It's a pain in the butt though. It would be nice to be able to skip over `to_h`
<watzon> Now I have another issue. Does anyone know of a good example of a converter being used with `JSON.mapping`? I need to take a `String` and convert it into an `Int32` in a couple places.
<watzon> It seems like the type of converter that would exist in the standard library already
alex`` has joined #crystal-lang
<FromGitter> <crisward> G
<FromGitter> <imonmyown> @crisward G for good morning? :)
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
<FromGitter> <crisward> It turns out you can type on your phone by just looking at it. But hey, why not, Good morning. 😆
DTZUZU2 has joined #crystal-lang
snsei has quit [Remote host closed the connection]
DTZUZU2 has quit [Quit: WeeChat 1.7]
DTZUZU2 has joined #crystal-lang
<FromGitter> <Azphreal> I'm trying to do a fairly basic networking exercise for a course that tries to distribute a `max` function around a ring network. I'm using `TCPServer`s to listen and `TCPSocket`s to connect to the next in the ring. Currently I'm unable to start a single node, because it attempts to connect to the next in the ring, and immediately fails because it can't connect. How do I retry on a failed connection?
snsei has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 252 seconds]
mark_66 has joined #crystal-lang
claudiuinberlin has joined #crystal-lang
vikaton has quit [Quit: Connection closed for inactivity]
snsei has quit [Remote host closed the connection]
<FromGitter> <crisward> @Azphreal perhaps begin / rescue - sleep in a loop ?
snsei has joined #crystal-lang
<FromGitter> <GrgDev> Is there a standard convention for how many characters per line with Crystal? Does it default to Ruby conventions?
snsei has quit [Remote host closed the connection]
claudiuinberlin has quit [Ping timeout: 240 seconds]
baweaver is now known as baweaver_away
<FromGitter> <Azphreal> @crisward Thanks, that worked. I thought it would but it wasn't working. Turns out I was doing my concurrency wrong too, so it was just ending after the first `rescue`.
<watzon> Anyone here have experience with amber?
<watzon> I know that @faustinoaq and @elorest have contributed to its development
<FromGitter> <Papierkorb> @GrgDev No other convention. I'm not even aware of a convention for line lengths in ruby code. I stick to what I did over there though: 80 chars hard limit for docs, 100 chars soft limit for code, 120 chars hard limit for code. Served me well up to now
<FromGitter> <sdogruyol> mornin everyone
<FromGitter> <petoem> good morning
rohitpaulk has joined #crystal-lang
<FromGitter> <straight-shoota> good morning =)
<FromGitter> <alex-lairan> Hi :)
rohitpaulk has quit [Ping timeout: 255 seconds]
thews has quit [Ping timeout: 248 seconds]
Yxhuvud has quit [Remote host closed the connection]
Yxhuvud has joined #crystal-lang
rohitpaulk has joined #crystal-lang
<FromGitter> <DRVTiny> Who knows, how to convert UInt8 to string "hex" representation of that UInt8?
<FromGitter> <DRVTiny> And yes, this will conversion be VERY quick with Intel MMX, because there is special instruction for that
<FromGitter> <bew> Wut
<FromGitter> <bew> What do you mean exactly?
<FromGitter> <asterite> to_s(16)?
<FromGitter> <DRVTiny> @bew Unpack byte with value 255 to "FF"
<FromGitter> <iambudi> Is nil in crystal similiar to null in other programming language?
<Yxhuvud> yes
<FromGitter> <iambudi> So there would be a case nil exception error runtime?
<Yxhuvud> except that it is not an alias for 0 which null often is
<Yxhuvud> iambudi: it can happen, but usually the type checker catches that kind of error. nil is a separate type and not just the lack of value.
thews has joined #crystal-lang
thews has quit [Changing host]
thews has joined #crystal-lang
tilpner has quit [Read error: Connection reset by peer]
<FromGitter> <DRVTiny> ```code paste, see link``` ⏎ ⏎ How is that? Why 255 is Int32??? [https://gitter.im/crystal-lang/crystal?at=59e5e1b7bbbf9f1a386fa052]
tilpner has joined #crystal-lang
<FromGitter> <DRVTiny> 1) to_u8 ? :)
<FromGitter> <DRVTiny> It's awful
<FromGitter> <DRVTiny> Oh, yes ⏎ ⏎ ```icr(0.23.1) > a=255.to_u8 ⏎ => 255``` ⏎ ⏎ Type inference is SO type inference [https://gitter.im/crystal-lang/crystal?at=59e5e209177fb9fe7e8bd29b]
<FromGitter> <DRVTiny> Wow, it works: a.to_s(16)
<FromGitter> <DRVTiny> How to calculate md5sum for file in Crystal? It is simple! ⏎ ⏎ ```OpenSSL::MD5.hash(File.read("/etc/fstab")).map{|b| b.to_s(16)}.join("")``` [https://gitter.im/crystal-lang/crystal?at=59e5e339bbbf9f1a386fa8d0]
<FromGitter> <asterite> Simpler: ⏎ ⏎ ```require "digest/md5" ⏎ p Digest::MD5.hexdigest(File.read("/etc/fstab"))``` [https://gitter.im/crystal-lang/crystal?at=59e5e3c6210ac26920f7ce67]
<FromGitter> <Papierkorb> @DRVTiny `255u8` reading the docs tend to help.
<FromGitter> <Papierkorb> `Slice#hexstring` is also a thing
<FromGitter> <Papierkorb> You choosing the hardest way to do things isn't Crystals fault
livcd has quit [Quit: Changing server]
livcd has joined #crystal-lang
tilpner has quit [Remote host closed the connection]
<FromGitter> <zyriuse75> hi
tilpner has joined #crystal-lang
<FromGitter> <asterite> hello
<FromGitter> <DRVTiny> @Papierkorb Could you explain me, how can i find this in the docs?
<FromGitter> <DRVTiny> I mean: how can i find the answer for my question. I am not developer of Crystal itself and can't remember all methods of all classes. With substring "hex" i can find "hexdump" in api. Its absolutely not my case. Where is "hexstring" mathod in search results? What i do wrong?
<FromGitter> <asterite> I don't think you are doing anything wrong, the docs are not the best ones and we are missing a better search
<FromGitter> <DRVTiny> @Papierkorb >255u8 reading the docs tend to help. ⏎ This is very annoying syntax. It is absolutely obvious that a=255 means a=(1 byte) 255 if i explicitly define that a is Uint8. It works in C. Why this doesnt work in Crystal?
<FromGitter> <DRVTiny> Crystal is simpler than C, but a=255u8 instead of a=255.
<FromGitter> <DRVTiny> @asterite ⏎ ⏎ Thanks for Digest::MD5 answer!
rohitpaulk has quit [Ping timeout: 240 seconds]
alibby has joined #crystal-lang
alibby has left #crystal-lang [#crystal-lang]
<FromGitter> <asterite> It's because in Crystal using a : UInt8 is not common (actually discouraged), and it's usually simpler to just write a = 255_u8
rohitpaulk has joined #crystal-lang
<FromGitter> <ansarizafar> @jasonrobot Is there any DB.mapping example available?
rohitpaulk has quit [Ping timeout: 248 seconds]
ShalokShalom_ has joined #crystal-lang
ShalokShalom has quit [Ping timeout: 240 seconds]
flaviodesousa has quit [Quit: KVIrc 4.2.0 Equilibrium http://www.kvirc.net/]
rohitpaulk has joined #crystal-lang
<FromGitter> <DRVTiny> @asterite And than write a=16_u8, and after that - a=197_u8 ... etc?
<FromGitter> <DRVTiny> This is unobvious obstructed semantic
ShalokShalom_ is now known as ShalokShalom
<FromGitter> <asterite> Yes, it's a current limitation of the language
<FromGitter> <asterite> Eventually we'll implement this if possible: https://github.com/crystal-lang/crystal/issues/2995
snsei has joined #crystal-lang
<crystal-gh> [crystal] asterite opened pull request #5135: Semantic: don't combine union of Number and Number subclass into Number (master...bug/5073-union-of-numbers) https://git.io/vdSXp
rohitpaulk has quit [Ping timeout: 260 seconds]
<crystal-gh> [crystal] asterite opened pull request #5137: XML: missing forwarding of `variables` argument (master...bug/5063-xml-variables) https://git.io/vdSDm
rohitpaulk has joined #crystal-lang
<crystal-gh> [crystal] asterite opened pull request #5138: Codegen: don't assign yield exp to underscore block arguments (master...bug/block-arg-underscore) https://git.io/vdS9z
<crystal-gh> [crystal] asterite closed pull request #5135: Semantic: don't combine union of Number and Number subclass into Number (master...bug/5073-union-of-numbers) https://git.io/vdSXp
<FromGitter> <faustinoaq> > I have another question, is it possible to create an identity lambda in Crystal that would work for all types ? I tried `id = -> (a) { a }` but it doesn't work since I need to specify a type for the param. ⏎ ⏎ @martinos I think isn't possible on Crystal, as far I know only `def` and `macros` can work without type annotation
<FromGitter> <GrgDev> @Papierkorb Why the difference in length between the doc limit and the code soft limit?
rohitpaulk has quit [Ping timeout: 258 seconds]
snsei has quit [Remote host closed the connection]
mark_66 has quit [Remote host closed the connection]
<FromGitter> <martinos> @faustinoaq, thanks, I was hoping that it was possible.
<FromGitter> <GrgDev> Also, different code convention question: Is emoji in code strings like this acceptable? https://github.com/diasks2/pragmatic_tokenizer/blob/master/lib/pragmatic_tokenizer/languages/common.rb#L5
<Yxhuvud> martinos: What would you want it for? Be aware that whatever would try to use it would also have to handle all types that matches the type signature.
<Yxhuvud> you can have it return a Reference or whatever, but you'd also be restricted to only the mehtods a Reference has. Which is probably not enough.
<crystal-gh> [crystal] asterite pushed 2 new commits to master: https://git.io/vdSdn
<crystal-gh> crystal/master 181986d Ary Borenszweig: Merge pull request #5135 from asterite/bug/5073-union-of-numbers...
<crystal-gh> crystal/master e1aa6c0 Ary Borenszweig: Semantic: don't combine union of Number and Number subclass into Number
lacour has joined #crystal-lang
<travis-ci> crystal-lang/crystal#181986d (master - Merge pull request #5135 from asterite/bug/5073-union-of-numbers): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/289094189
<DeBot_> https://github.com/crystal-lang/crystal/pull/5135 (Semantic: don't combine union of Number and Number subclass into Number)
rohitpaulk has joined #crystal-lang
<FromGitter> <martinos> @ Yxhuvud, I have a method that requires a proc as a parameter to do a transformation on an object. In some case I want to not transform the object, so I would simply pass it an identity function.
<FromGitter> <bew> @martinos or I think you could just add a method without the proc argument that won't do any transformation ?
<FromGitter> <Papierkorb> @GrgDev That's because docs are usually read in their entirety, and more often than not, you can't split them into chunks to consume at a time without having read them entirely. So I'm forcing a 80char limit there as I found that to fit on most screens, and to be a good width so you don't have to move your eyes too much (causing strain, wasting time), and never have to scroll horizontally (Or have awkward
<FromGitter> ... soft line breaks). Code on the other hand is more easily split into sections to digest individually, and make sense on their own. So the time wasted on moving yourself is negligible compared to the time you spend actually figuring out what's going on
<FromGitter> <Papierkorb> @GrgDev This also takes into account that you could scroll horizontally for a block of code without confusing you too much. That however would be the case for docs, as by scrolling, you basically hide the exterior code structure, which would make it much harder to get a grasp on. For methods, this is fine. Doesn't mean however that it's great if you have to scroll horizontally, the large buffer from 100 to
<FromGitter> ... 120 chars is just there to avoid most awkward line breaks you sometimes have to do.
rohitpaulk has quit [Ping timeout: 264 seconds]
<FromGitter> <martinos> @bew , was just trying to simplify my explanation the issue is more complicated it fact. I have a big list of tuples (String, Int64, Proc(String, String)), and I apply these 3 params to a method. I wanted to keep the code as simple as possible, the identity function was the obvious choice.
<FromGitter> <Papierkorb> And in the end, it served me well for the past 3-ish years I've been doing it like this. I even started to put two spaces after a sentence ending marker (. ! ?) in docs to further help navigating them visually quickly. This also helps doing a quick "audit" if your sentence get too long or too short. Though I guess this might be rather subjective.
<FromGitter> <coderhs> Hey there. Whats the equivalent of `object.send` in crystal? I tried `Time.now.send.("sunday?")` and it said send doesn't exist.
<FromGitter> <Papierkorb> @GrgDev In the end, do it how you like it best, as long you're consistent about it :)
<FromGitter> <Papierkorb> @coderhs No, doesn't exist, and most likely, never will
<FromGitter> <coderhs> @Papierkorb any other methods or way in which I could achieve the same?
<FromGitter> <coderhs> I wan to pass in the method name dynamically
<FromGitter> <Papierkorb> A `case` statement is a popular choice
<FromGitter> <Papierkorb> Make sure you actually need this.
<FromGitter> <Papierkorb> What's your use-case?
<FromGitter> <coderhs> to find the next sunday or monday based on today.
<FromGitter> <coderhs> i was going to add 1.day in a loop until it find the next sunday
<FromGitter> <coderhs> the day of the week will be passed dynamically.
<FromGitter> <Papierkorb> That sounds like a use-case where even in Ruby, send would be not a good choice.
<FromGitter> <bew> @martinos hmm you could also just pass nil in the tuple, and in the method just check for the '
<FromGitter> <bew> nil-ness'
<FromGitter> <coderhs> okay. @Papierkorb will go with that now. Thank you.
<FromGitter> <Papierkorb> @coderhs Use a `case` statement, and use an `Enum` over matching random strings
<FromGitter> <GrgDev> Is there a way to split a regex literal into multiple lines if it is really long?
<FromGitter> <martinos> @GrgDev, can you create sub patterns?
<FromGitter> <GrgDev> probably, just going to be annoying. going to try throwing in a free spacing mode flag instead
<vegai> just looked at the Granite ORM
<vegai> I'm liking this a lot
<vegai> reminds me of Zend1 in all the good ways
<FromGitter> <aarongodin> @GrgDev ⏎ ⏎ ```a = Regex.new(<<-BOOP ⏎ [a-z]? ⏎ BOOP)``` [https://gitter.im/crystal-lang/crystal?at=59e63d34e44c43700a4532e3]
<vegai> simple things are easy for everything else you just drop down to SQL
DTZUZU2 has quit [Ping timeout: 248 seconds]
<FromGitter> <GrgDev> Okay, found my issue, you can break it into newlines, but I accidentally threw a newline into the middle of a range declaration in my regex which is a no-no
<FromGitter> <asterite> GrgDev: you can use /regex/x
<FromGitter> <GrgDev> Yeah, that's what I went with
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 255 seconds]
claudiuinberlin has joined #crystal-lang
sz0 has quit [Quit: Connection closed for inactivity]
wontruefree has joined #crystal-lang
<crystal-gh> [crystal] asterite pushed 1 new commit to master: https://git.io/vd9Oj
<crystal-gh> crystal/master a6ddeb3 Ary Borenszweig: Merge pull request #5138 from crystal-lang/bug/block-arg-underscore...
wontruefree has quit [Ping timeout: 248 seconds]
claudiuinberlin has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
DTZUZU2 has joined #crystal-lang
claudiuinberlin has joined #crystal-lang
rohitpaulk has joined #crystal-lang
<travis-ci> crystal-lang/crystal#a6ddeb3 (master - Merge pull request #5138 from crystal-lang/bug/block-arg-underscore): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/289159539
<DeBot_> https://github.com/crystal-lang/crystal/pull/5138 (Codegen: don't assign yield exp to underscore block arguments)
DTZUZU2 has quit [Quit: WeeChat 1.7]
rohitpaulk has quit [Remote host closed the connection]
claudiuinberlin has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<FromGitter> <Papierkorb> You could also write `%r{...}x`, maybe that's easier to see if it's multiline
<FromGitter> <Papierkorb> Oh that message is already 1.5hrs old >_>;
claudiuinberlin has joined #crystal-lang
<FromGitter> <GrgDev> No worries, but I don't think anything can make this regex look pretty
<FromGitter> <GrgDev> I am porting this gem over and it has this emoji regex https://github.com/diasks2/pragmatic_tokenizer/blob/master/lib/pragmatic_tokenizer/languages/common.rb#L12
<FromGitter> <GrgDev> I mean, converting it is easy. Just replace the `\u`s with `\x`s, but the size of it...
alex`` has quit [Ping timeout: 246 seconds]
claudiuinberlin has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<FromGitter> <asterite> You could also insert the emojis themselves instead of using \u
claudiuinberlin has joined #crystal-lang
baweaver_away is now known as baweaver
<crystal-gh> [crystal] asterite opened pull request #5139: HTTP::Client: use required named argument `form` instead of post_form and put_form (master...refactor/5136-http-client-post-form) https://git.io/vd9R0
claudiuinberlin has quit [Quit: Textual IRC Client: www.textualapp.com]
<FromGitter> <krypton97> Can crystal be used without a garbage collector? Using sonething like free()?
<FromGitter> <Papierkorb> Technically, yes it can. Practically speaking, no.
<FromGitter> <GrgDev> I... I don't know how I feel about putting raw emojis into regexs. I see no technical reason not to, but it seems wrong on principle.
<FromGitter> <drosehn> I 'd be reluctant to, because there are still times when I'm editing source code using `vi` over an ssh connection. 😄 I probably wouldn't be doing that on a tokenizer though!
snsei has joined #crystal-lang
<FromGitter> <drosehn> I have some absurdly long regex's, and I create those by using Regex.new and standard double-quoted string constants.
<FromGitter> <drosehn> ```test_rex = Regex.new( "this\\s+" + ⏎ "string", ⏎ Regex::Options::EXTENDED);``` [https://gitter.im/crystal-lang/crystal?at=59e6837a01110b7231cb5c8d]
<FromGitter> <drosehn> It's a bit of a pain because you have to remember the different rules for string-constants vs regex constants. The need to use `\\s` instead of `\s`, for instance.
snsei has quit [Remote host closed the connection]
bmcginty has quit [Ping timeout: 260 seconds]
bmcginty has joined #crystal-lang
jackivan88 has quit [Ping timeout: 240 seconds]
<FromGitter> <imonmyown> For those who understand I want to thank turkish guys for their generosity
dhk has joined #crystal-lang