<FromGitter>
<drosehn> The few times I've used Object#send in ruby, it's to take an arbitrary method name which was determined at *runtime*, and call that method in some object. You can't really do that in crystal.
<FromGitter>
<jwoertink> :joy:
<FromGitter>
<Sija> one union of all types found in crystal src/, that would sth of compiler bug hunt 101
<FromGitter>
<jwoertink> compiler bug hunt sounds like a game for Atari 2600
<FromGitter>
<Sija> never had one, but could be one of these titles for programming nerd
<FromGitter>
<Sija> z
<FromGitter>
<jwoertink> :thumbsup:
<FromGitter>
<Sija> possibly killing insects all over the logicboard
<FromGitter>
<Sija> i think u could even mock it in sdl.cr ;)
<FromGitter>
<jwoertink> yeah!
<FromGitter>
<jwoertink> maybe I'll make that my demo game for my latest shard :D
<FromGitter>
<jwoertink> ok, so I'm not sure what I'm missing here....
<FromGitter>
<martinium> Const is checked at compile time
<FromGitter>
<jwoertink> ah, I see
<FromGitter>
<martinium> Immutable I think unchangeable from its creation
<FromGitter>
<martinium> But they are very similar
<FromGitter>
<martinium> They closed that request 11 months ago
<FromGitter>
<martinium> IMO immutability is a big deal especially for languages that have parallelism baked in like this one will prior to 1.0
<FromGitter>
<martinium> Swift is another lang that has both mutable and immutable variables and is quite fast just like this
<shelvacu>
Well a struct would be an immutable variable, right?
<FromGitter>
<martinium> The language Nim has all three. Mutable using var keyword, immutable using let keyword and compile time checked via const keyword
<FromGitter>
<martinium> Depends on how crystal uses and defines struct
<FromGitter>
<martinium> Struct to me is when you define your own data structure
<FromGitter>
<martinium> Like in C
<shelvacu>
I guess all Value objects
<FromGitter>
<martinium> They can still change so a struct wouldn't be immutable by default. I could be wrong
<shelvacu>
No wait, I don't know what I was thinking. Nevermind.
<FromGitter>
<drosehn> Hmm. Looks like crystal's `Time` methods work at the millisecond level, while ruby's works at the microsecond level.
akwiatkowski has quit [Ping timeout: 240 seconds]
<FromGitter>
<martinium> Hmm
<FromGitter>
<martinium> That has to be fixed then
<FromGitter>
<martinium> Probably Ruby's C implementation being badass as usual
<FromGitter>
<martinium> Ruby ends up performing much more slowly though due to not being compiled
<FromGitter>
<martinium> I wonder if they would ever just make a compiled ruby if it would causes a drastic speedup with minimal changes to the language
<FromGitter>
<drosehn> It's hard to get a major speedup without making some significant changes to the ruby language. Some of the ruby scripts that I write *really* take advantage of the fact that so many things are determined at runtime.
Guest93652 has quit [Quit: Guest93652]
<FromGitter>
<drosehn> I have been kind of surprised how much I take advantage of that when writing ruby scripts without really thinking about it.
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
bjz has joined #crystal-lang
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<bmcginty>
Sija: I've got something that's kind of modified and working... I'm probably commiting a code crime against types and who knows what else though.
<FromGitter>
<thbar> Hi there! I'm playing around with Crystal, and trying to pass a `Class` as a method parameter then store that in an array inside the method (not an instance, a `Class` really). Is that supported ?
<FromGitter>
<sdogruyol> @thbar those are some great insights :)
<FromGitter>
<sdogruyol> have you discovered method overloading yet <3 ?
<FromGitter>
<sdogruyol> it's awesome
<FromGitter>
<thbar> I think I'm right about to dive in, since I need some form of flexibility to allow passing both a block or a class type
<FromGitter>
<thbar> Will look into it
mgarciaisaia has joined #crystal-lang
balduin has quit [Ping timeout: 240 seconds]
sz0 has quit [Quit: Connection closed for inactivity]
<FromGitter>
<thbar> I'm trying to capture a block and store it as an instance variable, but I'm facing problems. First apparently since the block is not for immediate yielding but to be stored, I have to provide input and output types. But if I do so with e.g. `def transform(&block : Hash -> Hash)` then I get that `Hash` "cannot be used as a Proc argument type yet, use a more specific type". Is there a way to still capture a random block in a way or
<FromGitter>
<mverzilli> @martinium not that I know of. there's a quite interesting shard with immutable data structures: https://github.com/lucaong/immutable
<FromGitter>
<martinium> hilarious
<FromGitter>
<martinium> I was just asking about immutable variables yesterday
<FromGitter>
<martinium> that they should be added via a let keyword etc so crystal could adopt FP features that would be quite beneficial
<RX14>
i think that adding such features dilutes the language quite a bit
<RX14>
it feels like just "adding FP for FP's sake"
<FromGitter>
<martinium> why do you think it dilutes?
<RX14>
because it doesn't really fit with the rest of the language
<RX14>
crystal is OO and mutable
<FromGitter>
<martinium> The only reason I think immutable variables would be awesome is due to managing state more effectively
<FromGitter>
<martinium> Nim is Imperative and OO but supports mutable and immutable
<RX14>
mutability scales inside a method, but not inside a whole codebase
<RX14>
variables themselves being immutable is pointless if the objects are not immutable
<RX14>
and immutable objects can easilly be created using crystal
<FromGitter>
<martinium> well yes immutable variables objects etc
<FromGitter>
<martinium> via use of let keyword
<FromGitter>
<martinium> or whatever they choose to adopt
<RX14>
no, inventing "let" wouldn't magically make the underlyingf object immutable
<RX14>
immutability is a property of an object not a reference
<RX14>
creating the arbitrary "this variable cannot be assigned to" seems moot when your method fits on the screen
<FromGitter>
<martinium> I mean immutable the way Rust-lang does it
<RX14>
what does not fit on the screen is your entrie codebase
<FromGitter>
<martinium> via their let keyword
<RX14>
and your objects *are* passed around the entire codebase
<RX14>
making them immutable is the solution, not making variables immutable
<FromGitter>
<martinium> yeah I understand and kind of what I meant
<FromGitter>
<martinium> support making objects variables functions immutable
<RX14>
@martinium the correct way to write immutable objects is to just write immutable objects
<FromGitter>
<martinium> while still allowing for mutable versions
<RX14>
i don't feel syntax support is worthwhile
<RX14>
that sounds impossible to me
<RX14>
at least with crystal's level of introspection
<FromGitter>
<martinium> it may not even be necessary since the syntax is so clean already
<FromGitter>
<martinium> the compiler also helps so we will see if long term people can avoid huge bugs in big projects
<RX14>
in rust methods specify whether they can modify the object they're called on, right?
<RX14>
in crystal that's just not there so it's not possible to just "turn on and off" immutability
<FromGitter>
<martinium> yeah
<FromGitter>
<martinium> everything in rust is immutable by default
<FromGitter>
<martinium> you make them mutable by using the word mut
<RX14>
rust is very much safetey is key
<RX14>
which has a place
<FromGitter>
<martinium> yep
<RX14>
but I think crystal has a more balanced view
<FromGitter>
<martinium> Crystal is more dynamic and freeing
<FromGitter>
<martinium> so I can see the style differences
<FromGitter>
<martinium> @RX14 you work as a professional programmer aka your day job?
<FromGitter>
<zatherz> nice, thanks
<RX14>
@martinium no, i'm a student
<FromGitter>
<martinium> CS?
<RX14>
CS, maths and physics
<FromGitter>
<martinium> nice
soveran_ has quit [Remote host closed the connection]
mgarciaisaia has quit [Ping timeout: 276 seconds]
mgarciaisaia has joined #crystal-lang
soveran has joined #crystal-lang
bjz has joined #crystal-lang
<FromGitter>
<martinium> is there a way using the error handling to retry a section of your program until the expected input is entered?
<FromGitter>
<martinium> Would I have to use the exception handling?
<FromGitter>
<martinium> for instance if a user enters a string value instead of an integer value, instead of erroring and stopping the program I would want it to repeat the same prompt
<FromGitter>
<Sija> i meant, there’s a way to implement it as a regular method
<FromGitter>
<thbar> What is the correct syntax to set a default value "empty hash" to a method parameter? I tried `def initialize(klass : T, block : (Row -> Row) | Nil, options : {} of Symbol => String)` but I get the error `expecting token 'CONST', not '}'`. Thanks!
<RX14>
default value uses =
<RX14>
setting the type uses :
<RX14>
type restriction*
<FromGitter>
<thbar> Ahhh! Found it, right ; it's my ":" instead of "="
<FromGitter>
<thbar> Indeed
<RX14>
may I ask where options comes from?
<FromGitter>
<thbar> I'm playing around to write a Crystal prototype of my ETL library http://www.kiba-etl.org/, and typically the options are generic options to initialize components, provided by the developer.
<FromGitter>
<thbar> e.g. for a `CSVSource` which will yield CSV rows one by one, the options could be: `{filename: "the_file.csv"}`.
<RX14>
I'm just wondering if named parameters be more appropriate
<FromGitter>
<thbar> I have no idea at this point, but I will try out various approaches (tuple etc, named parameters etc)
<RX14>
if these fit the job, they're much more flexible than hashes or named tuples
<FromGitter>
<thbar> I have tried but did not manage to get that so far, maybe because I need arbitrary names for the keys etc. I will try again once I have a basic prototype working. Thanks!
<RX14>
you'd probably want **args for that, but that's something to think about once it works for sure!
<FromGitter>
<thbar> Hehe yes :-)
<FromGitter>
<thbar> Thanks for your input !
undying has joined #crystal-lang
undying has quit [Quit: Page closed]
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<FromGitter>
<thbar> I'm trying to use Hash with a union type for the values, in order to provide flexible configuration. As soon as I add more than 1 type to the union, though, I get this error https://gist.github.com/thbar/92c2deaa5422b6fccb98a1132c333882 . Is there a way to make this work?
<RX14>
@thbar the type of c will be String | Int32
<RX14>
so passing it to the constructor will fail because @filename needs to be a string
<RX14>
there's a few ways to fix it
<RX14>
you could use .as(String) on c
<RX14>
and it'll just raise
<RX14>
but a better way would be to used a namedtuple
<RX14>
or some other type which plays better with the type system
<FromGitter>
<thbar> I'm going to have other components like `SomeSource`, all with options named differently. I am under the impression that I can't use NamedTuple for that case, is that right?
<FromGitter>
<thbar> (options named differently = with various keys, which are component specific)
<FromGitter>
<thbar> I have an upper layer storing these hashes, then later instantiating each component (like `SomeSource`) by passing the options down there
<FromGitter>
<thbar> I'll try on a small test case with named tuples, but so far I have the impression that the keys are mixed between the components, as I assume maybe the names of the keys are shared etc. But well this is still new, so I'll try again later. Thanks!
soveran has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Changing host]
soveran has quit [Ping timeout: 260 seconds]
<FromGitter>
<andyfleming> Any idea why a crystal binary compiled in ubuntu wouldn’t run in a scratch/alpine docker container?
<RX14>
@andyfleming different libc
<RX14>
alpine uses musl libc
pawnbox has joined #crystal-lang
<FromGitter>
<andyfleming> Any idea on the leanest container that works for a crystal binary? I was able to make `debian:jessie-slim` work after installing `libssl1.0.0 libssl-dev` at about 119 MB
pawnbox has quit [Ping timeout: 240 seconds]
<FromGitter>
<jots_twitter> @thbar : kiba looks super interesting, hope to try it out in the next few days and would be interested in how your crystal port goes.
<FromGitter>
<andyfleming> And actually it looks like I may be able to exclude libssl-dev and get it down to 97.1 MB
<RX14>
@andyfleming crystal will work on alpine you just need an existing container
<RX14>
and build the binary in the aslpine container
<FromGitter>
<andyfleming> I was using `docker run -w /app -v $(pwd):/app crystallang/crystal crystal build src/service.cr --release -o service-release` for simplicity
<RX14>
but crystallang/crystal isn't alpine
<FromGitter>
<andyfleming> Yeah, I wasn’t sure about the compatibility side until you mentioned the libc difference
<FromGitter>
<andyfleming> That would be awesome if you updated your alpine-crystal docs :)
<RX14>
yeah hmm
<FromGitter>
<andyfleming> Would I be able to use that container to compile as well?
<RX14>
yep
<RX14>
you have to lol
<FromGitter>
<andyfleming> Awesome
<RX14>
i mean the containers were still 62MB
<FromGitter>
<andyfleming> I figured I still had to compile in alpine somewhere. Just wasn’t sure if the strategy is to use the same one or not.
<FromGitter>
<andyfleming> You are happy or unhappy with 62MB?
<RX14>
unhappy
<RX14>
alpine base is much smaller
<FromGitter>
<andyfleming> We should have a separate alpine-crystal-compiler and alpine-crystal
<FromGitter>
<andyfleming> Then we could get the size of alpine-crystal down, right?
<RX14>
maybe
<RX14>
probably not by much
<FromGitter>
<andyfleming> Forgive my ignorance, but is the crystal compiler a single binary? or does it have external dependnecies?