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>
>> 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]
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.
<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
<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
<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
<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
<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?
<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.
<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.
<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]
<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.