ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.23.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
<FromGitter> <johnjansen> im an idiot … you need `order_response["location”].not_nil!.as_i` i think
<FromGitter> <renich> ... didn't quite understand. Where should I have that?
<FromGitter> <renich> Oh, don't worry, I am the idiot here, hehehe.
greengriminal has quit [Quit: This computer has gone to sleep]
<FromGitter> <johnjansen> or you could fix the source of the issue ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=595989ad703e565c33692752]
<FromGitter> <johnjansen> note my comment # WHAT HAPPENS IF THIS IS FALSE????
<FromGitter> <renich> oh!
<FromGitter> <renich> Let me try that.
<FromGitter> <johnjansen> this method can return `nil` so as a result you cannot guarantee that the hash is a hash, it could be nil
<FromGitter> <renich> don't know quite what to do... raise an exception if not?... I wish there was more API consuming code available
<FromGitter> <renich> return false maybe?
<FromGitter> <johnjansen> line 55 in test ⏎ ⏎ order_response = nh[:rw].create_order(order)
<FromGitter> <renich> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=59598abf8dae4250317977bd]
<FromGitter> <renich> trying what you pasted
<FromGitter> <renich> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=59598b92c101bc4e3a44b0f2]
<FromGitter> <johnjansen> crap `nil?`
<FromGitter> <johnjansen> `return if order_response.nil?`
<FromGitter> <renich> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=59598c254bcd78af566bb9ee]
<FromGitter> <renich> order_response is what create_order returns. You want me to put this inside create_order?
greengriminal has joined #crystal-lang
<FromGitter> <johnjansen> man, never code on sundays ;-) ⏎ just get rid of that line
<FromGitter> <renich> OK, I changed it to exit 0 if order_response.nil?
<FromGitter> <renich> LOL
<FromGitter> <renich> yeah, I know. This is urgent...
<FromGitter> <johnjansen> you dont even need the line …
<FromGitter> <renich> OK
<FromGitter> <johnjansen> if it were inside a method, id return, but since you arent … dont
<FromGitter> <renich> Yes. OK, what about the new error... it doesn't like as_i
<FromGitter> <johnjansen> `to_i`
<FromGitter> <johnjansen> `to_s`
<FromGitter> <renich> ah! it worked!
<FromGitter> <renich> but the code looks awful. Why do we need the not_nil! thing?
<FromGitter> <renich> shouldn't I be able to dereference order_response["something"]
<FromGitter> <renich> ??
<FromGitter> <johnjansen> because the method `create_order` doesn’t always return a hash … it might return `nil`
<FromGitter> <renich> OK, so the key is to prevent it from doing that, right?
<FromGitter> <johnjansen> `not_nil!` yes … you should careful understand the return paths from `create_order`, you will see the problem if you carefully study it
<FromGitter> <renich> man, I am grateful. Thanks a lot. I've been stuck on this for a while... days...
<FromGitter> <renich> I need to make that thing return a simple Hash or a salvageable error
<FromGitter> <johnjansen> i have got into the habit of always specifying a return type on methods, so i know my code always returns what i expect … as such, you should add a return type to `create_order` so as to understand the problem
<FromGitter> <johnjansen> then `raise “HTTP ERROR” unless r.status_code == 200` and remove `if r.status_code == 200` in `create_order`
<FromGitter> <johnjansen> better still `raise “HTTP ERROR” unless r.success?`
<FromGitter> <renich> OK. thanks for the advice.
<FromGitter> <johnjansen> then you can ditch all the not_nil!
<FromGitter> <renich> wrapped in a try?
<FromGitter> <johnjansen> begin rescue ensure end
<FromGitter> <renich> yeah, got mixed with python for a while
greengriminal has quit [Quit: Leaving]
hightower3 has quit [Ping timeout: 260 seconds]
Philpax has joined #crystal-lang
qard has joined #crystal-lang
sz0 has joined #crystal-lang
<FromGitter> <elorest> @mverzilli Thanks.
Philpax_ has joined #crystal-lang
Philpax has quit [Ping timeout: 240 seconds]
_whitelogger has joined #crystal-lang
<FromGitter> <schoening> Following error with mongodb driver following the usage example:
<FromGitter> <schoening> http://i.imgur.com/IStVEWh.png
<FromGitter> <renich> Hello. I am building an app that consumes an API and tries to make decisions on the data it gathers. It should run in a loop and repeat the cycle every 5 mins or so. I am interesting in several things regarding this:
<FromGitter> <renich> Renich Bon Ciric @renich 00:51 ⏎ Hello. I am building an app that consumes an API and tries to make decisions on the data it gathers. It should run in a loop and repeat the cycle every 5 mins or so. I am interesting in several things regarding this: ⏎ ⏎ 1) Logging: how would you go about implementing logging, even in the library? ⏎ 2) Loop: what would be the best way to approach the loop part? Just
<FromGitter> ... write a loop and use sleep? ... [https://gitter.im/crystal-lang/crystal?at=5959db88703e565c336a3f9b]
txdv has joined #crystal-lang
hightower3 has joined #crystal-lang
hightower4 has quit [Ping timeout: 248 seconds]
hightower2 has joined #crystal-lang
qard has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
mark_66 has joined #crystal-lang
<FromGitter> <sdogruyol> hey everyone
<FromGitter> <bararchy> Sup @sdogruyol
<FromGitter> <sdogruyol> great @bararchy , how about you?
<FromGitter> <bararchy> @sdogruyol All good, working on my https://github.com/bararchy/crystal-fann project, it's getting along :)
<FromGitter> <sdogruyol> cool
<FromGitter> <sdogruyol> do you use it at work?
<FromGitter> <bararchy> Trying, still need to add more bindings, but the basic functionallity is working and I test around different Neural Network settings
<FromGitter> <bararchy> BTW , why does 32 is default Int32 but 0.1 is default Float64 ?
<FromGitter> <sdogruyol> isn't that normal?
<FromGitter> <sdogruyol> one is integer the other is float
<FromGitter> <bararchy> This is ok, I mean why Float64 and not default to Float32
<FromGitter> <sdogruyol> not sure but could be related to overflow
<FromGitter> <sdogruyol> i'm pretty sure @asterite knows why 0.1 defaults to Float64
<FromGitter> <bararchy> Becuase libfann expects Float32 I need to create data which is `[0.1_f32, 0.2_f32, etc...]`
Groogy has joined #crystal-lang
<FromGitter> <sdogruyol> ugh
<FromGitter> <sdogruyol> that's a bummer for performance
<FromGitter> <sdogruyol> does c defaults to 32 bit for floats?
<Groogy> yeah
<Groogy> double is 64
<FromGitter> <sdogruyol> good to know
<FromGitter> <sdogruyol> thanks
<Groogy> Though keep in mind of that precision on double and float is not fixed, we use our own fixed point implementation at work since we need to sync exact numerics over network between clients
<Groogy> if you are working with network it's a detail you don't want to discover late
<FromGitter> <sdogruyol> i'm kinda noob with that low level details
<FromGitter> <sdogruyol> thanks for letting me know @Groogy
<FromGitter> <bararchy> Yeha, thanks Groogy
<Groogy> no probs, I went through the pain of that and don't think anyone else should have to ;D
<FromGitter> <sdogruyol> i think the float64 default should be noted somewhere (wiki?) @bararchy
<Groogy> that crystal uses float64 by default? It does say it in the introduction documentation
<Groogy> I think
<FromGitter> <bararchy> Well, it's unexpected to be sure
<Groogy> yeah it can definetly have more visibility on it
<Groogy> it is going to take bunch of people of guard probably
<FromGitter> <bararchy> the thing is , the logic behind it is most likley valid for Int too, I think, so why not default Int to 64 as well ? \
<FromGitter> <bararchy> for consistency
<Groogy> Also chars being 4 bytes big caught me of guard :P
<Groogy> since I mainly work with c++ so
<Groogy> Int32 though is most of the time good enough for most of the things you do and it fits nicely into the registers if I remember correctly
<Groogy> double however uses floating point registers on the cpu instead
<Groogy> though 64bit cpu's I guess have larger registers
Qchmqs__ has joined #crystal-lang
Qchmqs__ is now known as Qchmqs
A124 has quit [Read error: Connection reset by peer]
A124 has joined #crystal-lang
<FromGitter> <bararchy> So, I got Array(Array(Float32)) ⏎ The C lib wants a Pointer(Pointer(Float32)), I can't get that to work normally
<FromGitter> <bararchy> Do I need to do .first.first or something and pass this pointer ?
<FromGitter> <bew> don't think you can do that
<FromGitter> <bew> because the `Array` instance is bigger than a pointer, the data you're looking for is not contiguous in memory
<Groogy> yeah you probably would have to go with ptr.malloc(size_of_crystal_array_memory) and copy it over
<Groogy> before passing it
hightower2 has quit [Ping timeout: 255 seconds]
<FromGitter> <bew> no need for malloc, you can do `your_array.map &.to_unsafe` to get an `Array(Pointer(Float32))`, then you can just pass this to the fun
<Groogy> ah cool
<FromGitter> <bew> the compiler will add the last `to_unsafe` on the array to get the `Pointer(Pointer(Float32))`
<Groogy> and that is guarranteed to be transformed so it is correct in memory as well?
<FromGitter> <sdogruyol> @groogy are you a C / C++ developer by day?
<FromGitter> <bararchy> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=595a02455a1ab55f644ca103]
<Groogy> By day I am a C++ programmer, by night I am a vigilante of modern languages
<FromGitter> <bew> it is
<FromGitter> <sdogruyol> @groogy wow, i'd really envy C / C++ people
<FromGitter> <sdogruyol> low level stuff
<FromGitter> <sdogruyol> must be more interesting than some web development stuff :P
<FromGitter> <bararchy> And my `Type = LibC::Float` is this
<FromGitter> <bew> so true @sdogruyol :p
<Groogy> Well you do until you become one with your soul drained ;D
<FromGitter> <sdogruyol> @bew right? :P
<FromGitter> <sdogruyol> @groogy soul drain? I assume you were a Warlock in World of Warcraft :D
<Groogy> No that's my boss
<Groogy> :PÅ
<FromGitter> <sdogruyol> hahaha
<FromGitter> <sdogruyol> in WoW when a Warlock soul drained a creature it'd gained a 'Soul Stone' :D
<FromGitter> <sdogruyol> good ol' days
<Groogy> Haven't played WoW in ages
<Groogy> my boss do actually play it pretty much everyday though
<FromGitter> <sdogruyol> same
<FromGitter> <bew> but there is something you need to not forget @bararchy the intermediate array you create with `...map &.to_unsafe` is the one that will be passed to the fun, but *it can be collected by the GC* so don't forget to save it somewhere in crystal-land to prevent GC collection
<FromGitter> <sdogruyol> seriously? :D
<Groogy> Yeah well it's a game company, everyone plays games here
<FromGitter> <sdogruyol> @bew wish we had a Crystal native-first GC of our own
<FromGitter> <sdogruyol> @groogy which company is it?
<Groogy> Paradox Interactive
<FromGitter> <sdogruyol> i'm sure i've heard that name before
<Groogy> well I am in Paradox Development Studios which make the internal strategy games
<FromGitter> <bew> nice!
<FromGitter> <sdogruyol> oh, Europa Universalis
<Groogy> Magicka, Cities Skylines, Europa Universalis 4(my current project), Crusader Kings 2(previous)
<Groogy> Yeah
<FromGitter> <sdogruyol> i've lost a significant part of my life to EU and games like that :P
<FromGitter> <sdogruyol> congrats on that @groogy :D
<Groogy> thanks
<Groogy> Well yeah I like to imagine myself as a crack dealer
<Groogy> "have a little taste" -> "500 hours later"
<FromGitter> <sdogruyol> hahaha
<FromGitter> <sdogruyol> @groogy what do you think of Crystal, can it handle your backend loads or replace some part of your C++ stack?
<Groogy> Don't know yet
<Groogy> Literally started this weekend so :D
<FromGitter> <sdogruyol> cool, hope we can help you on the way :)
<Groogy> but first of course it needs to work on Windows since that's the biggest market
<FromGitter> <sdogruyol> yeah
<FromGitter> <sdogruyol> that's why i said for backend :P
<Groogy> but usually I learn tons of cool things which I can then put into our code base
<Groogy> like Ruby style .each semantics I got into several logical things for us
<FromGitter> <sdogruyol> do you use boost with cpp?
<Groogy> like you have a country object, you want to iterate over all its cores, instead of fetching an array I implemented so you could do country.ForEachCore([](...))
<Groogy> which got inlined and used helpful structs so programmers could implement the logic in 3 lines
<FromGitter> <sdogruyol> wow, sounds really cool
mark_66 has quit [Remote host closed the connection]
<Groogy> nah we use only C++11, looking at C++14
mark_66 has joined #crystal-lang
<FromGitter> <bew> did you know there are coroutines in C++ ?
<FromGitter> <sdogruyol> so you're basically build a DSL for others' ease of use
<Groogy> Yeah
<Groogy> but they look super... eeeh
<Groogy> cumbersome to use
<Groogy> compared to other languages
<FromGitter> <sdogruyol> we have `spawn` :P
<FromGitter> <sdogruyol> super simple to use hehe
<FromGitter> <bew> ahah yes, I just found about it yesterday
<Groogy> Yeah, I find it if I make the logic clear and readable it makes the code base long liver
<Groogy> biggest opposition I got from the other seniors were that "it would make programmers lazy"
<Groogy> EXACTLY :D
<FromGitter> <bew> ahahah but WE ARE LAZY (in a certain sense)
<FromGitter> <sdogruyol> hahaha
<FromGitter> <sdogruyol> @groogy that's an interesting "Senior" way of seeing things
<Groogy> which part?
<FromGitter> <sdogruyol> "it would make programmers lazy"
<FromGitter> <sdogruyol> actually i was being sarcastic :P
<Groogy> ah well I'm simplifying the arguments but that's what it boiled down to. Essentially they were worried that people would do mistakes because they wouldn't know the underlying logic
<Groogy> while I was trying to prevent copy pasting problems
<FromGitter> <sdogruyol> @groogy that's a really low-level way of looking at things
<FromGitter> <sdogruyol> like everyone should know everything under the hood
<FromGitter> <sdogruyol> for high-level development that's the quite opposite
<Groogy> It's the c++ attitude in some circles I guess?
<FromGitter> <bew> IMO you should always knwo how work what you're using, either by recoding it, or understand it and explaining to someone else
<Groogy> Internet community around development have a very much "superiority" complex in certain things
<FromGitter> <sdogruyol> just use something and get the s**t done (without actually even knowing how it works)
<FromGitter> <bew> that last statement
<Groogy> I mean you should have a gist of kind of what it does but you don't need to understand underlying implementation
<FromGitter> <sdogruyol> @groogy agreed
<Groogy> I am looking forward on starting my hobbyproject in Crystal though
<Groogy> but yeah switching a whole company that has code worth of 15 year in C++ is not gonna happen :P
<FromGitter> <bew> Huh, why this lib: https://github.com/MakeNowJust/crake is not in http://crystalshards.xyz/?filter=crake ?
<FromGitter> <sdogruyol> @groogy yeah :)
<FromGitter> <sdogruyol> @bew hmm
<FromGitter> <sdogruyol> @bew is it inactive for more than 1 year?
<Groogy> what is it even?
<FromGitter> <bararchy> does shards.xyz is filtering out long sleeping repos ?
<Groogy> and yeah last commit is over a year ago
<FromGitter> <bew> :/
<FromGitter> <sdogruyol> yeah
<FromGitter> <sdogruyol> it doesn't list repos older than 1 years
<Groogy> anyway lunch
<FromGitter> <sdogruyol> it's implicit
<FromGitter> <sdogruyol> @groogy have a good lunch, me too
<FromGitter> <sdogruyol> guess you're from EU timezone
<Groogy> sweden yeah
<FromGitter> <bew> it's 11am for me, not lunch time yet ^^
<FromGitter> <bararchy> 12 noon here
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 260 seconds]
Raimondii is now known as Raimondi
<FromGitter> <sdogruyol> yeah, you're literally next to me :P @bararchy
<FromGitter> <bararchy> @sdogruyol Where are you at right now ?
<FromGitter> <bararchy> South America somewhere ?
<FromGitter> <sdogruyol> nope
<FromGitter> <sdogruyol> Istanbul
<FromGitter> <sdogruyol> aren't you from Tel Aviv?
<FromGitter> <bararchy> Close by, Hertzellia, it's like 10 min from there
<FromGitter> <sdogruyol> I'm really interested to visit and see there
<FromGitter> <sdogruyol> The culture interests me
<Groogy> @bew we have "workers lunch" so we eat at 11am here. I.e go out and eat before every single place is filled to max capacity
<FromGitter> <sdogruyol> 11am sounds too early
<Groogy> Well I've stopped having breakfast because of it xD
<FromGitter> <sdogruyol> makes sense :P
<Groogy> hope I get my new parts today so I can get cracking on getting Archlinux running at home again so I can play around all night with crystal :3
<FromGitter> <bararchy> @sdogruyol You are invited to visit :) tell me if you go we can meetup
<FromGitter> <sdogruyol> @bararchy thank you, i'd be happy to have a meetup / conf there :)
<FromGitter> <bararchy> @bew I still get errors: ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ So it seems the C lib isn't getting the data like it want's it, it thinks data is 0 so the array dosen't seem to be translating well [https://gitter.im/crystal-lang/crystal?at=595a117676a757f808ce61e7]
<Groogy> Can we see the code for where you build the pointer in question?
<FromGitter> <bararchy> This is the spec which produces this error: https://github.com/bararchy/crystal-fann/blob/master/spec/network_spec.cr#L72-L88
<Groogy> why do you enforce that data struct is a TrainData twice?
<Groogy> isn't that known by then for the compiler?
<Groogy> also what you give to the C function is the data_struct.input and data_struct.output right?
<FromGitter> <bararchy> Seems like it's not, because the return Type is `Pointer(TrainData | Nil)`
<FromGitter> <bararchy> Yeha, data_struct.input , etc..
<FromGitter> <bararchy> TBH the whole Struct
xiljin has joined #crystal-lang
<Groogy> and you have guarranteed it is the correct pointer you are sending to the actual function when you get to that point?
<FromGitter> <bararchy> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=595a1415bf7e6af22c9ad9de]
<FromGitter> <bararchy> Groogy: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=595a14378dae4250317b7444]
<FromGitter> <bararchy> btw, much thanks Groogy and @bew for the help :)
<Groogy> hmmm you are accessing the first element in the array and taking that ones size and then num_data is the top input_array's size
<Groogy> is that correct?
<Groogy> Don't know the underlying library so not 100% on what it expects
<Groogy> so it is saying that your num_data variable is zero while your neurons are 2?
<FromGitter> <bararchy> yeha
<FromGitter> <bararchy> as in, it thinks the Array is empty , or something
<FromGitter> <bararchy> I think
<Groogy> and if you do a puts(train_data.num_data) before you call the lib
<Groogy> what odes it say?
<Groogy> "The data inside this structure should never be manipulated directly, "
<Groogy> have you mapped the members correctly?
<FromGitter> <bararchy> Groogy ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=595a16bf8dae4250317b7e55]
<Groogy> hmm it says num_data = 4 so wonder why it thinks it iszero?
<Groogy> oh wait no it thinks there is zero neurons specified in the train data struct?
<FromGitter> <bararchy> ```The number of input neurons in the ann (2) and data (0) don't match```
<FromGitter> <bararchy> Data should equal the Input neurons
<FromGitter> <bararchy> there are no data neurons ⏎ input ⏎ hidden ⏎ output [https://gitter.im/crystal-lang/crystal?at=595a17616ae41d5d33acfb7e]
<Groogy> yeah, I think the #num_input is wrong maybe?
<FromGitter> <bararchy> ```input = [[0.0_f32, 0.0_f32], [0.0_f32, 1.0_f32], [1.0_f32, 0.0_f32], [1.0_f32, 1.0_f32]]``` ⏎ ⏎ and input neurons are set to 2 [https://gitter.im/crystal-lang/crystal?at=595a17ad5a1ab55f644d0224]
<FromGitter> <bararchy> so it's ok
<FromGitter> <bararchy> as we have 2 each time
<Groogy> hmmm is it possible to try and manually read from a Pointer?
<Groogy> probably "unsafe" but it would let you know if you could access the elements correctly in the pointer
<Groogy> or write a small little C lib that you link with that has a function that takes a (float** pointer, int count) that outputs the pointer to stdout to see if you can access it correctly
<FromGitter> <bararchy> I think I can just do ⏎ Slice.new(ptr.value.value, data_size)
<Groogy> test it out, see if you can read back the data as expected
sz0 has quit [Quit: Connection closed for inactivity]
<Groogy> so how did it turn out? you keeping me in suspense :P
<FromGitter> <sdogruyol> :D
<FromGitter> <sdogruyol> he's having lunch (probably)
<Groogy> Are there actually any big professional projects that use Crystal yet?
<Groogy> professional as in "makes money", not freetime stuff
<FromGitter> <bararchy> We have a few, but it's not open sourced ;)
<Groogy> no was just curious on development of the "scene/community"
<Groogy> cool, hopefully I'll get my hobby project there eventually as well
<Groogy> oh that's pretty nice webserver stuff as well
<FromGitter> <sdogruyol> yeah
<FromGitter> <sdogruyol> if you're interested check kemal https://github.com/kemalcr/kemal
<FromGitter> <sdogruyol> or the website http://kemalcr.com/
<Groogy> nah I'll play around with glfw and opengl for my stuff
<FromGitter> <sdogruyol> have you seen crsfml?
<FromGitter> <sdogruyol> somebody's actually writing a nes emulator with it https://github.com/romeroadrian/nes.cr
<FromGitter> <bararchy> So... `[0.0, 0.0, 0.0, 0.0]`
<FromGitter> <bararchy> I guess the c lib doesn't lie
<FromGitter> <bararchy> hahah
<Groogy> haha
<Groogy> so it seems to be getting garbage, or something it shouldn't be
<Groogy> @sdogruyol yeah I did rbSFML
<Groogy> but been fighting the new crew that took over the library kind of ish on some features they are being really stubborn about
<Groogy> so gave up on it
<FromGitter> <sdogruyol> that's sad to hear
<FromGitter> <sdogruyol> we have @Blaxpirit @oprypin actually maintaining crsfml he's a really great person
<Groogy> how the opengl context is handled is really dumb and I tried to get them to fix it but the guy in charge for that part had a completly false view on how opengl contexts in 3.* works
<Groogy> and evne when I proved it to him with a snippet he refused to fix it
<FromGitter> <sdogruyol> maybe you can work together
<Groogy> "because rasons" *fart*
<Groogy> no I am talking about the main library development
<Groogy> not the bindings
<FromGitter> <sdogruyol> oh
<FromGitter> <sdogruyol> sorry
<FromGitter> <sdogruyol> that's awful then
<Groogy> I was lead author on that book :P
<FromGitter> <sdogruyol> wow, amazing!
<FromGitter> <sdogruyol> It's great to have a chance to chat with you :)
<Groogy> haha it's not that special, I had just been using SFML since the earliest versions
<FromGitter> <sdogruyol> i'd like to ask you some question about writing a book though :)
<Groogy> Sure! I can start with it is way more work than I first imagined
<FromGitter> <sdogruyol> i can't pm you though, i'm using gitter
<FromGitter> <sdogruyol> :(
<Groogy> oh so that's what that weird bot is
<Groogy> now I get it
RX14 has quit [Ping timeout: 240 seconds]
<FromGitter> <bararchy> Groogy, getting there https://play.crystal-lang.org/#/r/2ahd
<FromGitter> <sdogruyol> yeah i'm on https://gitter.im/crystal-lang/crystal
<Groogy> @bararchy nice
<FromGitter> <bararchy> Now though, its a Pointer(Array(Float32)), while it needs to be Pointer(Pointer(Float32))
<FromGitter> <bararchy> and then somehow recreate it
<Groogy> Slice of a slice?
<Groogy> not sure how slices work though
<FromGitter> <bew> @bararchy can you have multiple f32 in a sub array?
<FromGitter> <bararchy> Cool, so now I onll need to re-map https://play.crystal-lang.org/#/r/2ahk
<FromGitter> <bararchy> Groogy, it was my issue for now re-translating right, but it seems the info is there
<Groogy> so the info should be correct when it is given to the C function?
<Groogy> hmm then I donno anymore ¯\_(ツ)_/¯
<Groogy> only thing would be if the C function receives it/perceives it wrong
<Groogy> and you need a different calling convention or something
_whitelogger has joined #crystal-lang
<FromGitter> <bararchy> there could be lots of Floats in each nested array
<FromGitter> <bew> and do you know in advane how many?
<FromGitter> <bararchy> which is why the underlying lib asks both input_array_size , and, nested_input_array_size
<FromGitter> <bararchy> I know it before passing it tot he lib
<FromGitter> <bew> thanks (why do you need all the `as ...` ?)
<Groogy> Yeah donno why I tried to help, I just got started with crystal myself xD :oops:
<Groogy> oh no my emoji plugin doesn't work D:
<Groogy> (ノ゚-゚)
<Groogy> there we go
<FromGitter> <bararchy> @bew because is tells me "Can't infer the type of...."
<FromGitter> <bararchy> so as long as I put .as ... it fixes it :)
<FromGitter> <bew> ...
<FromGitter> <bararchy> I know ...
<FromGitter> <sdogruyol> @groogy IMHO you've already grokked Crystal
<FromGitter> <sdogruyol> having low level experience helps a lot
<FromGitter> <bararchy> Right now i'm imagning @bew is doing a total refactor to everything and sending a PR HAHAHAH ⏎ It's like, WTF did he do here ?!?! WTH is this a Pointer ?!?!?
<FromGitter> <bararchy> LOL
<Groogy> grokked? what does that mean?
<FromGitter> <sdogruyol> @bararchy are you working together?
<FromGitter> <bararchy> With whom ?
<FromGitter> <bararchy> with @bew ?
<FromGitter> <sdogruyol> yes
<FromGitter> <bararchy> Nope, just a cool guy helping out :)
<FromGitter> <bararchy> Like Groogy
<FromGitter> <bew> ahahah almost @bararchy, almost ^^ but I do have work to doo, so not now ;) thanks
<Groogy> Yeah I am stuck with a problem that is "HOW THE HELL DO I SOLVE THIS?" so can't really code at moment
<Groogy> ( `Д´)=◯)`ν°)
<FromGitter> <bew> btw doing something like that *should* work, but idk why it doesn't... https://carc.in/#/r/2aho
RX14 has joined #crystal-lang
<FromGitter> <bararchy> Could be that the Pointer(Pointer(Float32)) is getting corrupted or something ?
<FromGitter> <bew> well no, because you see from the input that it find everything
<FromGitter> <bew> output*
<FromGitter> <bararchy> I mean the data is fine, the structure of the wrapping Array is lost ?
<FromGitter> <bew> found it ><
<FromGitter> <bararchy> ??
<FromGitter> <bararchy> What was it ?
<FromGitter> <bew> I forgot to save the array x)
<FromGitter> <bararchy> Oh hahah
<FromGitter> <bew> https://carc.in/#/r/2aht
<FromGitter> <bew> quite nice imo :)
<FromGitter> <bararchy> How come some of your floats become Ints ?
<FromGitter> <bew> when you know the size of the arrays in advance, the array can be easily recreated
<FromGitter> <bararchy> `[[0, 0.1], [1, 1.3], [1, 0.6], [0, 0.4]]`
<FromGitter> <bew> I think it's just the way they are displayed
<FromGitter> <bararchy> Oh
<FromGitter> <bararchy> ok
<FromGitter> <bew> I agree it's confusing..
<FromGitter> <bararchy> BTW, this means I do send the Data as it should be getting there
<FromGitter> <bararchy> As I use the same method you did to create the pointers
<FromGitter> <bararchy> saveing each temp_array as Instance var as to not lose it to the GC
<FromGitter> <bararchy> I think I just do it wrong
<FromGitter> <bararchy> Structure used to store data, for use with training. ⏎ ⏎ The data inside this structure should never be manipulated directly, but should use some of the supplied functions in Training Data Manipulation. ⏎ ⏎ The training data structure is very usefull for storing data during training and testing of a neural network. [https://gitter.im/crystal-lang/crystal?at=595a2c7af5b3458e30091b27]
<FromGitter> <bararchy> `The data inside this structure should never be manipulated directly, but should use some of the supplied functions in Training Data Manipulation.`
<FromGitter> <bararchy> So I guess I shouldn't try to create it myself
<FromGitter> <bararchy> there is a func to do it for me :(
<FromGitter> <bararchy> Creates an training data struct and fills it with data from provided arrays, where the arrays must have the dimensions
<Groogy> Yeah I pointed that out before :P
<FromGitter> <bararchy> Sorry missed it
<FromGitter> <bew> do you build the bindings from the API only or do you base yourself on some code using the lib to know what to bind?
<FromGitter> <bararchy> ```code paste, see link``` ⏎ ⏎ So I just call that and it creates the Struct filled and ready for me [https://gitter.im/crystal-lang/crystal?at=595a2d898dae4250317beb78]
<FromGitter> <bew> nice catch though Groogy, I think some are better at "reading the docs" than the others...
<FromGitter> <bararchy> XD
<FromGitter> <bararchy> True
<Groogy> I just went with "I am sure this guy knows what he is doing"
splitty__ has joined #crystal-lang
<FromGitter> <bararchy> Bad approch
<FromGitter> <bararchy> hahaha
splitty___ has joined #crystal-lang
<FromGitter> <bew> at least, everyone learnt something here :)
splitty_ has quit [Ping timeout: 240 seconds]
splitty__ has quit [Ping timeout: 240 seconds]
<Groogy> Well I have to have that approach, not trusting my colleagues to be capable would suck :P
<FromGitter> <bararchy> Woot !!! Working :)
<Groogy> nooice! ᕕ(ᐛ)ᕗ
<FromGitter> <bew> :clap: :clap: :clap:
<FromGitter> <codenoid> sup,
<FromGitter> <bew> you right groovy
<FromGitter> <bew> groogy sorry
<FromGitter> <codenoid> how to use SSL in kemal ?
<FromGitter> <codenoid> example, with lets encrypt
<FromGitter> <sdogruyol> @codenoid http://kemalcr.com/docs/ssl/
<Groogy> @bew people do that mistake all the time
<FromGitter> <bew> ahah, is the capital G important?
<Groogy> well it's a name so :P Had this nick since I was like 12
<FromGitter> <bew> I'll be careful then :pray: :)
hightower2 has joined #crystal-lang
<Groogy> from our forum
<Groogy> it's now an inside joke in the community ;)
<FromGitter> <sdogruyol> unfortunately imgur is blocked in my country
<FromGitter> <sdogruyol> lol
<Groogy> D:
<Groogy> @sdogruyol let's link the actual source then: https://forum.paradoxplaza.com/forum/index.php?threads/the-developer-multiplayer-clash-every-tuesday-at-15-00cet.994245/page-25#post-22386524
<FromGitter> <sdogruyol> ROFL :D
Philpax_ has quit [Ping timeout: 246 seconds]
<Groogy> usually when I link stuff, our forum is blocked but not imgur :idonnu:
<FromGitter> <eliasjpr> Hell0 everyone! I was wondering if Travis is back working for running Crystal Specs
<FromGitter> <sdogruyol> @eliasjpr not yet
<FromGitter> <eliasjpr> :(
<FromGitter> <eliasjpr> Thank @sdogruyol
<FromGitter> <eliasjpr> How are you doing?
<FromGitter> <sdogruyol> np
<FromGitter> <sdogruyol> i'm fine thanks and you @eliasjpr
<FromGitter> <eliasjpr> Im good celebrating the 4th of July weekend with family, and getting back to continue working on Amber
<FromGitter> <sdogruyol> that's great to hear :)
<FromGitter> <eliasjpr> Thanks!
<FromGitter> <sdogruyol> i've also worked on Kemal this weekend
<hightower2> Crystal is bringing regulation into the realm of awesome, but unregulated, Ruby syntax :-)
<FromGitter> <sdogruyol> released 0.20.0 http://kemalcr.com/blog/2017/07/01/kemal-0.20.0-released/
<FromGitter> <eliasjpr> I saw that you added support for crystal 23
<hightower2> s/syntax/runtime behavor/
<FromGitter> <sdogruyol> yeah, also improved handler chains
<FromGitter> <sdogruyol> now you can totally go crazy and replace the default Kemal handlers to build your own framework e.g
<FromGitter> <sdogruyol> or just use the router
<FromGitter> <sdogruyol> :D
<FromGitter> <bew> coool
<FromGitter> <eliasjpr> Nice! Im gonna look into that. That sweet
<FromGitter> <sdogruyol> yup
<FromGitter> <sdogruyol> thanks to @drujensen for the initial idea at CrystalCodeCamp
<FromGitter> <eliasjpr> yeah
<FromGitter> <eliasjpr> Where was the CrystalCodeCamp held?
<FromGitter> <sdogruyol> i can easily that it's great to have him in Amber team :)
<FromGitter> <sdogruyol> it's in San Francisco
<Groogy> there's a crystal code camp?
<FromGitter> <sdogruyol> https://codecamp.crystal-lang.org/
<FromGitter> <sdogruyol> back in May
<Groogy> ah
<FromGitter> <sdogruyol> i'm the one with glasses there :D
bjz has joined #crystal-lang
<FromGitter> <sdogruyol> overally it's a great great experience
<hightower2> Hey, who has some production examples of YAML.mapping()? I could use hints from seeing an actual, integrated implementation
<Groogy> hmm that would have been around GDC time as well... could have taken vacation and visited that if I knew Crystal existed
<FromGitter> <eliasjpr> nice! When would the next one be?
<FromGitter> <bew> hightower like in `shards` ?
<FromGitter> <sdogruyol> @eliasjpr not sure about the date
<Groogy> I'll have a project done before then and see if I can show up ^^
<FromGitter> <eliasjpr> would be nice to have a calendar so people can better plan to assist
<FromGitter> <eliasjpr> I would love to meet everyone in person
<FromGitter> <bew> nvm, no mapping in shards.. weird
<FromGitter> <sdogruyol> yeah, we have a great community with awesome people @eliasjpr
<Groogy> Crystal has nothing to fullfill Design by contract right, mostly focused on specs like Ruby? Think that might be my first thing to implement when I get home today
<Groogy> I'm lazy so I always end up not doing TDD correctly, so contracts work way better for me
<FromGitter> <molovo> I’ve never liked TDD. I refactor a ton while I’m developing, so prefer to write a few basic tests, and then aim for full coverage once I’ve nailed down the functionality
<Groogy> Everyone is different, I just like having code that describe what the function accepts and what the function ensures as result directly associated with the code
<Groogy> also makes me remember to keep it compliant/update contract
<FromGitter> <sdogruyol> @molovo that's also a good approach
tzekid has joined #crystal-lang
<Groogy> can you hook in on when a struct goes out of scope and gets destroyed?
<FromGitter> <sdogruyol> i'm pretty sure you can do that with a `finished` macro
<FromGitter> <bew> it's finalized
<Groogy> finished macro?
<Groogy> oh finalized, the GC calls that one though for referenced objects
<FromGitter> <bew> yeah iirc, not sure though
<Groogy> I need something for leaving the scope of a function
<FromGitter> <bew> it doesn't exist
<Groogy> i.e ensures is a macro which creates a struct that should be destroyed at end of function
<Groogy> aw man
<FromGitter> <straight-shoota> `finished` macro is invoked at compile time, when everything else in a class definition is defined
<FromGitter> <bew> oh but you can use `ensure` at the end, like: (I'll make an example)
<Groogy> I know
<Groogy> but I want to adhere to a DSL kind of
<Groogy> where oyu define the conditions of the funciton at start
<FromGitter> <bew> not sure you can do that, even with macros
<Groogy> though I mean, you can have an ensure keyword on any begin end right? including method definitions
<FromGitter> <bararchy> Wow, training Neural Nets with Crystal is awsome , the speed is crazy :)
<FromGitter> <sdogruyol> how crazy?
<FromGitter> <sdogruyol> what's your comparison there :D
<FromGitter> <bararchy> Ruby, and Python
<FromGitter> <sdogruyol> that's great to hear
<FromGitter> <sdogruyol> however i'm really sad about the compiler speed atm :(
<FromGitter> <bararchy> The loading of the Data (6Gb of train data to mem) takes like 2 sec
<FromGitter> <bararchy> Ot's amazing
<FromGitter> <sdogruyol> great
<FromGitter> <bararchy> Compiler speed as in compiling or runtime speed ?
<FromGitter> <sdogruyol> compilation speed
<FromGitter> <bararchy> Yeha, this one sucks hahah
<FromGitter> <bararchy> compiling Big projects takes lotsssss of time
<Groogy> if I do a return in a method before a ensure is declared for an entire function, it will still execute the ensure right?
<FromGitter> <bararchy> btw, do you guys at work right now doing Crystal programming ?
<FromGitter> <straight-shoota> Groggy, yes
<FromGitter> <straight-shoota> `ensure` block is ensured to be executed, no matter what
<FromGitter> <bew> you're talking about that kind of ensure? https://carc.in/#/r/2ai8
<Groogy> yeah I am thinking if I can hack around the language
<Groogy> problem will lie in what the macro language define as "complete code" and if it can generate a "ensure;else;"
<FromGitter> <straight-shoota> macro doesn't care about syntax the compiler just expects your macro to generate valid code. It it does not, it will result in an syntax error, when the macro-generated code is compiled
<FromGitter> <sdogruyol> BTW this talk is awesome, it's about Garbage Collectors and i hope Crystal will have a native GC like this https://twitter.com/sdogruyol/status/881860201015635968
<FromGitter> <sdogruyol> hey @RX14 are you there :P?
<Groogy> @straight-shoota nice then I might actually be able to get aorund it
<RX14> yes
<FromGitter> <sdogruyol> i'm thinking of creating benchmarks of Kemal versions with Crystal versions, thus i need to have previous Crystal versions installed. I thought that crane would be a great choice for that
<FromGitter> <sdogruyol> WDYT?
<RX14> well it'd be a good idea if crane worked
bjz_ has joined #crystal-lang
bjz has quit [Ping timeout: 248 seconds]
<FromGitter> <krypton97> Any chances in the future for crystal to support short assignment operators like := for example? This would be more readable than = for declarations..
<RX14> no chance
<FromGitter> <sdogruyol> @krypton97 probably not
<FromGitter> <sdogruyol> why do you need it though
mark_66 has quit [Quit: Leaving.]
<FromGitter> <krypton97> It's more readable...sometimes I get confused wheter I declared that or that var was already declared and so on..
<RX14> then your functions are too long
<FromGitter> <krypton97> Or being able to put the data type when declaring would be nice as well
<FromGitter> <sdogruyol> you can do that
<FromGitter> <bew> not really working @sdogruyol: https://play.crystal-lang.org/#/r/2aiv
<FromGitter> <sdogruyol> how https://play.crystal-lang.org/#/r/2aj0
<FromGitter> <krypton97> I kinda new about that, but why using str : String = instead of String str = it's not better
<FromGitter> <krypton97> Whatever, maybe I'll have to get used to it
<FromGitter> <sdogruyol> @krypton97 it's not that bad :P
<RX14> if you want to write Java write Java
<RX14> sounds like you'd be happier
<FromGitter> <krypton97> I hate VM languages
<FromGitter> <sdogruyol> did you know that Japanese people have a slang for NullPointerException ? :D
<Groogy> Nullopointua desu~
<Groogy> (• ε •)
<RX14> @krypton97 you really shouldn't declare types of local variables manually, the syntax was only introduced recently and to be honest it's a mistake
<Groogy> Well it's for when the inference falls short isn't it?
<RX14> no
<RX14> it doesn't affect the inference
<FromGitter> <sdogruyol> ぬるぽ
<RX14> it's really only for raising the scope of a variable
<RX14> but i'd rather just use a = nil
<Groogy> reset the var to a new type or?
<FromGitter> <krypton97> @RX14 but why?
<RX14> why to which bit?
<Groogy> is there a way to check in an ensure scope if an exception was triggered?
<RX14> i don't think so
<RX14> what's the usecase/
<Groogy> contracts
<Groogy> "fancy asserts"
<RX14> an example?
bjz has joined #crystal-lang
<FromGitter> <sdogruyol> we can help you more with a code snipper :P
<FromGitter> <sdogruyol> snippet*
<Groogy> can show you what I have in C++ right now
<Groogy> what I imagine in Crystal
bjz_ has quit [Ping timeout: 248 seconds]
<RX14> i meant the specific implementation that needs ensure trickery
<FromGitter> <krypton97> If so, why do we still need pipes like do |key|
<RX14> you can use rescue and else in begin blocks
<RX14> and then just set a bool and call a function or something
<RX14> not entirely sure what to suggest without the implementation that's givijng you trouble
<FromGitter> <krypton97> Anyway, what's the fastest way to iterate from i to n ??
<FromGitter> <crisward> Does anyone know if crystal client can be told to follow redirects? Can't see anything in the docs. Thanks...
<Groogy> no I am just planning
<Groogy> at work at the moment
<Groogy> and planning to work on this when I get home
<RX14> @krypton97 i.upto(n) do |x|
<FromGitter> <krypton97> I'm thinking between (i..n).each vs n.times
<FromGitter> <krypton97> Oo nice, didn't know about that
<RX14> if i is 0 use times
<FromGitter> <krypton97> Is it faster?
<RX14> ranges also have the same performance
<FromGitter> <krypton97> Than each
<RX14> no they are all the same
<Groogy> it's clearer to read
<RX14> the only difference between all these is how you write them
<FromGitter> <krypton97> Thanks!
<FromGitter> <bew> icr is broken with last archlinux updates, I updated libevent, icr needed the old version, and the AUR build crashes on a stupid spec :/
AckZ has joined #crystal-lang
mark_66 has joined #crystal-lang
bmcginty has joined #crystal-lang
<crystal-gh> [crystal] MakeNowJust opened pull request #4664: Parser: correct to parse 'foo &.%(1)' (master...fix/crystal/parse-percent-as-block-call) https://git.io/vQuCn
<FromGitter> <renich> > Renich Bon Ciric @renich 00:51 ⏎ Hello. I am building an app that consumes an API and tries to make decisions on the data it gathers. It should run in a loop and repeat the cycle every 5 mins or so. I am interesting in several things regarding this: ⏎ ⏎ 1) Logging: how would you go about implementing logging, even in the library? I want to log what methods do and get as response messages in the API
<FromGitter> ... library. ⏎ 2) Loop: what would be the best way to approach the loop part? Just write a loop and use sleep? ... [https://gitter.im/crystal-lang/crystal?at=595a55104bcd78af566eead7]
<FromGitter> <fridgerator> There is a logger built into the stdlib : https://crystal-lang.org/api/0.23.0/Logger.html
<FromGitter> <fridgerator> maybe look at something like: https://github.com/hugoabonizio/schedule.cr
<FromGitter> <mverzilli> loop, you can: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=595a573e3230e14f3a1dacad]
<FromGitter> <renich> @fridgerator thanks. I know. I am trying to learn how to implemented all around.
<FromGitter> <renich> Thanks @mverzilli for the tip.
<FromGitter> <renich> @fridgerator the latter link seems cool! Will read on.
<FromGitter> <renich> Regarding logging, let's say I have MyModule and I, also, have /lib/api/api.cr, which has a library for consuming the API. How would you go about logging in that case? Should I create a module for the API lib and
hightower2 has quit [Ping timeout: 276 seconds]
<FromGitter> <fridgerator> hard to say
<FromGitter> <renich> Maybe the library should have it's own logging, but I dunno.. doesn't seem right
<Papierkorb> renich, if you actually want to log from the lib, then make it so you can set a ::Logger, e.g. to a class_property in your Lib's main module
<Papierkorb> Initialize it to a logger logging into a blackhole
<FromGitter> <renich> Papierkorb: ok. Then set it in the app?
<Papierkorb> Then the user of the library sets it if wanted, yes
<FromGitter> <renich> Cool. That's sounds better, thanks Papierkorb
<FromGitter> <bararchy> Is it possible to bind C++ ? or is it too problomatic ?
<Papierkorb> You mean directly to an existing C++ library? Sanely you mean? "Don't even bother"
<FromGitter> <bararchy> Oh...
<Papierkorb> Many C++ libs have (3rd party) C bindings though, those you can use
<FromGitter> <bararchy> So, C-bind the C++ to Crystal Bind :)
<FromGitter> <azzuwan> @bararchy what machine learning framework are you using?
<FromGitter> <bararchy> @azzuwan => https://github.com/bararchy/crystal-fann
<FromGitter> <bararchy> My bindings for FANN
<FromGitter> <azzuwan> @bararchy sweet, I'm gonna take a look
<FromGitter> <bararchy> But I want to see if there are better ones to bind to , with CUDA support and multi-cpu
<FromGitter> <bararchy> @azzuwan Are you playing around with Neural nets ?
<FromGitter> <renich> Papierkorb: when you say class property, are you referring to the property macro?
<Papierkorb> `class_property` macro
<FromGitter> <renich> Ok. Will read about it. Thanks again, Papierkorb
xiljin has quit [Ping timeout: 255 seconds]
xiljin has joined #crystal-lang
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
Groogy has quit [Quit: WeeChat 1.7.1]
<crystal-gh> [crystal] MakeNowJust opened pull request #4665: Show helpful error message against invalid number literal like '.42' (master...fix/crystal/lex-special-error-dot-with-number) https://git.io/vQuEk
<FromGitter> <bew> @MakeNowJust it kind of a hack to fix #4664 in the parser no? I would expect to fix that in the lexer, so it does not get a `:DELIMITER_START` but an `:IDENT` or `:%`..
<DeBot> https://github.com/crystal-lang/crystal/pull/4664 (Parser: correct to parse 'foo &.%(1)')
Qchmqs has quit [Remote host closed the connection]
<FromGitter> <schoening> Can I change the directory Kemal uses for static files @sdogruyol ?
<FromGitter> <schoening> @oprypin thx
mark_66 has quit [Remote host closed the connection]
vegai has quit [Ping timeout: 246 seconds]
sija[m] has quit [Ping timeout: 240 seconds]
TheGillies has quit [Ping timeout: 255 seconds]
MatrixTraveler[m has quit [Read error: Connection reset by peer]
braidn[m] has quit [Read error: Connection reset by peer]
Lex[m] has quit [Write error: Connection reset by peer]
thelonelyghost has quit [Read error: Connection reset by peer]
werthen[m] has quit [Read error: Connection reset by peer]
davidbe[m] has quit [Read error: Connection reset by peer]
krigare[m] has quit [Ping timeout: 246 seconds]
MatrixTraveler[m has joined #crystal-lang
hightower2 has joined #crystal-lang
qard has joined #crystal-lang
braidn[m] has joined #crystal-lang
TheGillies has joined #crystal-lang
davidbe[m] has joined #crystal-lang
vegai has joined #crystal-lang
Lex[m] has joined #crystal-lang
thelonelyghost has joined #crystal-lang
krigare[m] has joined #crystal-lang
sija[m] has joined #crystal-lang
werthen[m] has joined #crystal-lang
Groogy has joined #crystal-lang
<Groogy> Hellu
<Groogy> is there a way to find out what function is currently being called in a macro? Like __FUNCTION__ in c++?
<Groogy> also is there something akin to static_assert or #error pragma?
<oprypin> >> {% if 5==5 %}{% raise "compiletime error %}{% end %}
<DeBot> oprypin: Syntax error in eval:18: unterminated string literal - https://carc.in/#/r/2alf
<oprypin> >> {% if 5==5 %}{% raise "compiletime error" %}{% end %}
<DeBot> oprypin: in line 16: compiletime error - https://carc.in/#/r/2alg
<Groogy> nice thx
<oprypin> there is a way to find out current type but probably not function
<Groogy> hmm type is enough, but guess enough to just do typeof(self)
<Groogy> aw you can't use the else in the shortform of a rescue/ensure thingy in a method :(
<FromGitter> <johnjansen> huh?
<Groogy> i.e def; rescue; ensure; end is only valid, you can't have code that "runs afterwards if no exception was thrown
<hightower2> Yo buddies, any production examples of YAML.mapping?
<Groogy> oh wait you can only have either else or ensure... hmm
bjz has joined #crystal-lang
<FromGitter> <johnjansen> can you drop and example of that
<Groogy> from the documentation: https://pastebin.com/GdZARGxT
<FromGitter> <johnjansen> both https://carc.in/#/r/2alj
<FromGitter> <johnjansen> ordering is important https://carc.in/#/r/2alk
<Groogy> huh okay
<FromGitter> <johnjansen> ensure is always last …
<FromGitter> <johnjansen> for cleanup etc
<Groogy> dang doesn't help anyway with that I am trying to accomplish
<Groogy> trying to be able to write code at start of function that I want to execute at any exit of the function
<FromGitter> <johnjansen> example?
<Groogy> I can give you c++ example of what I am trying to rewrite to Crystal
<FromGitter> <johnjansen> haha … yeah that might not go so well on this end
<Groogy> ah well lol
<Groogy> alright this I guess you could call the "concept"?
balduin has quit [Quit: Leaving.]
<FromGitter> <johnjansen> what have you got so far?
<Groogy> trying to figure out a way to invoke some kind of code at each exit point of a method :/ but can't come up with anything
<Groogy> Ah I just started
<Groogy> I mean require and invariant is simple enough
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<Groogy> ensure though is supposed to guarrantee on exit of function, this holds true at all times
<Groogy> been looking at structs but they don't seem to have any "on destruction" callback, I mean Pointer() just let's go of the memory it allocated and let's the GB handle it so
<FromGitter> <johnjansen> you mean like this? https://carc.in/#/r/2alu
<FromGitter> <johnjansen> thats for a class though … dont know if it applies to struct
<FromGitter> <johnjansen> this is a better example also https://carc.in/#/r/2am2
<RX14> there's no way to do what you want to do without replacing the entire method Groogy
<Groogy> yeah :/
<FromGitter> <johnjansen> thanks @RX14 glad you showed up
<RX14> however you could push the method details (class, name, args, etc) to a constant array and use a finally macro to override them
<Groogy> finally is when the class finishes get defined right?
<RX14> you'd firstly expand the requires and ensures macros to a nop
<RX14> and push the details to a constant array, which can be modified by macros
<RX14> finally macro runs after all other macros
<RX14> thats all
<Groogy> though that wouldn't let me rewrite the function right to add in the code where needed
<Groogy> you don't have the mixin(str_with_any_code_you_want) like D has
<RX14> why not?
<RX14> you can just reopen the class and redefine the method in top-level finally
<Groogy> hmm
<Groogy> actually....
<Groogy> yes
<Groogy> there's the prev def I can still access right?
<Groogy> that's really clever
<RX14> and if there wasn't you could simply save the body
<Groogy> yeah, been some time since I worked in Ruby :P
<Groogy> thx
<RX14> it'd be a lot simpler in ruby lol
<Groogy> yeah of course
<hightower2> Ok no YAML.mapping() examples in production :) Remains for me to try understand how it works on my own :)
DTZUZU has joined #crystal-lang
<FromGitter> <schoening> JSON::Any does not have to_i method and String does not have as_i method. So what do I do when my data can be of one of those types? Because this did not work: ⏎ ⏎ http://i.imgur.com/QuKNfig.png
<FromGitter> <akzhan> Kind of monkey patching :) ⏎ ⏎ ```class String ⏎ def as_i ⏎ to_i ⏎ end ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=595a8bfd6ae41d5d33af1a15]
<FromGitter> <akzhan> But it’s wrong way. Please use JSON.mapping to concrete classes.
<FromGitter> <johnjansen> a quick hack, `to_s.to_i`
<FromGitter> <johnjansen> ;-)
<Groogy> hmm can you save a class in a variable?
<oprypin> Groogy, yes
<Groogy> how? Tried var : Class and it told me I am not allowed to have a reference to type Object
<Groogy> "Error in src/crystal-test.cr:8: can't use Object as the type of a variable yet, use a more specific type
<Groogy> klass : Class"
<oprypin> how about dropping that line
<FromGitter> <schoening> @johnjansen thanks! :D ⏎ Could you elaborate on the sentence "Please use JSON.mapping to concrete classes" ? I don't understand that sentence I guess its the concrete part I don't get, dunno what that means
<oprypin> schoening, that code is so wrong i dont know where to begin :/
<oprypin> (honesly i dont have anywhere to begin because it's cut off)
<FromGitter> <schoening> Well, I gotta learn somehow
<FromGitter> <schoening> now it's changed to to_s.to_i hehe
<hightower2> If I have a class with YAML.mapping, and I subclass it, how do I add new fields to/from YAML? Can I "append" the definition or I need to repeat/redefine it?
<oprypin> probably cant do anything of that sort but i'm just guessing
<hightower2> schoening: they're saying you should be using JSON.mapping() (see mentions of "mapping" on https://crystal-lang.org/api/0.18.7/JSON.html) instead of manually parsing with JSON.parse
<hightower2> schoening: (since JSON.mapping() is optimal for mapping objects to/from JSON, rather than doing "manual" parsing)
<FromGitter> <schoening> Ok I will check it out :D
<FromGitter> <schoening> Thx
<hightower2> schoening: once you define a JSON.mapping() for your class, you will be able to convert it to/from JSON using #to_json() and #from_json(...json text...)
<hightower2> (just like that, no other work involved)
<oprypin> if only that always worked
<hightower2> I can't say I did it myself, I am trying to make that same thing working using YAML.mapping(), but at least that's the theory :)
<hightower2> schoening: sent old/outdated link, the 0.23 version is https://crystal-lang.org/api/0.23.0/JSON.html
<FromGitter> <schoening> I'll look into it and try it out.
Groogy_ has joined #crystal-lang
<Papierkorb> Protip: https://crystal-lang.org/api/latest/JSON.html will always be the latest and greatest
<oprypin> yeah but what matters is google search results, which are busted
Groogy has quit [Ping timeout: 258 seconds]
<Papierkorb> Eh, I don't use Google for that anyway, too slow
<FromGitter> <renich> I need help with this:
<FromGitter> <renich> Sorry, I know that 4 spaces per tab hurt your eyes... :D
<oprypin> we need some IRC sensitivity training around here
<FromGitter> <johnjansen> so @renich you should use https://carc.in
<hightower2> oprypin, auto-redirecting to latest version unless a person includes ?force=1 in the URL
<Papierkorb> Reject ^
<Papierkorb> There are good reasons to access old versions. First and foremost: You're not on the latest version.
<FromGitter> <renich> oprypin: sorry! I know. I use IRC... sorry...
<FromGitter> <renich> https://carc.in/#/r/2amp
<oprypin> you cant just type one word and then edit in 1000 words afterwards
<oprypin> or did you not use edit when adding that piece of code?
<oprypin> the main point is dont use edits for anything important
* FromGitter * renich forgot to add the method in the order hash... :S
<FromGitter> <renich> Still, that is not the problem... yet
<FromGitter> <coderhs> Hi. how do we retrieve an integer from a yaml file? I am getting the following error when i try to do `to_i` `undefined method 'to_i' for YAML::Any (did you mean 'to_a'?)`
onionhammer1 has quit [Ping timeout: 260 seconds]
<FromGitter> <akzhan> value.as_i (but please use YAML.mapping instead).
onionhammer1 has joined #crystal-lang
<FromGitter> <coderhs> as_i also gave the following error `undefined method 'as_i' for YAML::Any (did you mean 'as_s'?) ⏎ ` ⏎ ⏎ I will look at YAML.mapping [https://gitter.im/crystal-lang/crystal?at=595a93b8c101bc4e3a490b9c]
<oprypin> coderhs, yaml doesnt really have integers. not in crystal's world, anyway
<oprypin> .as_s.to_i
<FromGitter> <coderhs> got it, thank you.
onionhammer1 has quit [Ping timeout: 240 seconds]
<hightower2> Papierkorb, haha, sure, I was just making a wild suggestion ;-)
<hightower2> Papierkorb, but what could work would be to put on top of every versioned page, a link to the latest one (same page, just in /latest/)
<FromGitter> <johnjansen> @renich https://carc.in/#/r/2an7
<FromGitter> <renich> https://carc.in/#/r/2an9
<FromGitter> <renich> That one looks better than what I had... Let me check @johnjansen 's version
<FromGitter> <renich> @akzhan thank you very much. I will look into the mapping thing. I am a complete idiot when it comes to crystal... :S
<FromGitter> <johnjansen> @renich you need to pay special attention to Types … try to understand what every var is and ensure you are always in control …
<hightower2> Hey, does YAML.mapping() automatically define 'properties', or I need both 'property' and YAML.mapping() statements?
<oprypin> defines properties
<FromGitter> <renich> @johnjansen thanks,, man. It seems clean and all.
<oprypin> renich, i sent https://carc.in/#/r/2ams earlier but didnt notify you
<hightower2> thanks oprypin, trying to embark on that task now
<FromGitter> <johnjansen> not perfect, but im busy too
<FromGitter> <renich> oprypin: actually, I used yours first. Thanks! ;=)
<oprypin> renich, first of all, this type of data of different types but where each field has its expected type is just not meant to be in a Hash
<FromGitter> <renich> @johnjansen I appreciate you taking the time to help... Thanks
<oprypin> the types get jumbled up together and just cause you pain
<FromGitter> <renich> oprypin: yeah, that has been the case. So, what to use instead of hashes?
<FromGitter> <johnjansen> @renich @oprypin’s is cleaner for sure … my only comment is that you didnt appear to know that the “method” key was missing, or that it was a symbol not a string
<oprypin> renich, tuples. in this case i guess you can just replace `=>` with `:`
<FromGitter> <renich> @johnjansen yeah, fixed that
<FromGitter> <renich> cool
<oprypin> renich, do you have a predefined set of fields and types? or are they really variable?
<FromGitter> <johnjansen> i suspect this is the tip of the iceberg
<Groogy_> hmm how do you define the finally macro?
<oprypin> Groogy_, sorry what?
<Groogy_> can't seem to find it in the docs
<FromGitter> <renich> oprypin: no, they come from a restful API
<Groogy_> the one @RX14 refered to me before
<oprypin> renich, no what? i think that means the types are predefined
<RX14> Groogy_, just macro finally
<FromGitter> <renich> oprypin: I use JSON::Any in fact. Yes, they're pre-defined.
<Groogy_> globally or in a class?
<RX14> it'll be expanded in place
<oprypin> renich, in that case it's really worth using JSON.mapping
<RX14> so if you want to patch all different things from 1 array
<RX14> then you have to do it globally
<RX14> because you can't get out of a namespace in macros
<oprypin> renich, see https://carc.in/#/r/2ac4
<FromGitter> <renich> How do I convert all elements in a named tuple into strings?
<FromGitter> <renich> `processed_order = order.map { |k, v| [k.to_s, v.to_s] }.to_h` doesn't work anymore
* FromGitter * renich will check the example
<FromGitter> <renich> @oprypin how do I access house.location.lat there?
<oprypin> wait, i think it should work, right?
<oprypin> renich, well... by writing house.location.lat
<FromGitter> <renich> oprypin: nope, it doesn't work...
<oprypin> well ok it's nilable
<Groogy_> hmm Rx14 what am I doing wrong? https://play.crystal-lang.org/#/r/2and
<FromGitter> <renich> https://carc.in/#/r/2ane
<oprypin> renich, `house.location.not_nil!.lat` or something. or not make it nilable.
<FromGitter> <straight-shoota> RX14, Groogy it's either `macro finished` or `def finalize`
<Groogy_> finalize is for the GC
<FromGitter> <renich> oprypin: OK, I'll try that.
<RX14> damnit
<hightower2> oprypin, I am running into the following issue with YAML.mapping: https://play.crystal-lang.org/#/r/2ang
<RX14> sorry, my bad
<RX14> i misremembered the macro name
<Groogy_> but yeah finished
<Groogy_> nice
<Groogy_> thx
<hightower2> It is nilable, but still argument is required, and neither nilable: true (nor adding default: nil) helped
<Groogy_> that solved that headache xD
<RX14> np
<oprypin> hightower2, see example https://carc.in/#/r/2ac4 - must define constructor
<Groogy_> was bashing my head against a wall
<FromGitter> <straight-shoota> yes. I missed a bit from the discussion, so I am not sure what you were looking for
<oprypin> hightower2, nilable means it can be null in json and no error caused. but json/yaml mapping does not define a constructor
<FromGitter> <straight-shoota> the macro is still considered highly experimental (even more than the language itself) and therefore there are no docs for it
<oprypin> really?
<hightower2> oprypin, oh, so if I'm understanding it correctly, it always calls #new on the class with all arguments provided (even if nil), which is why it needs a specific constructor
<oprypin> hightower2, no, it does not call new and there is no such new in the first place
<hightower2> oprypin, I mean initialize...
<oprypin> same thing
<oprypin> YAML.mapping defines initialize(YAML::PullParser), no other method
<hightower2> I'm referring to the URL you pasted. Based on seeing "def initialize( @var1, @var2)" there, my understanding is that I need to create an initialize method which lists all fields/vars from JSON.mapping
<FromGitter> <straight-shoota> Groogy: here are more details: https://github.com/crystal-lang/crystal/pull/3612
<oprypin> hightower2, yes. all of them or some of them, whatever you actually need
<Groogy_> hmm now to just figure out why it won't override the function as I want to from the stored static data :/
<hightower2> oprypin, oh I understand, the problem is that without adding YAML.mapping(), I was able to just call "new()" and it worked. After adding YAML.mapping(), I also had to add a specific constructor which will get called when I call "new()"
<hightower2> With that addition in place, it works now
<oprypin> hightower2, hmm true that. when you have no constructor and no fields there is a default initialize
<Groogy_> don't have any good way to inspect WRAPPED_METHODS to see if it works as intended
<Groogy_> ge mig 5
<hightower2> oprypin, yeah. A little gotcha for users, maybe a note about it somewhere would be in order.
<Groogy_> adding a "puts "hahaha"" in the expansion of the for loop in the macro seem to output nothing :/
<oprypin> Groogy_, that's runtime code. maybe you meant {% puts "hahaha" %}
<oprypin> or {% debug() %}
<Groogy_> well the code is being expanded right? so technically it should expand that into a line of code saying "puts "hahaha""
<oprypin> i think it should but i have no idea what's happening in your code by now
<Groogy_> though tried, {% debug(WRAPPED_METHODS) %} and it gives me nothing :/
<oprypin> maybe explain the big picture of what you want to do and/or paste the complete code
<hightower2> Is there a way I can name types? E.g. I often repeat var : T1 | T2 | T3. Is there a way to have something like "type T = T1 | T2 | T3"? (There is "type", but using it as shown results in "can't declare constant dynamically)
<Groogy_> I did paste the complete code
<oprypin> hightower2, `alias` not `type`
<hightower2> wonderful, thanks
<oprypin> hightower2, I don't think there is `type`, could be any other word and you'd be getting the same error
<Groogy_> i.e, register the macro usage in "wrap" and then wrap around that function in in the macro finished
<Groogy_> if I write specifically the names then it works
<FromGitter> <straight-shoota> Groogy, `macro finished` must be defined on a type
<oprypin> Groogy_, :( I just read through the code and at every point i was like "yeah, that's not gonna work"
<hightower2> ok thanks for correcting, I was unclear on purpose of "type" :))
<oprypin> hightower2, do you mean that it highlights as a reserved word for you or what?
<Groogy_> according to RX14 it doesn't need to be on a type
<Groogy_> and I jsut tried and it works without a type
<Groogy_> It works, what is going wrong is saving the data to the constant
<Groogy_> which works but not as a tuple :/
<Groogy_> so need to find a better way to save the literal data
<hightower2> oprypin, (I use vim) it doesn't, I just mistakenly remembered that that was the keyword, didn't even look at coloring
<oprypin> ok
<FromGitter> <straight-shoota> why not: https://play.crystal-lang.org/#/r/2aob
<FromGitter> <straight-shoota> the `wrap` macro must be called before `finished` is invoked, inside a method definition this will probably not work
<oprypin> I have no idea how this works. it must be by accident.
<FromGitter> <straight-shoota> with this change your original code works as well: https://play.crystal-lang.org/#/r/2aof
<bmcginty> Anyone have a way to get some code from inside a macro/function/block pasted directly into another section of program?
<bmcginty> Basically like #defines in C, maybe?
<oprypin> bmcginty, probably but i dont get it
<FromGitter> <straight-shoota> do detail the order of execution: https://play.crystal-lang.org/#/r/2aoh
<oprypin> can anyone tell me how the compiler doesnt vomit on that `[] of Tuple(_, _)`
<hightower2> Ok I actually have a working YAML.mapping({}). Doesn't bail with error and creates properties as expected (all tests pass as if nothing happened). Writing converters for serializing/deserializing to/from YAML is the next step now.
<bmcginty> oprypin: I have boilerplate code I want to run for a bunch of different http routes, to give me convenience variables from a web request, and to set up a database connection.
<FromGitter> <straight-shoota> bmcginty, you can catch a block passed to a macro
<FromGitter> <coderhs> how would you do a YAML.mapping in crystal for a dynamic key? like `reader_1_ip:`, `reader_2_ip`. Each reader and its ip can be placed the YAML.
<oprypin> bmcginty, you should set up a function or some context instead of thinking about it as boilerplate code
<oprypin> macros don't tolerate defining new variables that weren't already in the scope
<FromGitter> <straight-shoota> oprypin, I wonder about that too. But the compiler doesn't care if a StringLiteral is appended to the array of tuples... https://play.crystal-lang.org/#/r/2aob
<oprypin> bmcginty, database connection would de def make_conn; c = Connection.new(asdf); yield c; finally c.close; end
<oprypin> convenience variables would be var1, var2, var3 = get_convenience_variables()
<oprypin> when i said `finally` i meant `ensure` like https://github.com/crystal-lang/crystal/blob/abd2dfd2/src/tempfile.cr#L62
<oprypin> ping me if something is not clear
<bmcginty> oprypin: thanks. I have the funtion returning a tuple now, but the individual types aren't being recognized. It's odd. THink I have a soltuion, though. Will try and shout here if it doesn't work.
<oprypin> bmcginty, I don't see why they would not be recognized. should work well.
xiljin has left #crystal-lang ["..."]
<FromGitter> <bew> @Groogy you can start from that: https://play.crystal-lang.org/#/r/2aou
<FromGitter> <bew> @oprypin for constants used in macros we can also use: `[] of _` :smile:
<oprypin> where did that come from?
<FromGitter> <bew> Don't know, I saw it in a project somewhere
<FromGitter> <bew> It's handy because the constants for macros don't care about the type and makes no checks, so it make no sense to put them
<FromGitter> <bew> And the compiler doesn't vomit on it because it's not used in actual code, so not type checking against real data
<FromGitter> <bew> Only macro usages.
<FromGitter> <straight-shoota> nice
<hightower2> By the way, my first crystal shard from yesterday: https://github.com/docelic/specreporter-spec
<hightower2> Adds "SpecFormatter" spec output format, similar to Ruby's of the same name
<crystal-gh> [crystal] matiasgarciaisaia opened pull request #4667: Statically link stdc++ (master...static-stdc++) https://git.io/vQzeX
<hightower2> oprypin, regarding your comments that default constructor is no longer there if there are some fields... Well, I did have property :x before and it worked
<hightower2> You know what I mean? I had property :x, as well as getter :y, setter :z... and just calling new() worked without any constructor written on my part
<oprypin> hightower2, default constructor is no longer there if there are some constructors
<hightower2> ok, that's clarifies, thanks
<oprypin> and if you have uninitialized fields, that's not gonna work out for ya with the default constructor
onionhammer1 has joined #crystal-lang
<oprypin> so i misworded it
<oprypin> but still mostly true
bjz has joined #crystal-lang
<hightower2> Ok, great, have YAML.mapping() working, at least the parts that don't involve custom converter
<Groogy_> hmm curious, straight-shoota, why do I have to make the macro outside the function for it to work?
<Groogy_> I mean it's not bad can still make this work, might be better
<Groogy_> it will end up looking like this I guess which isn't that bad
<oprypin> Groogy_, finally it's clear enough that you're making https://github.com/waterlink/spec2.cr
<Groogy_> No it's not specs
<Groogy_> it's contracts
<oprypin> ok
<Groogy_> think more defensive programming rather than TDD
<FromGitter> <straight-shoota> Groogy, the code in the method body is only evaluated by the compiler when the method is actually called somewhere. At this point, the type's `finished` macro hook has already been called
<Groogy_> aaaah
<Groogy_> that makes sense
<Groogy_> since every function in this language kind of behaves like a template right?
<oprypin> Groogy_, can't you just write these things inside the body of the function?
<oprypin> Groogy_, uh i suppose in c++ terms yes
<Groogy_> no tried, that's what I do in C++ or in D, but like what straight-shoota said I can't
<oprypin> Groogy_, i mean just write assert val.baz == true inside the function
<oprypin> (assert to be implemented)
<Groogy_> but yeah usually the point is to have it inline in the actual function but since I can't hijack a struct destruction on exit of scope I'll have to wrap the method instead to get proper behaviour
<Groogy_> yeah it's glorified assert
<Groogy_> but for instance you also have invariants which will guarrantee that on entry and exit to every method that they will hold true
<Groogy_> to make sure you are not left with a corrupt object, etc.
<Groogy_> Also the assert won't ensure that it is executed on every exit from the function, which ensure() will
<Groogy_> Also the assert won't ensure that it is executed on every exit from the function, which ensures() will
<FromGitter> <straight-shoota> you could try to replace `def`with a macro...
<Groogy_> nah this is good
<oprypin> namely, rather than specifying the function name twice, you pass the function *definition* to the macro
<oprypin> but reconstructing the function definition with arguments etc may be a problem, this is a simplified one
<oprypin> i gues
<oprypin> the general idea with macros, at least to me, has always been all about recursion, never about global state
<hightower2> I have a case where I need to implement obj<=>self, and basically the comparison comes down to comparing a series of instance variables. Is there any better approach than doing "r= @var<=>other.var; return r if r!= 0" for each of them?
<oprypin> but i guess that's mainly because i didnt know that stuff like was shown today was possible
<Groogy_> I mean you can sort of create global state in C++ as well with templates
<Groogy_> it is just very unintuitive
<oprypin> hightower2, first of all it could be a macro. {% for var in [:r, :g, :b] %} use {{ var.id }}
<oprypin> not macro in a literal sense, you dont actually need to write `macro macro_name`, just inline that
<oprypin> hightower2, i think `{@a, @b, @c} <=> {other.a, other.b, other.c}` should work
<hightower2> O boy, if that works that's stellar
<hightower2> let me try
<oprypin> https://crystal-lang.org/api/0.22.0/Tuple.html#%28other%3Aself%29-instance-method
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<oprypin> see also: https://crystal-lang.org/api/0.23.0/Object.html#def_equals%28%2Afields%29-macro unfortunately seems unapplicable to <=>
<bmcginty> Is there a reason Array(String) shouldn't be castable to JSON::Type?
<bmcginty> Ah, got it fixed ish.
<Groogy_> hmm if I define a macro in a module, that module can't be available for any classes that include that module right?
<Groogy_> since Macros are run before that
<oprypin> Groogy_, i think so
<FromGitter> <renich> Ah! crystal will not document stuff in /lib... :S
<oprypin> Groogy_, here's how i made private macros https://github.com/oprypin/crsfml/search?q=macro+extract
<Groogy_> oh my god that is super cool
<oprypin> renich, well yeah lib is supposed to be the folder where third party dependencies are put
<oprypin> why do you want to put stuff in lib
crnewb has joined #crystal-lang
<FromGitter> <renich> oprypin: I thought my API consumer should go there... I'll move it into src/<name>/
<crnewb> hi all. first time here
<oprypin> renich, your what?
<crnewb> I tried to recursively list all the files in a dir and it was 50 times slower than ruby
<crnewb> new to both langs
<FromGitter> <renich> @crnewb o/
<oprypin> crnewb, well show code and we'll try to tell you what went wrong
<crnewb> ok getting it back to how it worked one sec
<crnewb> testing
<oprypin> you can use https://bpaste.net/
<crnewb> ok
<crnewb> ran as: crystal dirs.cr `pwd`
<crnewb> or after building (just showing the arg)
<oprypin> tried without flush? crystal build --release dirs.cr && ./dirs `pwd`
<crnewb> yeah
<oprypin> and release?
<crnewb> it was so slow that I wondered if I needed flush to see it
<crnewb> it just hangs and prints it all out at the end
<crnewb> which is about 1 min
<crnewb> vs 1 second
<crnewb> (in ruby)
<FromGitter> <bew> Huh how many files do you have in there?
<crnewb> 76826 entries
<crnewb> i wanted to try the foreach syntax but can't get it
Disrecollection has joined #crystal-lang
<oprypin> crnewb, dont know any foreach syntax
<oprypin> what you have there is the idiomatic way
<oprypin> crnewb, don't take it as a sign that crystal is slow, it's just that ruby has an extremely optimized C implementation for that
<oprypin> and not that much thought has been put into performance in less used standard library modules
<oprypin> python went throught this phase, maybe worth copying their experience https://www.python.org/dev/peps/pep-0471/#rationale
<crnewb> there is a foreach here: https://crystal-lang.org/api/0.22.0/Dir.html
<crnewb> how do I use it
<oprypin> Dir.foreach("blah") do |entry|; use(entry); end
<oprypin> it's just a list of things in a directory (not nested)
<FromGitter> <mverzilli> wow, I love how they documented the discussion
<oprypin> mverzilli, you mean that python thing?
<oprypin> the effort for writing that document is way too much
<FromGitter> <straight-shoota> well 1 minute seems way to long even if stat is called on every file
<FromGitter> <straight-shoota> crnewb is it 1 minute including compilation or just running the binary?
<oprypin> compilation cant take time comparable to 1 minute
<oprypin> crnewb says they tried compilation separately, anyway
<crnewb> 1 minute execution
<crnewb> not including compile time
<crnewb> ok so foreach doesn't allow glob
<FromGitter> <mverzilli> yes, the effort is huge, so... respect
<crnewb> so maybe glob is poor performance
<FromGitter> <straight-shoota> python has a very scientific background and community ;)
<crnewb> keep in mind this is an old mac
<Papierkorb> If the OS isn't caching stat(), and you're using a slow HDD, that slow time makes sense
<oprypin> crnewb, i could tell you to try to remove the stat call, recompile crystal, and see what happens, but hmm
<crnewb> not a slow hd
<crnewb> super fast hd
<crnewb> hence still surviving with old mac
<Papierkorb> HDDs are never "super fast"
<crnewb> well, new solid state
<crnewb> that's what I meant
<crnewb> anyway ruby is almost instantaneous. But I'm excited about crystal existing.
<oprypin> oh `until` but why no foreach
<crnewb> i went with this : files = [] of String Dir[ARGV[0] + "/**/*"].each do |f| files << f end
<crnewb> still slow
<oprypin> crnewb, well yes, we didnt expect the printing to be the part that makes the diference
<Papierkorb> Is the glob matching implemented in Crystal, or is it an external lib?
<crnewb> yeah
<oprypin> Papierkorb, crystal, link above
<FromGitter> <straight-shoota> it's in crystal, converted to a regex :/
<Papierkorb> Line 228
<Papierkorb> For that glob a useless check
<FromGitter> <straight-shoota> indeed
<Papierkorb> For most globs a complete regex seems complete overkill
<oprypin> it's about making the implementation simpler
<Papierkorb> Doesn't make it fast
<FromGitter> <straight-shoota> I think it's just a quick and dirty solution intended to be improved upon
<oprypin> proper implementation is much larger and focus was put on getting it done
<Papierkorb> what straight-shoota says.
<FromGitter> <straight-shoota> though I wonder why they didn't just just glob from libc...
<oprypin> any dependency on non-crystal code is undesirable
<Papierkorb> straight-shoota, glob() may or may not exist on all platforms. Especially Windows.
<Papierkorb> And windows-only glob() bugs sound really nasty if one were to re-implement it just on Windows
<FromGitter> <straight-shoota> yes, but still, it would have been even cheaper and could be replaced with a proper Crystal implementation
<FromGitter> <straight-shoota> saving the effort to create an intermediary regex-based implementation
<Groogy_> Oh cool c++17 is gonna add contracts it seems
<Groogy_> anyway thx for the help straight-shoota and RX14, helped a ton to get started
<RX14> np
<FromGitter> <straight-shoota> you're welcome ;)
<FromGitter> <straight-shoota> initially `glob` from clib was used and replaced by pure-Crystal in #1487
<DeBot> https://github.com/crystal-lang/crystal/pull/1487 (Reimplementation of glob in Crystal)
<Groogy_> gonna finish up stuff tomorrow and put it up on github when done with some more extensive examples
<Groogy_> might read over this document before to see if I am missing something http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4415.pdf
<oprypin> lol i just removed scandir and it had no effect on speed whatsoever
<oprypin> sorry removed stat() call
hightower4 has joined #crystal-lang
<crnewb> cool. sounds like you guys know what's going on with it, and I'm not crazy. So this idea of crystal implementation vs c calls ... is compiled crystal still spinning up a self-contained interpreter?
<crnewb> i didn't know that
<crnewb> like a vm within a binary?
<oprypin> crnewb, there is no interpreter involved
<oprypin> would be nice to have it for macros though
<crnewb> just a lot a jumps in the code and loops?
<oprypin> crnewb, i am not sure what you mean
<FromGitter> <straight-shoota> Crystal is compiled into a binary which runs about as fast as C or other compiled languages
hightower2 has quit [Ping timeout: 255 seconds]
<hightower4> crnewb, btw, instead of `pwd`, you can use $PWD, and even simpler/better, just "."
<crnewb> sure
<oprypin> hightower4, using "$PWD" is discouraged
<hightower4> (it seemed to me he was just giving some quick example, didn't look into it in detail)
<hightower4> ok
<crnewb> the pwd is expanded before the pgm starts so that's the important part
<crnewb> my real goal was to time collecting ALL the files on a system, but I gave up
<crnewb> that was just my home dir
<crnewb> anyway, thanks for the discussion. ttyl
<crnewb> appreciate the help
crnewb has quit [Quit: Page closed]
<oprypin> forget my comment about $PWD, i guess it's just my personal feeling that it's too magical
<oprypin> but i would still prefer $(pwd) in every case. it's not actually running the pwd executable anyway
<hightower4> yes it's a builtin
<hightower4> but, I do believe that invoking $() in any case runs a process (i.e. does a fork at least)
<hightower4> hm, not sure
tzekid has quit [Remote host closed the connection]
<FromGitter> <fridgerator> has anyone used either the glove or crono game frameworks?
Groogy_ has quit [Quit: Leaving]
hightower4 has quit [Ping timeout: 260 seconds]
hightower4 has joined #crystal-lang
<oprypin> fridgerator, why not CrSFML though?
hightower4 has quit [Ping timeout: 258 seconds]
hightower4 has joined #crystal-lang
<FromGitter> <fridgerator> or that one :)