<willlll>
Hey, just came across this project earlier in the week. It looks really cool. Drive by suggestion, I’d love to see keyword arguments. I’d also love to see a lightweight syntax for blocks like smalltalk’s [ ] so you can easily pass more than one block to a method
<a5i>
willlll: You can always submit an issue to the repo so more people can hear you
<willlll>
that makes sense, I’ll do that thanks
<a5i>
anytime
<jhass>
willlll: keyword arguments are sort of there
<jhass>
you can pass regular arguments as keywords
<willlll>
I was going to send a message to the mailing list, but my google admin (me) hasn’t apparnetly set up joining google groups and I’m on a plane, so I just popped in here. :)
<a5i>
does Crystal have explicit return types?
<willlll>
that’s cool jhass. Coming from ruby, the requried keyword args in 2.1 has been surprisingly awesome
<jhass>
willlll: yeah, though I kinda like the idea of it being a caller only thing
<DeBot>
jhass: Syntax error in eval:3: unexpected token: ,
<jhass>
worth a try :P
<a5i>
like
<a5i>
fn foo() -> Bool
waj has joined #crystal-lang
havenwood has quit []
<a5i>
jhass ?
<jhass>
apparently not
<jhass>
I'm not sure why you're asking for all that type restrictions, after all the whole damn point of Crystal is to have to specify as few as possible
<a5i>
it's all a matter of curiosity
<jhass>
read through spec/, you'll get a decent idea about the current state
<jhass>
it's how I figure out stuff
<jhass>
then you don't need to come up with all kinds of things all the time and then find somebody with an answer
<a5i>
mk
waj1 has joined #crystal-lang
waj has quit [Read error: Connection reset by peer]
DerisiveLogic has quit [Read error: Connection reset by peer]
DerisiveLogic has joined #crystal-lang
ponga has joined #crystal-lang
ponga has quit [Client Quit]
willlll has quit [Quit: willlll]
waterlink1 has joined #crystal-lang
waterlink has quit [Ping timeout: 256 seconds]
waterlink1 has quit [Ping timeout: 248 seconds]
ponga has joined #crystal-lang
DerisiveLogic has quit [Remote host closed the connection]
DerisiveLogic has joined #crystal-lang
DerisiveLogic has quit [Remote host closed the connection]
havenwood has joined #crystal-lang
shama has quit [Remote host closed the connection]
strcmp1 has joined #crystal-lang
shama has joined #crystal-lang
shama has quit [Quit: (╯°□°)╯︵ɐɯɐɥs]
genericpenguin has joined #crystal-lang
<genericpenguin>
hello people. I was wondering if anyone was working on any GUI toolkit libs for Crystal? Probably a stretch at this point but just asking in case anyone is.
bcardiff has quit [Ping timeout: 248 seconds]
JBat has joined #crystal-lang
bcardiff has joined #crystal-lang
<strcmp1>
genericpenguin, Hey, I'm not, but I've seen a few graphics libraries being wrapped already, there is jhass/crystal-gobject. manastech/crocoa, and at least one other i can't remember the URL for :) those links are relative to github.com btw.
a5i has quit [Quit: Connection closed for inactivity]
<asterite>
jhass: Very evil! I didn't know %context would work in those position
<jhass>
hehe
<jhass>
I just tried and it did :D
<jhass>
how do you like my infecting included hook? :D
<asterite>
You mean line 110?
<asterite>
I just lol'd at it
ponga has quit [Remote host closed the connection]
<jhass>
yeah
<asterite>
What does that do??
<asterite>
Well, it's good you are squeezing the language to its maximum :)
<jhass>
define self.run on all modules the module is included to and all modules those modules are included into and all.... and so on
<asterite>
Why do you need the recursive inclusion?
<asterite>
I also see you used previous_def
<asterite>
But calling super in a module would also work, I was thinking... right?
<jhass>
I use super too :D
<asterite>
(when I'll fix the bug, which I was doing some minutes ago)
<asterite>
How you are using it if it's not working?
<jhass>
so, the before/after hooks by redefining a method on the context module, appending contents to it with previous_def
<waterlink>
jhass: I like that thingy. It totally adds before, after and let - the things I have been missing
<jhass>
and the initial definitions call super to include the hooks of the parent context module
<waterlink>
asterite: how about cleaning up this code a bit and including it in crystal?
<jhass>
yeah, totally needs cleanup
<jhass>
I had the idea and it's an experiment to see whether it would work out
<asterite>
If you can rewrite the specs in crystal's repo to use this new code, I think chances are very high that we'll switch to it
havenwood has quit [Remote host closed the connection]
<waterlink>
We will need some huge test suite for that probably )
<asterite>
Well, there are 5638 specs in crystal's repo ;)
<waterlink>
The thing is that, it is probably compatible with Spec
<jhass>
so the main features of that concept are: global namespace pollution down to 2 constants, hooks and instance variable sharing with the hooks and examples
<jhass>
which is what I attempted in the past with my other approach too
<jhass>
oh and example execution randomization
<asterite>
What made it work this time?
<asterite>
Maybe the %context thing?
<jhass>
that and being able to put each example into its own class with it
<jhass>
which was the idea that sparked the approach, putting each example into its own class
<waterlink>
I'm interested how it will impact performance of crystal test suite
<waterlink>
it will create 5.5K+ classes
ponga has joined #crystal-lang
<jhass>
yeah
<jhass>
plus a couple hundred modules
<waterlink>
yeah
<strcmp1>
haha
<strcmp1>
definitely evil :P
<jhass>
asterite: if #563 is an easy fix that'll ease cleanup :)
<waterlink>
jhass: do you want to try to replace Spec with this code and see how it goes ?
<jhass>
I still have to see if I can allot time to it tbh
<waterlink>
Because I can try it now, I have some time
<jhass>
oh, feel free
<waterlink>
ok
<jhass>
I need to make some food anyway and won't be useful until that's done ;D
<jhass>
there's probably a way to get rid of the both Container classes, I always forget how and didn't bother so far
<jhass>
the other issue is (and I think it's caused by the containers) that redefine_main has to sit below the examples, at lest when they're in the same, I didn't investigate yet if it works if broken into multiple files
<jhass>
*in the same file
<asterite>
I'm guessing this will take a lot of time to compile, but you can try :)
<asterite>
#563 should be very easy to fix, yes
<BlaXpirit>
oh i ran into this
<BlaXpirit>
in the end, i made my own different aliases for each value
<waterlink>
is there some sort of exit trap in crystal?
Ven has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<waterlink>
so you can trap exit and run spec
<asterite>
There's at_exit { ... }
<waterlink>
yeah, my linux box barely can compile test suite.. I doubt I will be able to compile it with this update at all. Lets see
<jhass>
asterite: mmh, could we allow class/module reopening with an alias?
<jhass>
alias B = A; module B; def foo; previous_def; more_code; end; end;
Ven has joined #crystal-lang
<asterite>
jhass: yes, an (non-recursive) alias should just work in any place where the aliased type would
<BlaXpirit>
jhass, yes, that's a great idea
<BlaXpirit>
and while we're at it
<BlaXpirit>
you should be able to add methods only to an ALIAS of a C lib struct
<BlaXpirit>
although that may be even more difficult
<BlaXpirit>
but yeah, this is my top feature request right now - being able to add things to lib types
<asterite>
I have a secret (just found it today): try doing struct LibFoo::Bar; add_methods_here; end
<asterite>
That is, outside the lib declaration
<asterite>
It works for structs and unions :-)
<BlaXpirit>
wuuuuuuuuuuuuut
<BlaXpirit>
that's cool
<BlaXpirit>
does it work on an alias?
<asterite>
But I still have to reply to that issue (just that there's so much activity lately, I can't catch up!)
<asterite>
Not sure it works on an alias because of what jhass said
<BlaXpirit>
right, right
<BlaXpirit>
well that's amazing
<asterite>
At one point c structs didn't inherit Struct, but after I made that change I also accidentally allowed adding methods to structs/unions like that :-P
ponga has quit [Remote host closed the connection]
<asterite>
(but I'll fix it soon, it should be easy)
<jhass>
so if Alias::CONSTANT, module/class Alias::Foo and ideally module/class Alias works I think it's possible to get down to 2-3n modules/classes where n is the number of describe blocks
<jhass>
oh, something else I noticed, but I guess asterite knows already :P
<jhass>
>> module A; end; A.class
<DeBot>
jhass: Class
<asterite>
Should be Module?
<jhass>
yeah
<asterite>
I guess we can do that. Do you need it now?
<jhass>
there's no need, it's just some inconsistency
<jhass>
since it's all faked :D
<asterite>
Hehehe, exactly :-)
<asterite>
but if you want to add a method to all classes but not all modules, you can't do that right now... I guess
<asterite>
>> class Class; def foo; 1; end; end; Int32.foo
<DeBot>
asterite: 1
<jhass>
>> class A; end; A.is_a? Module
<DeBot>
jhass: Error in line 3: undefined constant Module
<jhass>
>> class A; end; A.is_a? Class
<DeBot>
jhass: true
<jhass>
at least! ;D
ponga has joined #crystal-lang
<waterlink>
jhass: asterite: what does %context and %example in macro do?
<asterite>
So they don't conflict with outside identifiers... I think that makes "hygenic macros" into the language, but not sure :-)
* jhass
sometimes wonders if asterite actually does any paid work :P
<asterite>
Well, enjoy ;-)
<asterite>
jhass: I might have said this before, but thanks for being here and answering everyone's questions! You even point them to how primitives are implemented! :-)
* asterite
wonders the same about jhass
<jhass>
I'm still student ;)
<jhass>
and I found this (helping others solve their problems) the most effective way to learn something, it's how I learned the ins and outs of Ruby ;)
<asterite>
Amazing :-)
<asterite>
How old are you?
<jhass>
23
bjmllr has joined #crystal-lang
<asterite>
What are you studying?
Ven has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<asterite>
(I guess computer science :-P)
<waterlink>
So I'm getting this error: no type inherits Spec2::ContextContainer(T)
<jhass>
asterite: yup
<jhass>
waterlink: yeah, that's the one I got when moving redefine_main above the examples :/
<waterlink>
heh, but I'm trying to use at_exit at all..
<travis-ci>
manastech/crystal#2249 (master - 0470050 : Ary Borenszweig): The build was broken.
<jhass>
so it's instantiated in the context of a subclass if called on a subclass
<jhass>
which gives you compile time access to the child class from the parent class
<jhass>
if that makes any sense
<jhass>
it's basically a macro to define a specific method on call on the type it's called on
<BlaXpirit>
jhass, does {{ }} always just insert a string?
<jhass>
the macro language is sort of like a templating language
<BlaXpirit>
i know that it is sort of like
<BlaXpirit>
what i'm asking is if it's exactly like
<waterlink>
looks like I got it
<jhass>
the normal code is inserted at the place you call the macro
<BlaXpirit>
does the result of expression inside {{ }} always act as a piece of text and nothing more?
<jhass>
{{}} calls into the compile time context and is replaced by the return value
<jhass>
{% %} calls into the available control flow
<BlaXpirit>
i know
<jhass>
and yeah, it's pretty much just text replacement
<BlaXpirit>
ok
<asterite>
Yes, it just inserts a text
<waterlink>
So I call `(@@run_lambda || -> {})` inside of `Spec2.run` and then in the end of `describe` macro replace `@@run_lambda` with proper call
<waterlink>
lets see if it can handle multiple root contexts..
<BlaXpirit>
so let me tell you this. sorry that i'm talking about a different language, but... in Nim such templates can be implemented without any modifications to the compiler
<asterite>
There's just one special case and that's when you do {{ yield }}, that inserts the text but preserves the original block location, so the error messages are more useful… but that's it
<crystal-gh>
crystal/master 93e5d32 Ary Borenszweig: Fixed: broken link attributes logic when aliases are involved
<jhass>
<3, thanks!
<asterite>
BlaXpirit: it's ok to talk about other languages, like Nim. We usually like to learn about many other languages and get inspiration from them, but of course we have our way to do things
<asterite>
We try to keep things simple. I guess in Nim you can have arbitrary compile-time code execution?
<BlaXpirit>
not completely arbitrary, but yes
<asterite>
Those staticRead and writeFile happen at compile time?
<BlaXpirit>
yes
<BlaXpirit>
the executable does nothing :D
<asterite>
Well, you can do the same with run in macros
<asterite>
Well, not sure if the same, but it's close
<jhass>
I want example randomization at least though
<waterlink>
then I'm fine with having spec2 as external library )
<waterlink>
It is just when you use RSpec for quite some time, you can't go back to the world of simple unit tests..
<asterite>
:)
<asterite>
But, of course, that's my personal opinion and it's inevitable that other things will appear (and I like that!). There's already an initial minitest too
<waterlink>
Compiling all_spec.cr doesn't seem to get more then ~900MB of memory now
<waterlink>
but it is still not finished
<asterite>
You mean, with spec2?
<waterlink>
yes
<asterite>
I think 900MB is what it consumes with spec too
<waterlink>
It is already 915 :) so we'll see )
<asterite>
Oh, I thought spec2 is not finished, not the run
<waterlink>
I have tried already on couple of complicated spec files (like array_spec, markdown_spec, c_enum_spec) and it worked
<waterlink>
ok, I got compilation error :)
<waterlink>
because it is impossible to create classes inside blocks )
<waterlink>
jhass: so you put all of them as an unique-named methods to one class..
<jhass>
yep and then have lambdas to invoke them
<jhass>
and make a new instance of that class for each call
<jhass>
to have a clean context
BlaXpirit_ has quit [Client Quit]
<waterlink>
but you do have as much classes as you have contexts
<jhass>
yes
BlaXpirit_ has joined #crystal-lang
<waterlink>
might be actually not bad from performance point
BlaXpirit has quit [Ping timeout: 250 seconds]
<jhass>
one module and one class per context
<waterlink>
>> s = %( hello world "
<DeBot>
waterlink: Syntax error in eval:7: unterminated string literal
<BlaXpirit_>
can't take pointerof(self) :(
<BlaXpirit_>
that is gonna complicate things a ton
<BlaXpirit_>
should it be allowed maybe?
<asterite>
You can assign it to a variable and take a pointer to that
<asterite>
(there was a reason why pointerof(self) is not allowed, can't remember it though)
asterite has quit [Quit: Leaving.]
<BlaXpirit_>
asterite, but if that copy is modified?
<BlaXpirit_>
can't write self = copy, can i
<jhass>
waterlink: meh, might not be worth it after all, I hacked up array_spec to run under it and pasted it a couple of times to get a 18kloc file, still bumps up to close to a GB RES and
<jhass>
Parse: 00:00:00.3079000
<jhass>
Type inference: 00:00:07.8077410
<jhass>
Codegen (crystal): 00:00:03.0791330
<jhass>
Codegen (bc+obj): 00:00:32.9864620
<jhass>
Codegen (clang): 00:00:01.6888090
<waterlink>
it is definitely worth it as a library for people to use
<waterlink>
because lets, befores and afters will be very useful to them. And I doubt they will have such a big test suites as crystal itself )
<jhass>
let's see, I pasted it another couple of times to get to ~33kloc, since spec/ is 35kloc
<jhass>
interestingly doing the same for stdlib spec (pasting array_spec into a file to get to a ~33kloc one) crashes the compiler
<jhass>
mh, this time it doesn't
<jhass>
Type inference: 00:00:05.8161470
<jhass>
Codegen (crystal): 00:00:03.2885120
<jhass>
Codegen (bc+obj): 00:00:13.4779560
<jhass>
Codegen (clang): 00:00:00.2275330
<jhass>
for the old one
<jhass>
anyway, if you want to shape that into a proper library you're welcome to, I can't really justify dedicating too much time to it atm, but if you add me to the repo I might push some boilerplate every once in a while ;)
Ven has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
DerisiveLogic has joined #crystal-lang
zipR4ND has joined #crystal-lang
<zipR4ND>
hi all, i would like to write a ssl client + server application that checks certificates and stuff, therefore i need a more complete binding of the openssl headers. i've been playing with crystal_lib_gen and managed to compile something, but it segfaults. has anyone already created better openssl bindings for crystal?
<asterite>
BlaXpirit_: I saw in your readme that you talk about enums and that you can or them... I don't think you know about @[Flags] (not documented :-()
<BlaXpirit_>
asterite, i read about something
<BlaXpirit_>
that it enables ORing
<BlaXpirit_>
but that it also works anyway for now
<BlaXpirit_>
no immediate advantage from it or am i missing something
<jhass>
asterite: sorta, expensive migration running on my box :P
<BlaXpirit_>
asterite, I added ": UInt32" anyway to those combinable enums
<BlaXpirit_>
so yeah, trivially added @[Flags] as well
<BlaXpirit_>
i was in the process of moving constructors inside structs as well, but it doesn't work well
<asterite>
Yeah, constructors are like hijacked (special) right now for those things
<asterite>
But maybe we can change things, I hope. We all want to simplify things :-)
<BlaXpirit_>
have to stick with SF.video_mode(...) for now but would like to see SF::VideoMode.new(...) working without gotchas
<BlaXpirit_>
i replied in the topic
<BlaXpirit_>
you probably saw
<asterite>
Yes, I saw it. I have some ideas, I'll write them down later. I'd also like to brainstorm it with waj
JBat has quit [Quit: Computer has gone to sleep.]
<asterite>
By the way, I just tried the record sound sample and I was amazed it worked :)
DerisiveLogic has quit [Ping timeout: 256 seconds]
<BlaXpirit_>
why wouldn't it
<BlaXpirit_>
but strangely saving to file and playing back is deafening
<BlaXpirit_>
playing in VLC, anyway
<asterite>
I don't know, it's nice to have a complete game lib working in crystal :)
<BlaXpirit_>
sure is
BlaXpirit_ has quit [Quit: Quit Konversation]
BlaXpirit has joined #crystal-lang
<jhass>
asterite: mh, I need a quick refresher, any tip how I can quickly bind gethostname(3)
<jhass>
?
<jhass>
that API is kinda f*cked up
<asterite>
what do you mean?
<jhass>
it wants you to pass an allocated buffer, you tell it how big that buffer is with the second param, it writes a 0 terminated string into the buffer (or as much as it can)
<jhass>
it doesn't tell you how was actually written
<jhass>
and the maximum hostname length is system configuration dependent apparently
<asterite>
So ugly
<asterite>
So how much you'll allocate?
<jhass>
SO says POSIX says it has to be 255, so that's good enough
<jhass>
but I'm not sure about what String API I should use
<jhass>
do we have strlen mapped?
<asterite>
Well, the most efficient way would be to do String.new(256) { |buffer| LibC.gethostname(buffer, 256); len = LibC.strlen(...) }
genericpenguin has quit [Ping timeout: 246 seconds]
<asterite>
Is String#succ used in real life?
<jhass>
I just had a usecase for it
<jhass>
Github switched its API so you can no longer fetch an auth token
<jhass>
instead creating one you supply now an fingerprint
<jhass>
if you try to create one with an existing fingerprint your get a 422 back
<jhass>
so I put that it into loop with fingerprint.succ basically
<jhass>
(I use the hostname as fingerprint and append -1, -2, -3 until it works)
<BlaXpirit>
>> "a9".succ
<DeBot>
BlaXpirit: Error in line 3: undefined method 'succ' for String
<jhass>
ssvb: forgive my ignorance, but I wonder, what does C++ do on v32 = one + v64? implicit cast to int32?
zipR4ND has joined #crystal-lang
<BlaXpirit>
>> {Int32, String}.class
<DeBot>
BlaXpirit: Sorry, that took too long.
<BlaXpirit>
>> {Int32, String}.class
<DeBot>
BlaXpirit: Sorry, that took too long.
<ssvb>
jhass: for the addition operation, it does not matter if we cast the int64 operand to int32 before addition or truncate the result to int64
<ssvb>
jhass: with the other operations it may be probably different, but I haven't looked too deep into this yet
<jhass>
just thought you might know offhand what C++ actually does in that case
<ssvb>
Crystal can probably just mimic whatever is done by Clang for C++
<ssvb>
it is unlikely to have any performance implications because C++ is supposed to be fast anyway :-)
<jhass>
my question is about the behavior, you're saying the result of one + v64 is a 64bit integer, what happens if you assing that to a variable that's typed as a 32bit integer?
<ssvb>
hmm, this is an interesting question
<asterite>
I just tried it, it "works"
<ssvb>
for C++, the end result is a 32bit integer because the variable type is explicitly declared as int32
<asterite>
int x = 0; long y = 123456789123; x += y; ... print x and you get -1097262461
<ssvb>
for Crystal, it might be not very nice to get an union of Int32 and Int64
<asterite>
I think what ssvb proposes makes sense. For example if you add an Int32 with a BigInt the result is always a BigInt
Excureo has quit [Remote host closed the connection]
<asterite>
I think it's no problem. Well, the problem is that if you have a variable of type Int32, say x, and you do x += y with y being Int64, x will become a union, but the result will be (if there's no overflow) correct. You will get a compile error if you try to put that into an array of Int32
<asterite>
but you can always go and change x to be Int64 and you'll get the same behaviour plus a bit of performance
<asterite>
I can't remember why right now a op b preserves a's type, maybe we didn't think about it enough
<asterite>
(i think it's that way to avoid accidental unions)
Excureo has joined #crystal-lang
<ssvb>
ok, I see
<asterite>
There's also Rust's alternative, which basically disallows operations between distinct types
<asterite>
But i think I prefer ease of coding and accidental unions which can always be profiled and fixed
asterite has quit [Quit: Page closed]
BlaXpirit has quit [Quit: Quit Konversation]
shama has quit [Quit: (╯°□°)╯︵ɐɯɐɥs]
a5i has joined #crystal-lang
cool_coder_forfo has quit [Ping timeout: 272 seconds]