<jsn->
i suppose declarations are available immediately after parsing, init blocks are called at the "execution time" of the first require, except when they are needed earlier :)
<Papierkorb>
jsn-: Speaking in C terms, a Crystal constant is basically this: `static int Q() { static int v = q(); return v; }`. Not even sure if yours is an actual bug or not
<jsn->
it's a bug since it does something unexpected and hard to document; specifically, it means that having init blocks for side effects is okay, except when they initialize an unused constant (but not, for example, an unused var)
<Papierkorb>
It could be argued that the initialization of a constant should not have visible side-effects
<jsn->
it sure can; doesn't change the fact that it's misleading. reading "Q = q()" in someone else's code should give you an idea about what's going on, without remembering that side effects in constant initialization are bad (and in e.g. unused vars it still works)
greengriminal has joined #crystal-lang
DTZUZO has joined #crystal-lang
qard has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 264 seconds]
greengriminal has quit [Quit: This computer has gone to sleep]
<FromGitter>
<stevensonmt> @asterite You are correct. Thanks. Thanks also @sdogruyol for raising the idea.
greengriminal has joined #crystal-lang
woodruffw has quit [Quit: And then he took off.]
faustinoaq has joined #crystal-lang
vivus has quit [Quit: Leaving]
woodruffw has joined #crystal-lang
woodruffw has joined #crystal-lang
woodruffw has quit [Changing host]
jnyw has quit [Quit: WeeChat 2.0.1]
faustinoaq has quit [Quit: IRC client terminated!]
faustinoaq has joined #crystal-lang
LastWhisper____ has joined #crystal-lang
qard has joined #crystal-lang
qard has quit [Ping timeout: 260 seconds]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 248 seconds]
alex`` has joined #crystal-lang
hightower4 has joined #crystal-lang
illy_ has joined #crystal-lang
illy_ is now known as illy
illy is now known as _illy_
greengriminal has quit [Quit: This computer has gone to sleep]
_illy_ has quit [Quit: Leaving]
faustinoaq has quit [Quit: IRC client terminated!]
alex`` has quit [Ping timeout: 276 seconds]
<FromGitter>
<stevensonmt> I have the following hash structure: ⏎ `myHash = { key => [ {int => int}, int, int, string ] }` ⏎ and I want to access the hash with `myHash.fetch(key).at(0)` and then map that result with ⏎ ⏎ ```{ |k,v| array1[v] + array2[k] }``` ... [https://gitter.im/crystal-lang/crystal?at=5a7d338de217167e2c6009f8]
rohitpaulk has joined #crystal-lang
<FromGitter>
<bew> Don't use a Hash for this
<FromGitter>
<bew> Sorry, maybe the Hash is ok, the Array looks misused though
<FromGitter>
<stevensonmt> use a named tuple instead?
<FromGitter>
<bew> What is the structure of the value of the hash?
<FromGitter>
<stevensonmt> the hash nested in the array? its { int => int}
<FromGitter>
<bew> No the array itself, why is there a hash inside it, then just numbers?
<FromGitter>
<bew> Nulber & string sry
<FromGitter>
<bew> Do you realize that Array's elements type is `Hash(Int32, Int32) | Int32 | String`?
<FromGitter>
<stevensonmt> Oh, sorry. The array consists of first a hash that ultimately matches keys as indexes to another array and values as indexes to a third array.
<FromGitter>
<stevensonmt> Yes, that is what I intended.
<FromGitter>
<stevensonmt> To clarify this was initially in a ruby project.
<FromGitter>
<bew> when you do `your_array.at(0)`, the type of the result is also `Hash(Int32, Int32) | Int32 | String`, the compiler can't know that the first element is the hash and the other are `Int32 | String`
<FromGitter>
<stevensonmt> I've got a list of medications that form the key to the outside hash. The nested `Hash(Int32, Int32)` provides a way to reference the mechanism and strength of that mechanism for each med. Each med can have multiple mechanisms but always at least one.
<FromGitter>
<stevensonmt> I see.
<FromGitter>
<bew> and what are the Int32 or String for in the rest of the array?
<FromGitter>
<stevensonmt> as opposed to storing it as a constant in this way?
<paleorange_h>
also my issue is still not solved
<FromGitter>
<bew> @stevensonmt hmm if it's constant and known at compile-time then maybe it's ok
<FromGitter>
<stevensonmt> Yeah, it's just for a subset of medications that aren't going to be expanded (or at least not very often).
danielpclark has joined #crystal-lang
hightower4 has quit [Ping timeout: 256 seconds]
sz0 has joined #crystal-lang
LastWhisper____ has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<paleorange_h>
:(
alex`` has joined #crystal-lang
<FromGitter>
<alehander42> @paleorange_h honestly, if you want to write your own language, writing a simple parser library (e.g. using parser combinators) might be a good beginning
<paleorange_h>
yet i need a lexer/parser generator for that
<FromGitter>
<alehander42> that's what I am saying, you can write this lexer/parser manually (or write a parser generator yourself), it's not very hard
<FromGitter>
<malyutinegor> Is there some zeroconf lib or another thing for finding services in network?
<FromGitter>
<malyutinegor> Thanks.
<FromGitter>
<sdogruyol> I'm not sure what zeroncof is..
<FromGitter>
<sdogruyol> zeroconf*
bijan_ has quit [Quit: My iMac has gone to sleep. ZZZzzz…]
bijan_ has joined #crystal-lang
bijan_ has quit [Client Quit]
bijan_ has joined #crystal-lang
<FromGitter>
<malyutinegor> I'm too 😄
bijan_ has quit [Quit: My iMac has gone to sleep. ZZZzzz…]
bijan_ has joined #crystal-lang
greengriminal has quit [Quit: This computer has gone to sleep]
snsei has quit [Remote host closed the connection]
greengriminal has joined #crystal-lang
bijan_ is now known as bijan_awaaaay
rohitpaulk has quit [Remote host closed the connection]
bijan_awaaaay has quit [Quit: System has gone to sleep. ZZZzzz…]
maattdd has quit [Ping timeout: 256 seconds]
snsei has joined #crystal-lang
snsei has quit [Ping timeout: 252 seconds]
rohitpaulk has joined #crystal-lang
return0e has joined #crystal-lang
return0e_ has quit [Read error: No route to host]
<FromGitter>
<stevensonmt> Having trouble getting kemal to render a partial view. In `src/views/main.ecr` I have the line `<%= render "./views/partial.ecr" %>` but I keep getting a `file not found` error.
rohitpaulk has quit [Ping timeout: 248 seconds]
<FromGitter>
<stevensonmt> Should the path instead be `./partial.ecr`?
LastWhisper____ has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<FromGitter>
<sdogruyol> it should be `src/views/partial.ecr`
<FromGitter>
<eliasjpr> Heads up, ⏎ ⏎ The Amber Framework team has assume maintenance responsibilities for the Micrate crystal shard. As we want to support the crystal community we will maintain Micrate as a complete separate shard. We will monitor and address issues in order of community importance, Welcome people to contribute as well. ⏎ ⏎ @juanedi as the author of the shard we will listen closely and take good
<FromGitter>
<stevensonmt> @sdogruyol I think @malyutinegor is talking about zero configuration network service discovery. Basically plug and play for any device connecting to a network. Something like this go pkg https://github.com/grandcat/zeroconf. I don't think there is a similar package in crystal.
<FromGitter>
<sdogruyol> thank you @stevensonmt
<FromGitter>
<stevensonmt> @eliasjpr the readme has two sections with instructions for adding `micrate` to dependencies, but in the first instance it is `github: amberframework/micrate` and in the second it is `github: juanedi/micrate`
<FromGitter>
<eliasjpr> Working on it. Thanks :)
<FromGitter>
<stevensonmt> thanks @sdogruyol. I probably have some other bug then b/c I think I tried that. Will try again when I get home.
Ven`` has joined #crystal-lang
maattdd has joined #crystal-lang
faustinoaq has joined #crystal-lang
alex`` has quit [Quit: WeeChat 2.0.1]
hightower4 has quit [Ping timeout: 276 seconds]
sz0 has quit [Quit: Connection closed for inactivity]
faustinoaq has quit [Ping timeout: 248 seconds]
hightower4 has joined #crystal-lang
maattdd has quit [Ping timeout: 240 seconds]
<FromGitter>
<xfbs> Hey guys, just wondering but is there a layout engine in crystal?
<FromGitter>
<straight-shoota> what do you mean with layout engine?
<FromGitter>
<xfbs> I don't really know what I mean haha. You know how in jekyll, or for example in rails, you can define layouts (views) in like a DSL, something like that? I don't need it to be turing complete, just looking what's out there, so I don't end up implementing something that already exists :p
<hightower4>
xfbs: HTML-based views?
<crystal-gh>
[crystal] straight-shoota opened pull request #5697: Add JSON::Serializable and YAML::Serializable (master...jm/feature/serializable) https://git.io/vAIFr
greengriminal has quit [Quit: This computer has gone to sleep]
duane has quit [Ping timeout: 268 seconds]
<crystal-gh>
[crystal] straight-shoota opened pull request #5699: Fix YAML::Core parse float with leading 0 or . (master...jm/fix/5698) https://git.io/vAL8q
moei has quit [Quit: Leaving...]
<FromGitter>
<xfbs> Oh well, I mean like, just the feature that you can use regexes in `when xx` expressions wasn't immediately clear, I think that's a big seller!
<FromGitter>
<xfbs> Also another question: when I have `a: String | Nil`, and I want to call `.to_i` on the `String`, how can I do this?
<Papierkorb>
xfbs, what should the result be if it's nil?
<FromGitter>
<xfbs> Still `nil`. Like "call .to_i if !obj.nil?, do nothing otherwise"
<Papierkorb>
Object#try, combine with the &. shorthand notation
<FromGitter>
<xfbs> Ahh, I knew there was something. Gotcha!
cremes has quit [Quit: cremes]
<FromGitter>
<jwoertink> Is there a way with specs where I could run something when the entire spec suite is done?