<FromGitter>
<renich> OK, I understand why x = 10 * 10000000000 is giving me some odd number. I don't understand why x = Int64; x = 10 * 10000000000 is not working...
<FromGitter>
<jsilverMDX> isnt it x : Int64
<FromGitter>
<renich> Jon: that word.... up until 99,999,999,999,999,999,999
<FromGitter>
<renich> @johnjansen wow! Cool, man! Thanks! Let me make sense of it.
<FromGitter>
<renich> why lines 12 and 13?
<FromGitter>
<renich> I mean, could we just live with line 13?
RX14 has quit [Ping timeout: 260 seconds]
<FromGitter>
<johnjansen> 12) because adding a mapping adds a constructor which takes yaml pull parser, and having 1 initializer means you cant do `Demo.new` anymore without meeting the requirements … ⏎ 13) for convenience given your example
<FromGitter>
<johnjansen> if you comment out 12 you will see the issue
<FromGitter>
<renich> ah, yes, overload according to method args... yes, I use that. Pretty cool.
<FromGitter>
<renich> I find math to be much easier. Even Then there are all kinds of floats/ints involved
Dreamer3_ has joined #crystal-lang
Dreamer3 has quit [Ping timeout: 260 seconds]
<FromGitter>
<johnjansen> why so many types? convenience?
hightower2 has joined #crystal-lang
hightower3 has joined #crystal-lang
hightower4 has quit [Ping timeout: 276 seconds]
<FromGitter>
... JSON request is returned with keys starting with a capital letter.
<FromGitter>
<coderhs> Hey How can i create a JSON.mapping for keys which are starting with a capital letter `{"Epc" => "000221153000000012500052", "Qty" => 1, "Upc" => "999999"}` when i do the following code `JSON.mapping(Epc: String, Qty: Int32, Upc: Int64)` i get error that it is expecting `)` not `:`. Also tried `JSON.mapping("Epc" => String, "Qty" => Int32, "Upc" => Int64)` works only if i place the key in smaller letter but my
<hightower2>
coderhs: I would say that you use a lowercase letter, but you do something like : myfield: { type: ..., key: "Qty" }
<FromGitter>
<crisward> @sdogruyol found the problem, the undying error is in the JSON parser, when you try and parse {} however it gets masked by another error. Suffice to say you can ignore this.
<FromGitter>
<renich> @crisward dude, you rock!
<FromGitter>
<renich> Now I can sleep nicely!
<FromGitter>
<akzhan> 1) 23
<FromGitter>
<bew> with a pointer on a struct, when I do `ptr.value` (to access or modify a field), will there be a copy of the struct?
<FromGitter>
<bew> the question is for lib's kind of structs
bjz has joined #crystal-lang
<FromGitter>
<krypton97> no need to do a pointer on a struct
<FromGitter>
<krypton97> you should use stack memory as much as possible
<FromGitter>
<krypton97> and no, if you pass by refference, there won't be any copy
<FromGitter>
<krypton97> but structs are passed by value by default
<FromGitter>
<bew> I think it's the special case of crystal's type system and accesses, do you know where `Pointer#value` and `Pointer#value=` are defined?
<FromGitter>
<sdogruyol> Yeah it should be removed
<FromGitter>
<sdogruyol> @w-p that's great :)
<w-p>
that said, the compiler asks you to use @@class_variables. does that make sense in the context of, for example, a kemal server with a few simple routes?
<Papierkorb>
w-p: If there is a possibility to not use globals, as there is most of the times, try to not use globals
<w-p>
right. so, static classes.
<Papierkorb>
Not using global-like variables doesn't really increase source code length, but improves maintainability considerably
<Papierkorb>
Static classes are globals
<w-p>
no argument from me.
<FromGitter>
<ziprandom> @sdogruyol ah ok, so you don't need any real logic. but you don't intend to run it against the real api for comparison (because it's not opensource i guess)
<Papierkorb>
If you really need a shared state, make that shared-state class a normal class, but store a reference to it somewhere. If needed, a global one (=> Singleton)
<w-p>
more like a configuration object pattern.
<Papierkorb>
Oh it's for immutable configuration?
<w-p>
in this case, yes.
<w-p>
runtime server configuration. similar to a Flask config dict / obj.
<Papierkorb>
In that case, it's acceptable. If you can, have no setters in there. YAML.mapping() supports this and you can easily read config with it too
<w-p>
oh cool. good call.
<FromGitter>
<sdogruyol> @ziprandom yep
splitty_ has joined #crystal-lang
mark_66 has left #crystal-lang ["PART #elixir-lang :PART #ruby :PING 1499349104"]
<FromGitter>
<eliasjpr> Hello everyone, just wanted to let everyone know that the Amber team has added support for Crystal v0.23.0 for those who already have the `amber cmd` just run a `brew update` on mac, for new installs `brew install amber-crystal/amber/amber`
<j0hnny>
hello everyone! is there a way to install an older version of crystal on ubuntu? say 0.22.0 instead of 0.23.0?
<FromGitter>
<bew> idk, but why would you want that?
bjz_ has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<j0hnny>
0.23.0 is breaking a few shards i'm using
<j0hnny>
namely Crecto
<FromGitter>
<fridgerator> yep crecto is broken in 0.23.0, haven't had a chance to address yet. I should be able to work on it tonight.
<FromGitter>
<fridgerator> I have a macro method `schema`, that is now throwing compiler error undefined method
rohitpaulk has joined #crystal-lang
<FromGitter>
<bew> @fridgerator when compiling `src/creto.cr` I only get an `undefined constant DB::Database` and adding `require "db"` on top of that file fixes the error
<FromGitter>
<fridgerator> `crystal spec` is when I see the error, or when including it in another project
<FromGitter>
<bew> ah yes I see it
<j0hnny>
hello fridgerator! yes i'm the one who posted the issue yesterday
<j0hnny>
thank you for looking at it!
<j0hnny>
and for the excellent library
<FromGitter>
<sdogruyol> yeah, thanks for crecto @fridgerator
splitty_ has quit [Ping timeout: 276 seconds]
unshadow has joined #crystal-lang
<FromGitter>
<bew> @fridgerator I recreated the error with: https://carc.in/#/r/2b7l (this code in 0.22 works, but not 0.23 (not available on carc.in yet))
Dreamer3_ has quit [Quit: Computer has gone to sleep.]
<FromGitter>
<gabrielrios> I think its related to #4639 @bew
<FromGitter>
<straight-shoota> @fridgerator 0.23.0 is broken, you should probably wait for 0.23.1 before fixing stuff that isn't necessarily wrong in crecto
<Papierkorb>
pre-release, a CI could probably just run the unit tests of popular shards. If it fails, something is off.
<FromGitter>
<molovo> That’s how NodeJS do it. It works really well for picking up unexpected bugs
<Papierkorb>
I mean it's not perfect, but besides setting up the script for it, comes almost for free
rohitpaulk has quit [Ping timeout: 248 seconds]
<FromGitter>
<straight-shoota> I think nightly builds are even more valuable, because then people will use them (for new features and stuff) and detect errors
<FromGitter>
<straight-shoota> Though, both would be nice^^
<FromGitter>
<molovo> You can already get that on Mac by tracking master with `brew install —HEAD crystal-lang`. I believe `apt` supports something similiar too, but I can’t remember the command off the top of my head
<FromGitter>
<fridgerator> thanks @straight-shoota , I just saw your issue referenced above
<FromGitter>
<fridgerator> Is there already a 0.23.1 scheduled?
<FromGitter>
<straight-shoota> should be coming soon I expect
<oprypin>
fridgerator, core team said it is important to have 0.23.1 soon but no concrete date
<FromGitter>
<mverzilli> there's already a PR for that
<FromGitter>
<mverzilli> we already fixed the key issues for apt
rohitpaulk has joined #crystal-lang
<FromGitter>
<mverzilli> now we're working on getting 0.23 packages for Ubuntu 12 and 14
<FromGitter>
<mverzilli> (related to the glibc/stdc++ issues)
<FromGitter>
<mverzilli> we'll probably have to stick with LLVM3.5 just for Centos packages
<FromGitter>
<mverzilli> no dates, but we'll probably release once we have Ubuntu 12 and 14 packages again
<FromGitter>
<fridgerator> :thumbsup:
<Yxhuvud>
mverzilli: Do you care about Centos that much? They do tend to have packages from the stone age, so if you limit yourself to them you are in for a world of pain in the long run.
<Yxhuvud>
I wonder this after being stuck with ruby 1.8.7 for something like 4-5 years longer than the rest of the world.
j0hnny has quit [Quit: Page closed]
<FromGitter>
<mverzilli> (on a call, will reply that in 5 minutes, sorry)
<Yxhuvud>
no worries, I'm not in a rush.
unshadow has quit [Quit: leaving]
<Yxhuvud>
hmm, I wonder why llvm hasn't provided binaries for redhat derivates since 3.9.
<FromGitter>
<elorest> @bew about a year ago.
<FromGitter>
<mverzilli> Yhuvud: there were reports of some people that was aiming to use Crystal on Centos for production, and we don't want to let them out. The middle ground we found is to just stick to LLVM3.5 for redhat derivatives, so that doesn't leave as anchored on the rest of the distros/platforms
<Papierkorb>
Wasn't llvm3.5 super broken, as in release builds producing wrong SHA1 hashes and such?
<FromGitter>
<mverzilli> that complicates a bit the release and leaves some code in the codebase that ideally we'd like to remove, but it's best tradeoff we can think of
<FromGitter>
<mverzilli> Papierkorb, I'm not sure if "super broken", there were some issues that happened with LLVM3.5 and just went away since LLVM3.8
<oprypin>
llvm3.5 really is super broken, there are random memory corruptions
<oprypin>
in my world view centos is also totally broken but whatever
<FromGitter>
<mverzilli> lol
<FromGitter>
<mverzilli> the fact that we have some bugs with LLVM3.5 that stopped happening in LLVM3.8 doesn't mean LLVM3.5 is broken. It could be a problem on Crystal's side that we couldn't identify
<FromGitter>
<mverzilli> so, what we want to do is, still publish packages for CentOS with LLVM3.5, to not let CentOS users out of the loop
<oprypin>
what about those memory corruptions though
<FromGitter>
<mverzilli> then I guess we would welcome PRs fixing a LLVM3.5 issues in Crystal
<FromGitter>
<bew> are there similar LLVM3.5 issues in other LLVM-based languages?
<FromGitter>
<mverzilli> not that we're aware of, but we didn't research that
<oprypin>
maybe it's possible to bisect on llvm?
<oprypin>
mmmm nope, building llvm is too cmplicated
<hightower2>
I have a situation where I have 2 variables, both of which can be Nil | Int | Bool | Range. And I need to "compare" them (whatever my specific "comparison" may be between two types). Since this is in total 8 combinations (and possibly will grow), how do I best implement this comparison? Anything "better" than simply the main 'case' statement for var1 and then under each 'when' to put the the whole 'case' statement for var2?
<Yxhuvud>
I think I'd try to figure out a way to get a better type signature in that case
<hightower2>
Yxhuvud, there isn't any. I intentionally provide the user with the option to specify any of these types, for his convenience
<hightower2>
(and I then work with these types because it suits my application to have e.g. a Range instead of "expanding" it into e.g. array)
<Papierkorb>
hightower2: What kind of comparison? equal, or <, > ?
<oprypin>
hightower2, could be `private def compare(a : Int | Range, b : Bool)`
<oprypin>
then `private def compare(a, b); compare(b, a)` .. maybe?
<oprypin>
uh `-compare`
<hightower2>
Papierkorb, yes, basically my comparison between any of these types is "does A include B", where if number, it's a==b, if range, it's a.includes? b, if nil then true, if false then no.
<hightower2>
but it's a bit more complicated since both a and b can have all listed types, including the comparison between range == range etc.
<hightower2>
(which I consider true if one range is within other)
<oprypin>
hightower2, im saying instead of series of `case` you define a series of methods and use dispatch
<hightower2>
Oh pretty cool, yeah I could use overloading here
<hightower2>
Coming from Ruby I keep forgetting about it :)
<hightower2>
wonderful, looks really clean
<hightower2>
I need to check if array a includes all elements from array b. Any suggestions how to do it optimally?
<hightower2>
(Int elements)
<Papierkorb>
Are any of them sorted?
<FromGitter>
<johnjansen> `a.all?(b)`
<oprypin>
wait what
<FromGitter>
<johnjansen> i think … its in enum
<oprypin>
no
<oprypin>
hightower2, by default it's an n squared complexity
<oprypin>
make both of them into sets
rohitpaulk has quit [Ping timeout: 240 seconds]
<oprypin>
or at least one of them
<oprypin>
a.all? { |x| b_set.includes? x }
<FromGitter>
<johnjansen> that was wrong, but the method is there … whats the magic incantation
<hightower2>
Yes, they are sorted, I am comparing two Enumerable(Int)s while these originally come from Range(Int,Int) and from Range::StepIterator(Range(Int32, Int32), Int32, Int32)
<FromGitter>
<johnjansen> haha, yeah … sorry about that
<Papierkorb>
hightower2: So you want to know if range a includes range b?
<oprypin>
Papierkorb, well it's stepiterator also which is annoying
<hightower2>
Papierkorb, yes, but also Range::StepIterator, so I might have to compare 1..10 with 1,3,5,7,9
<oprypin>
how i miss python's great abstractions sometimes
<Papierkorb>
hightower2: Then both sets are sorted, you can do that in O(n) easily
<oprypin>
johnjanse, > it's an n squared complexity
<oprypin>
stepiterator can have negative step
<oprypin>
if you have two stepiterators with opposite steps it's impossible to compare them without saving at least one of them completely into memory
<Papierkorb>
hightower2: #each over a, take an iterator over b. Then, check if the current element from a is the current element from b's iter. If yes, advance b's iter. Outside the #each, make sure b's iter is at its end.
<hightower2>
that too, although it's still sorted, and in my case it doesn't matter if it's going 10..1 or 1..10. I can turn it around to avoid negatives.
rohitpaulk has joined #crystal-lang
<oprypin>
basically stepiterator should not be an entity to deal with
<hightower2>
Small... couple elements usually, but max up to 1000 elements
<FromGitter>
<johnjansen> and what types of elements
<hightower2>
oprypin, yes, that's why I reduced the comparison to Enumerable(int) with Enumerable(Int), to avoid dealing with StepIterator and also because this same type matches both Ranges and StepIterator
<hightower2>
johnjansen: all its
<hightower2>
Ints32s
<FromGitter>
<johnjansen> thanks
<Papierkorb>
I already gave the algorithm for O(n).
<hightower2>
Sure
<hightower2>
Thanks!
<oprypin>
Papierkorb, it is impossible to apply that algorithm
<Papierkorb>
oprypin: Proof
<oprypin>
i still recommend `a.all? { |x| b_set.includes? x }`
<oprypin>
where b_set = b.to_set
<oprypin>
Papierkorb, i dont have a proof, it's obvious > if you have two stepiterators with opposite steps it's impossible to compare them without saving at least one of them completely into memory
<hightower2>
Papierkorb, if I have a = [ 1.. 10], and I have b which uses StepIterator, 2nd element in a will be 2, while 2nd in StepIterator will be 3
<hightower2>
yes
<hightower2>
1..10 compared to (1..10).step(2)
<oprypin>
if you can never have a negative step, then what Papierkorb is saying is good
<Papierkorb>
oprypin: You have enumerables. I said that I assume them to be sorted in correct order. If both are true, my algorithm holds true.
<oprypin>
hightower2, your example does not break Papierkorb's idea
<oprypin>
so negative step is not a thing then. just need to exclude downtoiterator
<Yxhuvud>
Why are you complicating so much? (x - y).empty? is what you want, where x is the elements that must be in y.
<oprypin>
Yxhuvud, I don't think comparing 1..1000 and 2..1001 in a million operations is a good idea
<hightower2>
haha
<hightower2>
cool idea though, I didn't come to think of it :)
<Yxhuvud>
oprypin: The question was about arrays, and the way I gave is not quadratic for that (unless the #- implementation has some really easy improvements that is possible). Ranges clearly have a better solution.
<hightower2>
Ok, in the end I went with oprypin's suggestion of b.all?{ |i| a_set.includes? i}
<hightower2>
thanks!
<oprypin>
Yxhuvud, Array#- cant be better than quadratic
<Yxhuvud>
huh?
<Yxhuvud>
hint: check the implementation.
<oprypin>
right, that...
<oprypin>
then i guess Yxhuvud's way is the same thing but i guess with one more allocation
<FromGitter>
<johnjansen> this might be a stupid question, but @hightower2 do you need to know if the items in b ARE in a, of that they MIGHT BE?
<FromGitter>
<johnjansen> im assuming the answer is “ARE” ;-)
<FromGitter>
<johnjansen> but just checking
<hightower2>
johnjansen: ARE, I'm looking for behavior of (array a) includes? (array b)
<FromGitter>
<johnjansen> nice, had to ask …
<FromGitter>
<johnjansen> are you up for implementing a different data structure if necessary, or is that too bigger hammer?
<FromGitter>
<johnjansen> i know you have a solution for now
DTZUZU has quit [Quit: WeeChat 1.5]
<hightower2>
Sure, I'm up for ideas
Groogy has quit [Disconnected by services]
Groogy_ has joined #crystal-lang
greengriminal has joined #crystal-lang
<hightower2>
Mm, pretty funny. I have a YAML converter, and when I call #to_yaml, the method does case( value) ... And I have "when Range(Int32, Int32)", but this case is not matched and instead the code goes to "else" in which I have "raise "Uknown type: #{value.class}"", and it reports value as being exactly Range(Int32,Int32).
<oprypin>
hightower2, you lost me midway there
<oprypin>
oh yeah i see
<oprypin>
please just make a minimal reproducible example
<oprypin>
hightower2, i remember someone tried to redefine ===
<hightower2>
oprypin, hehe yes, I checked for that, I don't have any redefines of any operator on any class
<hightower2>
(I had, but I removed all of them earlier today, triple-checked with grep etc.)
<FromGitter>
<johnjansen> anyone got any suggestions about how to approach / isolate / avoid the following error, which occurs while trying to save a large msgpack string ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=595e8f99329651f46e5f34bb]
<oprypin>
this error means "something somewhere went wrong"
<oprypin>
so no, probably can't isolate it based on that
<FromGitter>
<johnjansen> haha, yeah thats what i thought … would it make any sense to try this with crystal 0.22.0 ?
<FromGitter>
<johnjansen> it 0.23 now
<oprypin>
i dont know
<FromGitter>
<johnjansen> ok … makes 2 of us ;-)
greengriminal has quit [Quit: This computer has gone to sleep]
greengriminal has joined #crystal-lang
Dreamer3 has quit [Remote host closed the connection]
<RX14>
we really should have a flag to disable the sigfault handler
<FromGitter>
<johnjansen> @RX14 just the person i need ;-)
<FromGitter>
<johnjansen> im trying to serialize the NET tst to msgpack (serialize branch of TST) … this is happening at the 32+M mark … and its not related to write, i cant even pack.size without the problem … trying to isolate now (running tst.words to see if its our side)
<FromGitter>
<johnjansen> at least as a starting point
<RX14>
shouldn't be anything unsafe now
<RX14>
did you compile without --release?
<FromGitter>
<johnjansen> i did not
<FromGitter>
<johnjansen> i will try that
<RX14>
it'd get you a much better stacktrace
<RX14>
well
<RX14>
maybe
<FromGitter>
<johnjansen> its not 0.23.0 either as i tried with 22
<FromGitter>
<johnjansen> rescue wont trap it either … just bails out
<FromGitter>
<johnjansen> actually it *might* be to_msgpack ...
<RX14>
yeah lol a rescue won't rescue a sigfault
<RX14>
there's really no recoverable action
<FromGitter>
<johnjansen> haha, i expect more ;-)
<FromGitter>
<johnjansen> its `to_msgpack` so yeah …
<RX14>
yeah maybe msgpack is playing with pointers
<hightower2>
And in the example of course the result of those tests us true, as it should be
greengriminal has quit [Quit: This computer has gone to sleep]
<hightower2>
But in my case here, I get false to all of the tests, including === and is_a?
<hightower2>
And I for sure didn't override any of these methods.
<oprypin>
hightower2, you gotta isolate it though. if you cant any further, at least put it in 1 file and show it
<hightower2>
Yeah I'll try that, will try putting in one file and trimming down the code until it either becomes isolated or I identify which block of code made a difference
<hightower2>
Got it reproduced in single-file approach, now to trim
<FromGitter>
<johnjansen> if i gsub out downcase.gsub(/[^a-z0-9\-\.]+/, “") it works
<oprypin>
gsub out gsub?
<oprypin>
that must be your code
<FromGitter>
<johnjansen> damn … just moved the problem
Dreamer3 has quit [Remote host closed the connection]
Dreamer3 has joined #crystal-lang
Dreamer3 has quit [Ping timeout: 268 seconds]
<hightower2>
Mm, oprypin , I got somewhere. I have my type defined as: alias Virtual = Nil | Int32 | Bool | Range(Int32, Int32) | Enumerable(Int32) | Proc(Int32, Bool). And even though my object is Range(Int32,Int32), the existence of Enumerable in this list made that be preferrable over the explicit Range(Int32,Int32) type. My mistake was that I didn't check typeof(). When Enumerable is not in the list, typeof() reports (Bool | Int32 | P
<hightower2>
roc(Int32, Bool) | Range(Int32, Int32)). When it is in the list, typeof() reports (Bool | Enumerable(Int32) | Int32 | Proc(Int32, Bool))
<hightower2>
Not sure if this is some kind of a bug/problem, or just an unintuitive, but correct/expected behavior.