<|2701>
in ruby, it's possible to do: (1..100).to_a.combination(3).select{|a,b,c| (a*a)+(b*b)==(c*c)}, where a,b and c are binded to the 3 elements of each array from combination, but in crystal I get an overload error when trying to do a similar thing with combinations
<|2701>
would it be easy to make crystal bind block arguments in select calls to elements of the arrays passed to the block?
<crystal-gh>
[crystal] asterite pushed 1 new commit to master: https://git.io/vrcnJ
<crystal-gh>
crystal/master 8cec777 Ary Borenszweig: Fixed #2601: Global function named 'initialize' crashes the compiler
<icezimm>
any way of extend a module and create a class variable?
<icezimm>
emancu: uber builder is used to return classes dynamically
<emancu>
like a factory ?
<icezimm>
emancu: imagine you have a class that returns the Object Form, but in some cases you want to return SimpleObjectForm, sometimes you want the AdvancedObjectForm
<icezimm>
a factory usually instantiate the object
<icezimm>
builder just returns the call
<icezimm>
*class
pawnbox has joined #crystal-lang
<emancu>
ok.. and those classes are polymorphic ?
<icezimm>
depends on the purpose… the idea is just the block returns a class to be initialized later hehehe
<icezimm>
based on options hash
trapped has joined #crystal-lang
<icezimm>
but don't worry I think I'm too beginner on crystal to implement such a thing like this, I'm gonna start with simple classes until I get more used to, then I get back to Uber when makes sense hehehe
<icezimm>
thank you!
soveran has quit [Remote host closed the connection]
steenuil has joined #crystal-lang
<jhass>
note not all if not most ruby patterns translate well to Crystal
Raimondii has joined #crystal-lang
<icezimm>
jhass: yes… I'm realizing this hahahah
Raimondi has quit [Ping timeout: 265 seconds]
Raimondii is now known as Raimondi
elia has quit [Quit: Computer has gone to sleep.]
<icezimm>
I'm trying to store a proc in a instance variable like @block = block then in a later point just @block.call
<icezimm>
hahahahah with 1 character you solved it.. amazing, thank you jhass :)
brunto has quit [Ping timeout: 260 seconds]
<icezimm>
I need to better understand Generics, really new concept to me
<Rocky_>
hey folks, i recently discovered crystal and i've been trying to learn it, I use java most of the time and am wondering if there is something that functions like data (input/output) streams in crystal for tcp sockets
<icezimm>
emancu: thank you for all your patience and support :)
<icezimm>
Rocky_: I'm not used to Java, but you mean an event loop?
<icezimm>
that reads / writes from an IO stream (in this case tcp sockets)…
<Rocky_>
yeah
<icezimm>
I'm as new as you in crystal, but in my research I found something that may be useful to you
<jhass>
icezimm: what's the benefit over the evented IO provided by the standard library?
<icezimm>
no one hahaha it's just a pattern implemented
<icezimm>
I think what Rocky_ wants, is to know how you initialize a tcp client and pass a block so when something is ready to be read on buffer, process this block
<icezimm>
so you can open a tcp socket to receive something, bufferize and write on another socket… so you just stream without the need of write an IO
<jhass>
just use it inside a fiber and program like it's blocking
<jhass>
your other fibers will run while it's blocked on IO
<icezimm>
Rocky_: jhass example is much better (and simpler)…
<icezimm>
jhass: perfect!
<icezimm>
jhass: your example is exiting after 10 seconds
<jhass>
yeah, argless sleep would make it run forever
<jhass>
gotta keep the main fiber alive
<Rocky_>
im trying to work with a connection between a client and the server (which im trying to write) where the client is sending all of this information as abitrary bytes and im trying to read that information
<jhass>
else the process exits
<Rocky_>
so icezimm is pretty much on point with what im trying to figure out
<jhass>
you gotta have a wire protocol
<jhass>
no API can ever provide you an exact TCP packet like it was written by the sender
<icezimm>
jhass: I got it running endless, thank you for sleep argless tip :)
<icezimm>
Rocky_: I faced this problem when porting a nodejs application to ruby
<icezimm>
Rocky_: streams are sooo easy on node heheh
<icezimm>
on ruby I ended with eventmachine
<icezimm>
but as jhass said, on crystal there's native event support
<jhass>
Rocky_: what do you want to do while not reading data?
<Rocky_>
the packet im trying to work with right now has this structure [id: 0x00, field: varint, field: string, field: unsigned short, field: varint"]
<icezimm>
probably wait hahaha (the most useless wait time in mankind, wait for an IO :P )
<jsaak>
anyone used macruby or ruby-motion? it looks pretty close to crystal
<jhass>
don't both embed runtimes?
<jsaak>
i do not know what you mean
<jsaak>
it is a wrapper around ios stuff, and some ruby reimplemented i think
<jhass>
produce execuatables which basically implement a Ruby VM that then runs the code
<jsaak>
no, i think it is all compiled
<jsaak>
with llvm
<wmoxam>
MacRuby used JIT compilation
<wmoxam>
AFAICT it is closer to JRuby than Crystal
<wmoxam>
and Ruby Motion is based on MacRuby
mgarciaisaia has left #crystal-lang [#crystal-lang]
<wmoxam>
Although in Ruby Motion's FAQ they state that "RubyMotion implements a dialect of Ruby that conforms to those rules. RubyMotion apps are fully compiled, do not download or interpret code"
Raimondi has quit [Quit: The road to wisdom?—Well, it's plain and simple to express: Err and err and err again, but less and less and less. — Piet Hein]
Raimondi has joined #crystal-lang
sdogruyol has quit [Quit: Connection closed for inactivity]
srabuini has joined #crystal-lang
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 265 seconds]
Raimondii is now known as Raimondi
<crystal-gh>
[crystal] asterite pushed 3 new commits to master: https://git.io/vrWMA
<crystal-gh>
crystal/master 73dd85a Ary Borenszweig: Formatter: format special named tuple syntax in the type grammar
<crystal-gh>
crystal/master 31e5e37 Ary Borenszweig: SimpleHash: use named tuples for values
<crystal-gh>
crystal/master 249cf87 Ary Borenszweig: Compiler: use record instead of tuple for representing named arguments with types (less magic numbers)
willl has joined #crystal-lang
Ven has joined #crystal-lang
greengriminal has joined #crystal-lang
brunto has joined #crystal-lang
<icezimm>
is there any way to include a module on a class, and create a class variable there?
<icezimm>
I tried with macro included, but didn't work
brunto has quit [Read error: Connection reset by peer]
brunto has joined #crystal-lang
brunto has quit [Read error: Connection reset by peer]
<icezimm>
I tried storing a generic type on a hash, but compiler does not allow `can't use BlockHolder(T) as generic type argument yet, use a more specific type` hehehe
<crystal-gh>
[crystal] bcardiff pushed 1 new commit to master: https://git.io/vrWHX
<crystal-gh>
crystal/master 7efdf26 Brian J. Cardiff: [ci skip] fix CSV#build docs
Yxhuvud has quit [Remote host closed the connection]
<travis-ci>
crystal-lang/crystal#249cf87 (master - Compiler: use record instead of tuple for representing named arguments with types (less magic numbers)): The build was fixed. https://travis-ci.org/crystal-lang/crystal/builds/130928805
<jhass>
icezimm: class variable should've worked, show what you got?
<icezimm>
I've spent 2 days on make it badly "working", and you solved beautifully
<jhass>
I said Ruby idioms don't port to well, especially around "DSLs" :P
<icezimm>
jhass: https://carc.in/#/r/ypb does it worth to open an issue for this? started happening after added the @klass, crystal has 271 issues, do wanna flood the team with dummy issue (specially because I don't know what to write on description) hehehe
<icezimm>
jhass: hahahah yes
fryguy9 has joined #crystal-lang
<icezimm>
jhass: I'm learning this _the hard way™_ :D
<jhass>
icezimm: too bad, taking out spec makes it disappear, gonna be a lot of work to reduce
<jokke>
RX14: merged!
<jokke>
RX14: thx
<RX14>
thanks
<jhass>
icezimm: anyway open a bug anyway, just title it "stack overflow in the compiler" or so
<icezimm>
jhass: being honest, this solution sucks, it's not the _crystal way_, so I'm gonna use yours, just reported because it's an error on compiler… but if it's an edge case and doesn't worth to track it down, forget it hehehe
<icezimm>
ok
<jhass>
nah such things should basically never happen
<jhass>
at worst the compiler should say "not able to compile your code for now, sorry!"