e_dub has joined #crystal-lang
waj has joined #crystal-lang
asterite has joined #crystal-lang
e_dub has joined #crystal-lang
CraigBuchek has joined #crystal-lang
e_dub has joined #crystal-lang
kostya has joined #crystal-lang
e_dub has joined #crystal-lang
e_dub has joined #crystal-lang
waj has joined #crystal-lang
<asterite> @CraigBuchek will there be videos or slides of your talk next monday?
<CraigBuchek> Actually, there might be video.
<CraigBuchek> Not sure if there will be slides, or just a Markdown doc that I'll work from. I'll try to make some slides though.
<CraigBuchek> I'll see if we can get video posted.
e_dub has joined #crystal-lang
Excurio has joined #crystal-lang
e_dub has joined #crystal-lang
CraigBuchek has joined #crystal-lang
<asterite> @CraigBuchek (sorry for the delay) cool, anything will be fine… I'm just curious because it will be the first talk ever about Crystal :-P
<CraigBuchek> We're going to try to do a Google Hangouts On Air session, so people can watch it remotely, or watch it later.
<asterite> Awesome!! We'll definitely be there if you do that
<CraigBuchek> asterite: That's a lot of pressure on me. ;)
<asterite> @CraigBuchek nah, relax… we wouldn't know how to structure a presentation ourselves so anything you'll say in the talk will be more than ok
<asterite> The pressure is on us if you get a compiler crash during the presentation :-D
<CraigBuchek> I'll have to work on the presentation quite a bit this weekend. I'll likely have some questions for you guys. I can ask a couple now, since you're here.
<CraigBuchek> 1. Is there any introspection? Can I see the methods for a class or object — including "primitive" methods fir Bool and String?
<CraigBuchek> 2. Can I define functions and enums outside of a lib?
<CraigBuchek> 3. Can you explain the syntax for block type signatures? That is, I don't understand this: def map_with_index(&block : T, int32 -> U) or this: def select(&block : T ->)
<CraigBuchek> I've created a Google Hangouts On Air event for the presentation: https://plus.google.com/u/0/b/110181072134940314339/events/cvvb6lealje999oqbg86g3q50dk
dbouzolin has joined #crystal-lang
<asterite> 1. Not right now. We don't know if that'll be possible in the future
<asterite> 2. You can define "fun" outside of "lib", at top level. This is useful for providing a function to be used by a C program.
<asterite> For example, check gc/boehm.cr, there's "fun __crystal_malloc"
<asterite> in the code generation we depend on that function being available in the binary, and that's the way we can have a known name
<asterite> 3. &block : T, Int32 -> U means that the block will receive two arguments, one with type T and the other with type Int32
<asterite> the compiler checks this for you and gives an error if that's not the case
<asterite> Then you have "-> U" telling the compiler "and give the name U to the type returned by the block"
<asterite> The easiest method to understand this is map: def map(&block : T -> U)
<asterite> In Crystal, when you create an instance of a generic type (like Array) you need to tell it the type
<asterite> For example, Array(Int32), Hash(Int32, String), etc.
<CraigBuchek> OK. And (&block: T ->) would have Nil return type?
<CraigBuchek> Right.
<asterite> So for map you need to create an array whose type is the type of the block, and that's how you get the type (U, but the compiler needs to know the type yielded to the block to figure that out)
<asterite> In the case of T -> it means "I will yield T to the block but I don't care what the block's type is"
<asterite> In fact, in that case you can omit that information and it will still work
<CraigBuchek> Cool. Thanks.
<CraigBuchek> I think those were my biggest questions.
<asterite> The only thing is, if you do indicate that, the compiler will work faster because it can cache the call instantiation based on those types, but that's it
<asterite> (so it's an abstraction leak in a way, we need to improve that)
<CraigBuchek> Although I could still use an answer for 1b. How can I find out more about what methods are available on String? At the very least, where do I look in the compiler code?
<asterite> Ah, I see what you mean
<asterite> All methods, except primitives, are right there in the source code
<asterite> All String's methods are the ones in string.cr
<CraigBuchek> Yeah. Found those. Looking for the primitives.
<asterite> Hmmm...
<asterite> There's an idea of including those in the source code, similar to how Rubinius marks its primitives
<asterite> Something like: struct Int32; def +(other : Int32); primitive; end; end
<asterite> that will make all methods apear in the source code
<asterite> Another thing we can do is to write a tool that shows you all the methods, something similar to RDoc
<asterite> Hmm… but that will still have that problem
<asterite> For now, you can look at the source code, there's a file called primitives.cr
<asterite> It's very short, about 150 lines of code
<asterite> There are really very few primitives in Crystal :)
<CraigBuchek> Oh, that's nice. Cool.
<asterite> These are for arithmetic operations, pointers, type casts (to_i, to_u8, ord, etc.), object_id, class… and that's it :)
waj has joined #crystal-lang