<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>
<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>
<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>
<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?
<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>
<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?
<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"
<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
<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> 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>
<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
<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> 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>
<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>
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>
<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>
<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 `:%`..
<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
<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> 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 :)
<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'?)`
<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.
<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
<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
<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 :/
<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)
<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()
<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.
<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
<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...
<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
<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?