jhass changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.7.4 | Paste > 3 lines of text to https://gist.github.com | GH: https://github.com/manastech/crystal - Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/ | Logs: http://irclog.whitequark.org/crystal-lang
daneb has quit [Remote host closed the connection]
daneb_ has joined #crystal-lang
Locke23rus has quit [Remote host closed the connection]
waj has joined #crystal-lang
datanoise has quit [Ping timeout: 250 seconds]
havenwood has quit [Quit: Textual IRC Client: www.textualapp.com]
daneb_ has quit [Remote host closed the connection]
ozra has quit [Ping timeout: 246 seconds]
waj has quit [Quit: waj]
havenwood has joined #crystal-lang
<crystal-gh> [crystal] asterite pushed 1 new commit to master: http://git.io/vtGSm
<crystal-gh> crystal/master c1ec553 Ary Borenszweig: Fixed: abstract class/struct inside macro didn't count as opening
havenwood has quit [Ping timeout: 276 seconds]
waj has joined #crystal-lang
<travis-ci> manastech/crystal#2556 (master - c1ec553 : Ary Borenszweig): The build passed.
datanoise has joined #crystal-lang
havenwood has joined #crystal-lang
waj has quit [Quit: waj]
waj has joined #crystal-lang
waj has quit [Quit: waj]
havenn has joined #crystal-lang
havenn has quit [Remote host closed the connection]
havenn has joined #crystal-lang
havenwood has quit [Ping timeout: 264 seconds]
vikaton has joined #crystal-lang
waj has joined #crystal-lang
waj has quit [Quit: waj]
havenn is now known as havenwood
bcardiff has joined #crystal-lang
<crystal-gh> [crystal] will opened pull request #863: add Benchmark.ips (master...ips) http://git.io/vtZg0
havenwood has quit [Ping timeout: 244 seconds]
bcardiff has quit [Quit: Leaving.]
qb has quit [Quit: sage]
qb has joined #crystal-lang
BlaXpirit has joined #crystal-lang
unshadow has joined #crystal-lang
<crystal-gh> [crystal] will opened pull request #864: docfix: the accumulator is the first argument in Enumerable#inject (master...docfix) http://git.io/vtZ5B
Ven has joined #crystal-lang
datanoise has quit [Ping timeout: 252 seconds]
Ven has quit [Read error: Connection reset by peer]
daneb has joined #crystal-lang
vikaton has quit [Quit: Connection closed for inactivity]
NeverDie has quit [Quit: I'm off to sleep. ZZZzzz…]
datanoise has joined #crystal-lang
daneb has quit [Remote host closed the connection]
daneb has joined #crystal-lang
daneb has quit [Remote host closed the connection]
daneb has joined #crystal-lang
datanoise has quit [Ping timeout: 264 seconds]
Ven has joined #crystal-lang
daneb has quit [Remote host closed the connection]
daneb has joined #crystal-lang
Ven has quit [Read error: Connection reset by peer]
daneb has quit [Remote host closed the connection]
daneb has joined #crystal-lang
BlaXpirit has quit [Quit: Quit Konversation]
BlaXpirit has joined #crystal-lang
vesakaihlavirta has joined #crystal-lang
vesakaihlavirta is now known as vegai_
<vegai_> howdy!
<vegai_> I see from some examples that there's some form of limited string formatting like in python
<vegai_> i.e. "%.4f ms" % elapsed works
daneb has quit [Read error: Connection reset by peer]
<vegai_> but then '"%s %.4f ms" % path, elapsed' does not
<vegai_> what's the proper form, then?
<vegai_> neither does '"%s %.4f ms" % (path, elapsed)'
<jhass> >> "%s %.4f ms" % {"elapsed", 123.12345}
<DeBot> jhass: # => "elapsed 123.1235 ms" - http://carc.in/#/r/5a7
<jhass> \o/ guessed right
<vegai_> ohh, takes a dict?
<jhass> it's actually technically the same as python there, {a, b, c} are tuples in Crystal
<vegai_> ok
<jhass> >> "%s %.4f ms" % ["elapsed", 123.12345]
<DeBot> jhass: # => "elapsed 123.1235 ms" - http://carc.in/#/r/5a8
<jhass> array works too though
<jhass> I guess anything with an each method
daneb has joined #crystal-lang
<vegai_> "%s %.4f ms" % "foo", "bar"
<vegai_> >> "%s %.4f ms" % "foo", "bar"
<DeBot> vegai_: Syntax error in eval:4: unexpected token: NEWLINE - http://carc.in/#/r/5a9
<jhass> yap, no implicit arrays or tuples
<vegai_> hmm
<vegai_> if I put that in a file and compile it, the compiler is fine with it
<vegai_> breaks at runtime with "Unhandled exception: too few arguments"
<jhass> you're sure? http://carc.in/#/r/5aa
<vegai_> jhass: yes :) http://carc.in/#/r/5ab
<jhass> ah, the assignment makes a difference
<vegai_> yeah, apparently
<jhass> well, I lied, there's an implicit array on the right hand side of assignments ;)
<jhass> or is it a tuple?
<jhass> >> a = 1, 2; a.class
<DeBot> jhass: # => Array(Int32) - http://carc.in/#/r/5ag
<jhass> no, array
<jhass> str = [("%s %.4f ms" % foo), bar] so it's that
<vegai_> ah
<vegai_> implicit array
DeBot has quit [Quit: Crystal IRC]
DeBot has joined #crystal-lang
Ven has joined #crystal-lang
Kilobyte22 has joined #crystal-lang
vegai_ has quit [Ping timeout: 264 seconds]
vegai_ has joined #crystal-lang
Ven has quit [Read error: Connection reset by peer]
Ven has joined #crystal-lang
<Kilobyte22> can i mark a value in a c enum as volatile
<Kilobyte22> or do i even need to do that
<jhass> I think there's a ##c ;)
<jhass> or you mean inside a lib?
<jhass> no idea there
<Kilobyte22> yes
<Kilobyte22> also, what type is 32 bit uint?
<jhass> UInt32
<Kilobyte22> how complete is the pthread wrapper? does it have barriers?
<Kilobyte22> is there actually one?
<vegai_> do I typically have to initalize Hashes before using them?
<Kilobyte22> i don't see anything in the docs
<Kilobyte22> vegai_: depens on what you mean by initialize
<Kilobyte22> hash = {} of KeyType => ValueType
<Kilobyte22> thats what you want
<Kilobyte22> (or was it a ->?)
<vegai_> it seems to be =>
Kilobyte22 has quit [Quit: http://www.kiwiirc.com/ - A hand crafted IRC client]
<vegai_> problem is, I intend to initialize a two-level hash as an instance var
<vegai_> like @foo = {} of Symbol => Hash
<vegai_> then @foo[:bar] of Symbol => String
Kilobyte22 has joined #crystal-lang
<Kilobyte22> what was my last message
<vegai_> gives me a compiler error "undefined method '[]=' for Nil
<vegai_> 14:03 < Kilobyte22> (or was it a ->?)
<vegai_> and while you were away I said
<vegai_> 14:04 < vegai_> problem is, I intend to initialize a two-level hash as an instance var
<vegai_> 14:04 < vegai_> like @foo = {} of Symbol => Hash
<vegai_> 14:04 < vegai_> then @foo[:bar] of Symbol => String
<vegai_> the second line is actually @foo[:bar] = {} of Symbol => String
<Kilobyte22> yes
<Kilobyte22> what line is the error in?
<Kilobyte22> oh wait
<jhass> >> foo = {bar: {} of Symbol => String}
<DeBot> jhass: # => {:bar => {}} - http://carc.in/#/r/5aj
<Kilobyte22> the compiler gives @foo the type Nil | Hash(...)
<Kilobyte22> you need to assign it in all constructors or the class body
<vegai_> ohh
<jhass> >> foo = {} of Symbol => Hash(Symbol, String); foo[:bar] = {} of Symbol => String
<DeBot> jhass: # => {} - http://carc.in/#/r/5ak
<jhass> >> foo = Hash(Symbol, Hash(String, String)).new {|h, k| h[k] = {} of Symbol => String }; foo[:bar]
<DeBot> jhass: Error in line 4: no overload matches 'Hash(Symbol, Hash(String, String))#[]=' with types Symbol, Hash(Symbol, String) - http://carc.in/#/r/5al
<jhass> uh
<jhass> >> foo = Hash(Symbol, Hash(Symbol, String)).new {|h, k| h[k] = {} of Symbol => String }; foo[:bar]
<DeBot> jhass: # => {} - http://carc.in/#/r/5am
<jhass> so, not entirely clear what variant you want, so here you got them all ;)
Ven has quit [Read error: Connection reset by peer]
<vegai_> that seems to work for method local variables, but not for instance vars
<vegai_> >> @foo = Hash(Symbol, Hash(Symbol, String)).new {|h, k| h[k] = {} of Symbol => String }; @foo[:bar]
<DeBot> vegai_: Error in line 4: can't use instance variables at the top level - http://carc.in/#/r/5an
<vegai_> meh :)
<vegai_> or perhaps that works, but some magic Amethyst does is not quite what I need
<vegai_> perhaps it doesn't deep copy the instance variables to the views, or something
* jhass shrugs
<Kilobyte22> vegai_: a hash is empty
<Kilobyte22> so your new() is useless
<Kilobyte22> (a new one that is)
<vegai_> well clearly amethyst views are a bit wip
Kilobyte22 has quit [Quit: http://www.kiwiirc.com/ - A hand crafted IRC client]
Kilobyte22 has joined #crystal-lang
Kilobyte22 has quit [Client Quit]
Kilobyte22 has joined #crystal-lang
Ven has joined #crystal-lang
waj has joined #crystal-lang
Kilobyte22 has quit [Quit: http://www.kiwiirc.com/ - A hand crafted IRC client]
Ven has quit [Read error: Connection reset by peer]
<vegai_> would be cool if multilevel hashes'd be a bit more robust
daneb has quit [Remote host closed the connection]
<jhass> what do you mean?
daneb has joined #crystal-lang
<vegai_> well, for one, if they could be used as instance variables :)
<vegai_> but I'll certainly check if this is just me doing something foolish instead of crystal doing the same before suggesting anything
<vegai_> odds are that the former is true
<jhass> I'm pretty sure instance variables can point to nested hashes
waj has quit [Quit: waj]
<vegai_> jhass: seems like that thing died already
<jhass> huh?
<vegai_> your link there gives me an empty editor
<vegai_> oh, what. Now it works
<jhass> weird
<vegai_> one of those days
<vegai_> jhass: shouldn't this work then? http://carc.in/#/r/5c7
<jhass> why would it? I didn't setup any auto vivification
<vegai_> oh, I need to initialize all the previous levels
<vegai_> yeah
<vegai_> I'm spoiled by the hashes of more dynamic languages, I suppose
<jhass> well, Ruby would throw a NoMethodError on NilClass there ;)
<vegai_> huh, indeed
<vegai_> I'm spoiled by my stupidity, then
<jhass> :P
Ven has joined #crystal-lang
bcardiff has joined #crystal-lang
ozra_ has joined #crystal-lang
Ven has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
havenwood has joined #crystal-lang
Ven has joined #crystal-lang
NeverDie has joined #crystal-lang
Ven has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
waj has joined #crystal-lang
daneb_ has joined #crystal-lang
daneb has quit [Read error: Connection reset by peer]
<vegai_> jhass: http://carc.in/#/r/5fn hmm
<vegai_> and this works
Ven has joined #crystal-lang
<vegai_> oddly enough, this too http://carc.in/#/r/5fs
<vegai_> is that a bug
<jhass> vegai_: yes, because @foo is nilable because you didn't set it in an initializer
<jhass> it's not a bug
<jhass> same issue
bcardiff has quit [Quit: Leaving.]
Ven has quit [Read error: Connection reset by peer]
Ven has joined #crystal-lang
<vegai_> ah, ok. I guess you said that already
bcardiff has joined #crystal-lang
daneb has joined #crystal-lang
daneb has quit [Remote host closed the connection]
daneb_ has quit [Ping timeout: 248 seconds]
<ozra_> I'm still new to this with garbage collecting. There are some black-box core work I think would as well be kept out of GC knowledge in my test - how do I allocate / deallocate memory manually?
<jhass> uh, I guess you'd have to rebind libc's malloc and free
<jhass> try to trust the GC for a while though ;)
<ozra_> The way I've understood things, the GC implementation used by Crystal essentially scans through all of memory looking for pointers to alloced memory to determine use? So reducing the amount of memory it has to search should be good, no? Or better yet: is there some way to hint "this memory area contains no pointers - don't bother scanning it". Or have I completely misunderstood the workings? :)
<ozra_> jhass: Ok.
datanoise has joined #crystal-lang
<jhass> as I understood it you push regions as "roots" to it from which it scans for pointers allocated by the GCs malloc wrapper, possibly following those until it finds no new ones
<jhass> so not the entire memory in theory, just in practice
<ozra_> essentially, using type info, it could bo ordered to scan only variables that actually _are_ pointers/references? But it is not implemented currently?
<ozra_> (including of course, instance vars, arrays of ptr etc..)
<jhass> what's not a reference?
datanoise has quit [Ping timeout: 244 seconds]
<ozra_> jhass: arrays of ints, bytes, doubles what not..
<jhass> uh
<jhass> well, everything is possible
<jhass> whether we should spend that much effort with bdwgc I don't know, it's not unlikely that we'll end up with our own GC at some point
<ozra_> jhass: Yeah, I'm just trying to get a grip on the process, being used to C++ new/delete. Yeah, it's cool to just get an understanding, I guess I am an optimizing speed freak some times - I just don't like the idea of wasted energy and cycles, haha. I'm starting to like Crystal a lot, so when it's time for a Crystal native GC, I might jump in and help out :-)
<jhass> ozra_: being deeply inspired by a dynamic language, I think you should try the Ruby programming style with Crystal, that is write beautiful code, then optimize the parts that actually prove to be a bottleneck
vegai_ has quit [Ping timeout: 272 seconds]
<jhass> it's not unlikely that one wastes time trying to come up with the most efficient implementation where you never need it and thus don't have time left for the part that you really need to optimize
<jhass> After all fast prototyping is one of the main aspects that made Ruby popular and I feel that transported to Crystal quite a bit, having and relying on a GC is just one big part of that
<ozra_> jhass: I've always coded performance needing things, and it's only the hot paths I optimize - of course - for all setup code, ui code, etc. I would love to be able to use more dynamic constructs. C++ is terrible in that regard. So, in my primary tests now, I am putting a lot of focus on the performance parts, to see how Crystal holds up - because I reaaaally want to ditch C++.
vegai_ has joined #crystal-lang
<ozra_> Yeah, I've come to accept GC, it's a good thing (TM) - I just want to be able to hint things when one needs to minimize unnecessary memory touching to keep throughput maximal.
<ozra_> Also, fast prototyping is essential - Crystal is a real win in this regard. Superb.
<ozra_> So, that's why a lot of my questions in my initial "investigation" are very low-level centric - that's where many languages fail / ignore...
<jhass> https://github.com/manastech/crystal/blob/master/src/gc/boehm.cr is pretty much the whole binding, if you rebind the LibC malloc, you can wrap the result in a pointer and get a crystal object with .value (and probably need to call the initializer by hand), that should completely bypass it
<jhass> if the GC doesn't see the allocation it doesn't track it
<jhass> bdwgc also has a bunch more stuff like GC_malloc_ignore_off_page that's not bound currently
<ozra_> jhass: Ok, so If I allocate a 1GB buffer of doubles manually (but I will keep a pointer to this in GC collected instance) it won't search it, cause it doesn't point to any known GC allocation, right?
<ozra_> jhass: And so mmap's should be safe already - since they're not alloced by GC.
<jhass> mh, I guess
<ozra_> cool.
<ozra_> Thanks, will look around.
asterite has joined #crystal-lang
datanoise has joined #crystal-lang
<asterite> ozra_: about the memory, it's true: the less you allocate, the better your program will behave because the GC will have to scan through less memory
<asterite> You also have GC.malloc_atomic to allocate memory that you know doesn't have pointers. String for example uses that instead of the regular Pointer.malloc
<asterite> Also, don't worry about the current GC, it can always be improved. waj is also investigating this: https://www.ravenbrook.com/project/mps/
bcardiff1 has joined #crystal-lang
<ozra_> asterite: Aha, does the same go for arrays of non pointer data?
bcardiff has quit [Ping timeout: 264 seconds]
<asterite> Not right now. I think Pointer.malloc should be smarter about that, delegating to malloc or malloc_atomic.
<asterite> But, in my few experiments, I didn't notice a huge difference between malloc and malloc_atomic
Ven has quit [Read error: Connection reset by peer]
Ven has joined #crystal-lang
<ozra_> asterite: I assume it's for special cases where you have laaaarge arrays it becomes apparent. If the distinction by crystal is more or less cost free it should be better for those cases in any event.
<ozra_> Is there a "don't follow" pointer type, to use for mmaped and malloced mem - or is that completely unnecessary?
<asterite> What's "don't follow"?
<crystal-gh> [crystal] asterite pushed 2 new commits to master: http://git.io/vtCFz
<crystal-gh> crystal/master cafe935 Will Leinweber: docfix: the accumulator is the first argument in Enumerable#inject
<crystal-gh> crystal/master ca30398 Ary Borenszweig: Merge pull request #864 from will/docfix...
<ozra_> Mmm, I guess it will only compare the pointer to existing gc-regions, so it's probably not worth the effort - to make it an 'ignored' pointer...
<crystal-gh> [crystal] asterite pushed 4 new commits to master: http://git.io/vtCFN
<crystal-gh> crystal/master 505b28d rhysd: Add Array#transpose...
<crystal-gh> crystal/master f1961ba rhysd: Use IndexOutOfBounds instead of IndexError
<crystal-gh> crystal/master b89e6f0 rhysd: Enable Array#transpose to transpose union elements
waj_ has joined #crystal-lang
waj has quit [Ping timeout: 264 seconds]
waj_ is now known as waj
<crystal-gh> [crystal] asterite closed pull request #863: add Benchmark.ips (master...ips) http://git.io/vtZg0
<travis-ci> manastech/crystal#2560 (master - ca30398 : Ary Borenszweig): The build passed.
Ven_ has joined #crystal-lang
Ven has quit [Ping timeout: 255 seconds]
shevy has joined #crystal-lang
<jhass> >> puts "hi shevy"
<DeBot> jhass: hi shevy - more at http://carc.in/#/r/5gb
<shevy> you are in the wrong channel guys!
shevy has left #crystal-lang ["I'll be back ... maybe"]
centrx has joined #crystal-lang
<travis-ci> manastech/crystal#2562 (master - b9052d1 : Ary Borenszweig): The build passed.
asterite has quit [Quit: Page closed]
vegai_ has quit [Ping timeout: 255 seconds]
vegai_ has joined #crystal-lang
vegai_ has quit [Ping timeout: 265 seconds]
leafybasil has joined #crystal-lang
leafybasil has quit [Client Quit]
<travis-ci> manastech/crystal#2561 (master - df46ace : Ary Borenszweig): The build passed.
strcmp1 has joined #crystal-lang
shama has joined #crystal-lang
waj_ has joined #crystal-lang
waj has quit [Ping timeout: 264 seconds]
waj_ is now known as waj
daneb has joined #crystal-lang
bcardiff has joined #crystal-lang
DeBot has quit [Quit: Crystal IRC]
DeBot has joined #crystal-lang
bcardiff1 has quit [Ping timeout: 248 seconds]
waj_ has joined #crystal-lang
waj has quit [Ping timeout: 244 seconds]
waj_ is now known as waj
luislavena has joined #crystal-lang
<luislavena> hello folks, wanted to confirm the behavior of Hash#to_a
<luislavena> seems that it returns an array of hashes, and not an array of pairs like Ruby?
asterite has joined #crystal-lang
<asterite> luislavena: {:foo, 10} is a tuple
<jhass> asterite: btw, you made a new stackoverflow account? :o
<ozra_> asterite: I was thinking about the new method. This is done twice as often as indexing - yet indexing has operator `id[ix]` instead of, say `id.get(ix)`/`id.set(ix)`. What I'm leaning at: Why not allow `()` "operator" for newing: `Type(initializer_args)`, and `Type(Int32)(initializer_args)`. For giving generics the double parens would be required - else init-args is assumed.?
lokulin has quit [Ping timeout: 264 seconds]
waj_ has joined #crystal-lang
<ozra_> a = Foo("Bar", 47)
<jhass> because then it'd look like Python
<ozra_> vs. a = Foo.new("Bar", 47) in 5676 places in the compiler alone. It obviously gets mindshare immediately, and it has presidence in many languages..
<ozra_> I don't care what it looks like. What is the _rational_ approach for a better language?
<jhass> okay, the rational is that .new is OOP
<jhass> while it doesn't quite make it into Crystal, in Ruby there are few keywords
waj has quit [Ping timeout: 256 seconds]
waj_ is now known as waj
<ozra_> If there's no ambiguity, "new" is just boilerplate. Whatever paradigm one glorifies.
<jhass> and those are mostly flow control or convenience wrappers around methods
<ozra_> Crystal don't use 12.add(32).mul(15) all over the place because it would be more OOP..
<jhass> in Ruby, class Foo; def bar; end; end; can be seen as mere syntax Sugar around Foo = Class.new do; define_method(:bar) do end; end;
<jhass> and as such 12 * 32 * 15 is mere syntax sugar for 12.*(32).*(15)
<luislavena> asterite: so a tuple conforms a type defined as Hash(Symbol, Symbol) ?
<ozra_> jhass: Exactly. And Type(foo) is just a `()` operator (like [] for arrays) for Type.new(foo) - dismissing the obvious boiler...
<jhass> ozra_: it looks like a method call to a Rubyist though, in fact in Ruby there's Array(...) and such, but implemented as a method with the same name, Kernel#Array. And slightly discouraged thus
<jhass> I don't know, it just feels odd to a Rubyist
<ozra_> jhass: With your arguments, array-indexing with `[]` should be thrown out in favour of above mentioned get/set? Since it's used half as much as .new...?
<jhass> no, it's not ambiguous
<ozra_> jhass: I can understand that. I've coded most languages under the sun - and I'm always interested in what can be better, more rational, and what seems appropriate given use in the language. Considering numbers in this case, it is obvious to me.
<jhass> foo[bar] is calling the [] method
<jhass> foo.bar(baz) is calling the bar method
<jhass> Foo(bar) is suddenly calling the new method
<jhass> Ruby has .() as sugar for .call, you don't see that much used either
<waj> luislavena: tuples has their own type: http://play.crystal-lang.org/#/r/5he
<ozra_> Ah, right, operators are just methods - so just call the '()' operator a method too - yes - so sugar for both call and new then. For Types it's obviously new, for methods it's obviously call.. :)
<jhass> meh, I guess it boils down to preference, would get -1 from me because of what I said, after all that's just my opinion though
<luislavena> waj: confused, I was expecting Hash#to_a to return an array of K,V pairs instead of an array of tuples made from K,V
<waj> Foo(Bar) would be ambiguous. It’s a generic type instance right now
<jhass> luislavena: why would you represent an "K,V pair" as Array instead of Tuple?
<ozra_> Yeah, definitely the same here. I will open an issue RFC anyway - since I see Crystal as a new language that can solve a lot of problems for me, and I'm not interested in any one particular language idioms - just progress and a better coding experience. So, it could be good with some more opinions - I do realize that many of the current crystal crowd seems very Ruby Religious, so to speak, so it might not even be considered. But
<ozra_> Thanks for discussing it.
<luislavena> jhass: was converting a code from Ruby where Hash#to_a is used to obtain keys + values combined in a flattened array.
<waj> luislavena: Crystal uses tuples for many cases where Ruby just returns fixed length arrays
<jhass> luislavena: I'm sure ruby would return tuples too, if it had them ;)
<luislavena> waj: what would you suggest to be the approach to obtain both keys and values combined?
<jhass> luislavena: what's wrong with .to_a again?
<jhass> or rather, what do you need them for?
<luislavena> jhass: expected [[k1, v1], [k2, v2]], got [{k1, v1}, {k2, v2}]
<luislavena> cannot flatten the results and apply uniqueness
daneb has quit [Remote host closed the connection]
lokulin has joined #crystal-lang
<jhass> mmh, I'd question Hash as a datastructure if you have to apply an operation to it, but just .flat_map it out
<jhass> oh wait, hash's still not Enumerable :/
daneb has joined #crystal-lang
vegai_ has joined #crystal-lang
<jhass> >> {foo: :bar, bar: :baz}.to_a.flat_map(&.to_a).uniq
<DeBot> jhass: # => [:foo, :bar, :baz] - http://carc.in/#/r/5hv
<jhass> the middle to_a bugs me, but oh well
<jhass> ah, can use .each I guess
<jhass> >> {foo: :bar, bar: :baz}.each.flat_map(&.to_a).uniq
<DeBot> jhass: # => [:foo, :bar, :baz] - http://carc.in/#/r/5hx
<asterite> ozra_: we actually thought about Foo() as an alternative to .new
<waj> >> {foo: 1, bar: 2}.map {|k,v| [k,v]}
<DeBot> waj: # => [[:foo, 1], [:bar, 2]] - http://carc.in/#/r/5hz
<asterite> Kotlin does it nice too, I think C# too
<waj> although I would try to do it in any other way
<luislavena> jhass: thank you, that is cleaner than the approach I took.
<waj> I wonder what’s your real problem :)
<jhass> yeah, the xy is strong in this one
<asterite> luislavena: Tuple: http://crystal-lang.org/api/index.html#http%3A//crystal-lang.org/api/Tuple.html
<luislavena> waj: need to obtain a list of all posible combinations given in a Hash (transitions) in uniques.
<ozra_> asterite: Nice - it just makes sense on so many levels. I'm writing up a "[RFC] ..." this moment.
<luislavena> asterite: yup, saw the docs, but was not sure why Hash#to_a was returning a Tuple instead of what Ruby did, all clear now.
<asterite> A minor problem with Foo() is that you have to explain it: "this ends up calling the new method". With Foo.new you don't need to explain anything, it's just a method call
<luislavena> asterite: waj and jhass provided examples, so all good :)
<waj> luislavena: ok, I just wanted to give you the best approach in crystal, not just “the ruby way” ;)
<waj> most of the time that means: do not create intermediate arrays
dtscode has quit [Quit: ZNC - 1.6.0 - http://znc.in]
<luislavena> waj: let me push to github the code I did and will appreciate your input.
<waj> sounds good!
daneb has quit [Remote host closed the connection]
<luislavena> waj: states is a combination of all the transitions defined for each event
<luislavena> so states should be [:pending, :confirmed, :ignored] based on all the transitions
<jhass> mmh, h.keys.concat(h.values).uniq is the least intermediate arrays variant I guess
<jhass> oh, actually h.keys & h.values
<waj> I was just trying to redefine the flat_map method
<waj> right now it has a restriction that requires the block to return an Array
<jhass> >> h = {foo: :bar, bar: :baz}; h.keys & h.values
<DeBot> jhass: # => [:bar] - http://carc.in/#/r/5ib
<waj> but it just need to be a Enumerable
<jhass> er |
<luislavena> jhass: but I have one for each event, the data is Hash(Symbol, Array(Hash(Symbol, Symbol)))
<jhass> >> h = {foo: :bar, bar: :baz}; h.keys | h.values
<DeBot> jhass: # => [:foo, :bar, :baz] - http://carc.in/#/r/5ic
<jhass> perhaps a set?
<jhass> do we have Set#add_all or something?
<luislavena> jhass: yeah, I think will change it for a set.
<jhass> Set and two .merges instead of + is probably as good as it gets
<asterite> jhass: about stackverflow, I had an account with a google account that I lost, so I had to start over
<jhass> meh
Ven_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
daneb has joined #crystal-lang
<asterite> My problem is that the old account doesn't exist anymore
<luislavena> jhass: thanks for the input, still trying to get familiarized with Crystal (again): https://github.com/luislavena/crystal-state_machine/commit/7507d4fd923e3381e0c206bde2026c435de94030
<luislavena> waj: any input will be appreciated on the code pushed to GitHub, really rusty on programming, specially crystal ;-)
<ozra_> asterite: Given it's almost as universally used as array indexing operators/methods in different languages, and it's constant recurrence, I'd say won't be hard explaining it :)
<jhass> asterite: nothing to loose, maybe you can convince them that the old one is you ;)
<asterite> I tried, but it's gone forever
<waj> Not rusty at all! and using a Set makes much more sense specially because it’s the one you’re finally saving. No intermediate structures needed.
<jhass> asterite: http://stackoverflow.com/users/20459/asterite references your blog, maybe you can set it up again and prove ownership?
<asterite> There's the thing that you invoke keys and values, which create intermediate arrays. Probably better to traverse the hash and add each key/value. But maybe do it if it becomes the bottleneck
<asterite> jhass: The problem is that was a hosted account, @esperanto.org.ar, which was free in one moment and I accidentally made it paid, there's no turning back
<jhass> luislavena: I'd even save the .to_a at the end, I think returning a Set makes total sense
<asterite> jhass: I already got used to the regular gmail account :-)
<asterite> But probably flatten_map is the way to go, once we remove that Array restriction
<jhass> asterite: I'm saying you may not even need the mail account if you can somehow convince them that you are you are the old account ;)
<asterite> Ah! In stackoverflow, I see
<asterite> I don't mind much about the karma points :)
<waj> just realized stackoverflow allow accounts with the same nick? wtf?
<jhass> sure it's a nice to have, but I mean it'd be 5 minutes to fill out the form, if the blog would still exist at least :P
centrx has left #crystal-lang ["End transmission"]
luislavena has quit [Remote host closed the connection]
waj has quit [Read error: Connection reset by peer]
waj has joined #crystal-lang
asterite has quit [Quit: Page closed]
vegai_ has quit [Ping timeout: 256 seconds]
<travis-ci> manastech/crystal#2563 (master - 0d9b7d2 : Ary Borenszweig): The build passed.
luislavena has joined #crystal-lang
waj_ has joined #crystal-lang
waj has quit [Ping timeout: 265 seconds]
waj_ is now known as waj
bcardiff1 has joined #crystal-lang
bcardiff has quit [Ping timeout: 244 seconds]
<luislavena> waj: noticed that temporary executables are created within `$pwd/.crystal` and contains there the full path to the script, including parent dirs
bcardiff1 has quit [Quit: Leaving.]
luislavena has quit [Remote host closed the connection]
luislavena has joined #crystal-lang
<crystal-gh> [crystal] waj pushed 1 new commit to master: http://git.io/vt8Z9
<crystal-gh> crystal/master 453d9f6 Juan Wajnerman: Avoid crashes on Array#sort when the comparison function is invalid (fixes #856)
bcardiff has joined #crystal-lang
<travis-ci> manastech/crystal#2564 (master - 453d9f6 : Juan Wajnerman): The build passed.
bcardiff has quit [Quit: Leaving.]
luislavena has quit []
daneb has quit [Remote host closed the connection]
<crystal-gh> [crystal] waj pushed 1 new commit to master: http://git.io/vt8XT
<crystal-gh> crystal/master 08f3259 Juan Wajnerman: No need to define a Fiber.rescheduler
waj_ has joined #crystal-lang
bcardiff has joined #crystal-lang
<travis-ci> manastech/crystal#2565 (master - 08f3259 : Juan Wajnerman): The build passed.
waj has quit [Ping timeout: 256 seconds]
waj_ is now known as waj
BlaXpirit has quit [Quit: Quit Konversation]
waj has quit [Quit: waj]
flaviu has quit [Ping timeout: 272 seconds]
flaviu has joined #crystal-lang
fowlduck_ has joined #crystal-lang
fowlduck has quit [Ping timeout: 246 seconds]
fowlduck_ has quit [Remote host closed the connection]
strcmp1 has quit [Quit: Leaving]
fowlduck has joined #crystal-lang
fowlduck has quit [Ping timeout: 248 seconds]