RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.24.1 | Fund Crystal's development: http://is.gd/X7PRtI | GH: https://github.com/crystal-lang/crystal | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/ | Gitter: https://gitter.im/crystal-lang/crystal
<arthur> I'm not sure if the above is expected behaviour or not, but I doubt it is.
<arthur> It's a weird issue i'm having with passing a tuple as an argument without wrapping the method call arguments in parentheses
<FromGitter> <bew> Yes this is known and documented
<FromGitter> <bew> The `{}` are recognized to start a block
<FromGitter> <bew> More precisely the `{`
<FromGitter> <bew> So to send a tuple to a method as first param you must use parenthesis
<arthur> I see. Thanks!
arthur has quit [Quit: Page closed]
qard has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
rohitpaulk has joined #crystal-lang
<watzon> I really don't understand why this is happening `instance variable '@options' of Tweeter::REST::Request must be Hash(String, JSON::Type), not Hash(String, Array(JSON::Type) | Bool | Float64 | Hash(String, JSON::Type) | Int32 | Int64 | String | Nil)`
<watzon> The hash in question is of type `String => JSON::Type`
<watzon> I tried creating my own version that includes Int32, but I still get the same error
<FromGitter> <bew> what are you doing with the instance var to get this error?
<FromGitter> <bew> which version of Cr are you using?
<watzon> Trying to set it using a hash of `String => JSON::Type`. Version 0.24.1
<watzon> Here's an example of it happening https://play.crystal-lang.org/#/r/3mie
<watzon> Is that expected behavior?
<FromGitter> <bew> yes: https://play.crystal-lang.org/#/r/3mig A `Hash(String, String)` is not a `Hash(String, JSON::Type)` !
<FromGitter> <bew> now, I think there was some discussion about this, not sure where we are about it now
<watzon> Then how do I make it work? Shouldn't that Hash just be checked to see if it conforms to the constraints?
<FromGitter> <bew> you'd still need to convert it to store it
<watzon> How can I convert it? Casting it with `.as` doesn't work
<watzon> This is the only thing I've been able to make work, and it's obviously not ideal https://play.crystal-lang.org/#/r/3min
<FromGitter> <bew> I thought #4385 was merged, it would have been easy to convert
<DeBot> https://github.com/crystal-lang/crystal/pull/4385 (Add Hash#transform_keys and Hash#transform_values)
<watzon> Well that works I guess. I'll just add it to my `core_ext`
<FromGitter> <bew> yeah and then you would just need `@options = options.transform_values &.as(JSON::Type)` or sth like that
<watzon> Yeah not super elegant, but it'll work
<FromGitter> <bew> Can I ask you why you need to store a JSON::Type ?
rohitpaulk has quit [Ping timeout: 248 seconds]
<watzon> Generic options. The value could be a string, int32, float64, or in some cases another hash.
qard has joined #crystal-lang
hightower2 has joined #crystal-lang
hightower has quit [Ping timeout: 256 seconds]
hightower2 has quit [Ping timeout: 248 seconds]
hightower2 has joined #crystal-lang
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 248 seconds]
early has quit [Quit: Leaving]
early has joined #crystal-lang
radagast_04 has joined #crystal-lang
qard has quit [Quit: qard]
qard has joined #crystal-lang
<FromGitter> <aisrael> What’s the idiomatic way to do dynamic, class-level polymorphism? E.g. I have ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5a8fba0fc3c5f8b90df3fd28]
<FromGitter> <aisrael> It works, but it just really feels… weird, and brittle
<FromGitter> <aisrael> Without that, I’m afraid I’d have to resort to the “Java-esque” `Factory(Base)` technique and `HANDLERS = {} of String => Factory(Base)`
<FromGitter> <bew> there is no class-level polymorphism, only instance-level (I don't have enough knowledge to tell you exactly why though)
<FromGitter> <bew> why do you need that?
<FromGitter> <aisrael> Use case: call different class-level methods (`.load_from_file`) depending on filename extension. I want to be able to, in the future, have the handlers add themselves to the `Base`. E.g., in my `YamlLoader` I have a call `Base.handlers[“yml”] = self.class.as(Base.class)`
<FromGitter> <aisrael> I suppose I could just use blocks/procs. `Base.add_handler(“yml”) do # …`
<FromGitter> <bew> iirc the why was that there was no point in having it, polymorphism on classes is a bad thing (or sth like that)
<FromGitter> <bew> yes that's a better idea to me (the proc based)
<FromGitter> <aisrael> Yeah I kinda understand the sentiment. I mean, we just got so used to in in Ruby
<FromGitter> <aisrael> If this was Go or Java, it’d all be some `ConcreteLoaderImplementationFactory`
alex`` has joined #crystal-lang
<FromGitter> <bew> ahahah yeah maybe, never used Ruby (really) so I can't tell
<FromGitter> <aisrael> Because *everything* is dynamic method dispatch in Ruby, it won’t matter if you call `Class.do_something` or `MyClass.do_something` or `reference_to_a_class = Foo; reference_to_a_class.do_something`
<FromGitter> <bew> oh yes I see, yeah it's too dynamic in some ways
<FromGitter> <aisrael> Then again, you also won’t know if it’ll all blow up until run-time
qard has quit [Quit: qard]
thi_ has quit [*.net *.split]
olbat__ has quit [*.net *.split]
desdeux[m] has quit [*.net *.split]
crse[m] has quit [*.net *.split]
logen[m] has quit [*.net *.split]
frojnd has quit [*.net *.split]
swav has quit [*.net *.split]
alex`` has quit [*.net *.split]
aemadrid has quit [*.net *.split]
cptaffe has quit [*.net *.split]
<FromGitter> <bew> Is there a way to add a method to a bunch of enums without having to write it multiple times? Calling a macro doesn't work: https://carc.in/#/r/3mjh
gewo has quit [Ping timeout: 255 seconds]
gewo has joined #crystal-lang
<FromGitter> <ezrast> @aisrael Can you get away with modules instead of classes? https://carc.in/#/r/3mji
cptaffe has joined #crystal-lang
aemadrid has joined #crystal-lang
alex`` has joined #crystal-lang
frojnd has joined #crystal-lang
swav has joined #crystal-lang
crse[m] has joined #crystal-lang
logen[m] has joined #crystal-lang
desdeux[m] has joined #crystal-lang
olbat__ has joined #crystal-lang
thi_ has joined #crystal-lang
desdeux[m] has quit [Ping timeout: 240 seconds]
crse[m] has quit [Ping timeout: 240 seconds]
logen[m] has quit [Ping timeout: 240 seconds]
byteflame has quit [Ping timeout: 248 seconds]
cptaffe has quit [Ping timeout: 255 seconds]
galstar[m] has quit [Ping timeout: 255 seconds]
kp666[m] has quit [Ping timeout: 255 seconds]
olbat[m] has quit [Ping timeout: 255 seconds]
thunker[m] has quit [Ping timeout: 252 seconds]
watzon has quit [Ping timeout: 252 seconds]
braidn[m] has quit [Ping timeout: 260 seconds]
fifr[m] has quit [Ping timeout: 256 seconds]
Renich has quit [Ping timeout: 256 seconds]
Ven`` has joined #crystal-lang
return0e_ has quit []
return0e has joined #crystal-lang
Ven`` has quit [*.net *.split]
thi_ has quit [*.net *.split]
olbat__ has quit [*.net *.split]
swav has quit [*.net *.split]
frojnd has quit [*.net *.split]
alex`` has quit [*.net *.split]
aemadrid has quit [*.net *.split]
flaviodesousa has joined #crystal-lang
Ven`` has joined #crystal-lang
alex`` has joined #crystal-lang
aemadrid has joined #crystal-lang
thi_ has joined #crystal-lang
olbat has joined #crystal-lang
olbat has joined #crystal-lang
frojnd has joined #crystal-lang
swav has joined #crystal-lang
watzon has joined #crystal-lang
<watzon> I'm trying to figure it out, but the differences between Crystal and ruby make it difficult
<watzon> Anyone good with Ruby and want to figure out how to accomplish this `flat_pmap` method in Crystal? https://github.com/sferik/twitter/blob/master/lib/twitter/utils.rb
olbat[m] has joined #crystal-lang
<watzon> Basically the idea is to wrap `Enumerable#each_slice` so that it can be mapped and have the results put into an array. As it is `each_slice` will run the block for each slice, but this would allow you to actually put the result of that block into an array
Ven` has joined #crystal-lang
Ven`` has quit [Read error: Connection reset by peer]
galstar[m] has joined #crystal-lang
braidn[m] has joined #crystal-lang
fifr[m] has joined #crystal-lang
byteflame has joined #crystal-lang
logen[m] has joined #crystal-lang
thunker[m] has joined #crystal-lang
Renich has joined #crystal-lang
cptaffe has joined #crystal-lang
kp666[m] has joined #crystal-lang
crse[m] has joined #crystal-lang
desdeux[m] has joined #crystal-lang
<FromGitter> <plainas> Is there a website that hosts shards api docs?
<FromGitter> <plainas> If not, is there a way to quickly get the on my computer?
ua has quit [Ping timeout: 256 seconds]
ua has joined #crystal-lang
bijan_ has joined #crystal-lang
bijan_ has quit [Client Quit]
bijan__ has joined #crystal-lang
bijan__ has quit [Client Quit]
rohitpaulk has joined #crystal-lang
PMunch has joined #crystal-lang
PMunch has left #crystal-lang ["Leaving"]
<FromGitter> <anicholson> `crystal tool expand` isn't working the way I expect. I expect to be able to pass it a file and have all definitions expanded, but when I do that I get the usage info. What have I missed?
Ven` has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<FromGitter> <j8r> i there a better to reset a variable, excepting `var = typeof(var)`?
<FromGitter> <anicholson> @j8r why do you want to?
<FromGitter> <anicholson> @j8r you can make the var nil, if you want: ⏎ ⏎ `var = nil`
<FromGitter> <j8r> I've an `addresses` array, and in each loop I need to reset the variable
<FromGitter> <anicholson> @j8r could you post your snippet? :)
<FromGitter> <j8r> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5a90022f6fba1a703a8ea093]
<FromGitter> <j8r> i haven't put all the code, all the parts concerned
Papierkorb has joined #crystal-lang
<FromGitter> <anicholson> @j8r if you declare `addresses` & `directives` inside your loop, they'll reset themselves
<FromGitter> <anicholson> @j8r if that's not possible/preferable: ⏎ ⏎ ```addresses.clear``` [https://gitter.im/crystal-lang/crystal?at=5a900301888332ee3ac060e1]
Papierkorb has left #crystal-lang ["Konversation terminated!"]
<FromGitter> <plainas> so guys, I guess this is not specific to crystal (same question aplies to ruby), but can anyone post a snippet on how I make block returns from one that doesn't?
<FromGitter> <aisrael> ☝🏽Can you clarify?
<livcd> yeah i doo not understand the question.
<livcd> You can return proc
<FromGitter> <plainas> for example... this snippet from crystagiri...
<FromGitter> <plainas> ``````
<FromGitter> <plainas> doesn't return... for example, this won't work: ⏎ ⏎ `````` [https://gitter.im/crystal-lang/crystal?at=5a900642c3c5f8b90df5bf1b]
<FromGitter> <plainas> array_of_h2 will be empty because the block just executes code.
<FromGitter> <anicholson> @plainas it sounds like you're trying to do something like `map`?
<FromGitter> <anicholson> Could you create an empty Array and push things into it from inside that block?
<FromGitter> <plainas> Yes, my question is: do I have to do that. Is there no crystalesque (rubyesque) way to do it?
rohitpaulk has quit [Ping timeout: 260 seconds]
Ven`` has joined #crystal-lang
rohitpaulk has joined #crystal-lang
<FromGitter> <aisrael> If `#where_tag` only `yield`s or `.call`s the given block and doesn’t return what the block returns, I don’t think there’s any way to make it do so. What if `#where_tag` returns `self` (the `doc`, in this case)—which is a common pattern in fluent syntax DSLs?
radagast_04 has quit [Ping timeout: 240 seconds]
<RX14> @plainas simply use `break tag.content` in the block and you should get the return value
<RX14> actually no thats not what you're asking
<FromGitter> <plainas> it can get multiple values
<RX14> @plainas that's a feature for crystalagiri not crystal
<RX14> you need to open an issue
<RX14> for now you'll have to make an array before and use array << tag.content in the block
<RX14> but crystalgiri should probably have a map_tag("h2") or similar
<FromGitter> <plainas> the question aplies to each block that doesn't return
<RX14> it's up to the library author what to do with the return value of a block
<FromGitter> <plainas> I opened an issue for just that. but the question was not to raise an issue, but to ask if there war a shorthand to creating an array and push to it
<RX14> when you do `doc.where_tag("h2") { tag.content }`, `tag.content` is the return value of `yield`. If the library never assigns the value of `yield` then it just gets discarded
<RX14> @plainas no, there's no shorthand
<RX14> people typically define map functions which create this shorthand
<RX14> you can create your own shorthand
<RX14> so there's no need for it in the language
<RX14> for example you could define your own `def map_tag(doc, tag, &block)`
<jokke> instance variable '@params' of RPCRequest must be Array(JSON::Type), not Array(Array(String) | String)
<jokke> this annoyes the crap out of me
<jokke> bing
<jokke> ups
rohitpaulk has quit [Ping timeout: 240 seconds]
<RX14> jokke, is it really that hard to define the array as an array(json::type) in the first place?
<FromGitter> <vpereira> hi, talking about documentation. How much a method should be documented? Are you accepting pull request for methods documentation?
<RX14> of course
<RX14> more documentation is very much appreciated
<RX14> you can look at previously documented methods for how we typically write documentation
<FromGitter> <vpereira> RX14 can you show me a method which is "well documented"?
<FromGitter> <vpereira> specially design decisions took in the code and so
<jokke> RX14: what do you mean?
<RX14> @vpereira most of `Array` https://crystal-lang.org/api/master/Array.html is well documented
<RX14> there are some methods missing docs but most of the ones that are documented are documented well
<FromGitter> <vpereira> hm, i see but inline documentation isnt allowed/welcome, right?
<FromGitter> <vpereira> @RX14 i.e https://github.com/crystal-lang/crystal/blob/797a2a62ea5bbe8576f19c62f152b1e1fe799cea/src/ini.cr#L22 in the parse method has lot things going on here
<FromGitter> <vpereira> including comments support ";,#" and so one
<RX14> well inline comments are fine in moderation
<RX14> but I wouldn't put much more than 3-4 comments in that method body
<FromGitter> <vpereira> if somebody wants to know or control the comment char, you have to read the code
<FromGitter> <vpereira> yes, not more than 3-4
<FromGitter> <vpereira> the methods should be self explanatory
<RX14> i'd put a line before the each_char block which said "Calculate the offset to start parsing from"
<RX14> and probably a line before the delete_if
<RX14> and thats the only two comments i'd make actually
<RX14> changing the comment chars is a PR i'd personally be fine with though
<RX14> just replace the `when` with a `Set`
<RX14> or tuple
<FromGitter> <vpereira> yes, thats what I was thing to do
<FromGitter> <vpereira> yup
<RX14> that's not comments though
<RX14> if you slip in comments with a code change
<RX14> you're far more likely to get them in
<FromGitter> <vpereira> i will submit a PR. thank you
<RX14> np
<RX14> i'd make sure to lay out your usecase for different comment chars though
<RX14> i've never seen an ini with different comments than # or ;
<RX14> jokke: I mean that usually you can avoid that arrive in the first place
<RX14> Error*
<FromGitter> <j8r> Ideally we should stick with the standard. If the comment isn't ";" or even "#", that's not INI
<RX14> There is no ini standard
<FromGitter> <vpereira> the "standard" was just ";" BTW
<FromGitter> <vpereira> maybe you dont want to add a new one, but remove one of both. I.e if in your ini file actually "#" isnt a comment but something else.
<FromGitter> <vpereira> the standard was the MS-DOS documentation, http://www.mdgx.com/msdos.htm
<FromGitter> <plainas> how do I call a method called []? on an instance?
<RX14> @plainas reciever[arg1, arg2]?
<RX14> so for arrays that's be
<RX14> array[1]?
<FromGitter> <plainas> thank you
<FromGitter> <plainas> on that topic... how do I handle these algebraic datatypes? I am getting errors like: undefined method starts_with? (compile-time type is (String | Nil))
<RX14> it really depends on the context
<RX14> there's no silver bullet
<RX14> if you have a String|Nil then it's your decision on what to do if you get a nil
<RX14> does a nil mean the input was wrong?
<RX14> is the nil theoretically impossible?
<FromGitter> <plainas> But how do I separate both cases? ⏎ is there a case consctruct? instanceof?
<RX14> you can use case, if, unless, anything
<RX14> it's slow typing
<RX14> flow typing*
<RX14> you can just do something like
<RX14> `return nil unless foo`
<RX14> and if `foo` is nil, your method will early-return nil
<RX14> you can replace the `return nil` with a `raise` of an error
<RX14> or just use `if foo` to do nothing if `foo` is nil
<RX14> or if it's actually /impossible/ for the variable to be nil (and the compiler is wrong) you can use `not_nil!`
<RX14> and not_nil! is just a shortcut method which raises if `self` is nil, or returns `self` if it's not
<RX14> so it just raises on nil and you use the return value
<RX14> but it's not really a good idea to use not_nil! often
<RX14> because it's not very robust error handling and the error message is generic
<RX14> @plainas if you show me code I can show you what I would do
<FromGitter> <plainas> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5a90227d35dd17022ee40b58]
<FromGitter> <plainas> I guess I can do with an extra if... how do I skip to the end of the block?
<RX14> so the question here is "what happens if the "href" doesn't exist"?
<RX14> so what do you want to do
<RX14> skip it?
<RX14> raise an error?
<FromGitter> <plainas> skip
<RX14> if (href = tag.node["href"]?) && href.starts_with? "/scripts/"
<RX14> puts href
<RX14> end
<FromGitter> <plainas> so I would assign tag.node["href"] to a variable and check for nulls before I proceed i guess
<RX14> simple :)
<watzon> Is there anyway to get raw headers from OAuth? Say to use with a library like https://github.com/icyleaf/halite
rohitpaulk has joined #crystal-lang
<FromGitter> <plainas> basic question here, bear with me, how to I declare a string without assigning?
duane has joined #crystal-lang
sz0 has joined #crystal-lang
philfine has joined #crystal-lang
<philfine> Hi everyone
<philfine> I wonder how to get libraries using shard
<philfine> Is it like gems in ruby ?
<FromGitter> <plainas> shards install
<philfine> Whay about to search ?
<philfine> What about to search ?
<philfine> :)
<FromGitter> <plainas> from what I gather there is no index? as you need to define the git url for the time being afaik
<philfine> Ok
<philfine> Thanks too bad
<philfine> What are the recommended replacements for libs like sinatra and datamapper
<FromGitter> <aisrael> For Sinatra, at least, have a look at Kemal
<FromGitter> <c17r> Mstrom2018#
<FromGitter> <c17r> *sigh*
duane has quit [Ping timeout: 240 seconds]
<FromGitter> <aisrael> For the shards index, well, unless with use ElasticSearch (Java, yuck) or Bleve (Go, not so bad but then why learn Crystal if you’re happy with Go?)—then first things first is a full text search library in Crystal
philfine has quit [Quit: Page closed]
<FromGitter> <philfine> Thanks
<FromGitter> <plainas> so the regex documentation is confusing me ``` myvar = /foo/.match "afoobar"``` gives me syntax error on the first /
<FromGitter> <aisrael> Am willing to lend a hand (wrote one ages ago in C++)
<FromGitter> <plainas> @aisrael a simple package index could easily do it without a fulltext index, but there are many implementations around. both mysql and postgres ship with one
moei has joined #crystal-lang
Ven`` has quit [Ping timeout: 240 seconds]
flaviodesousa has quit [Quit: KVIrc 4.2.0 Equilibrium http://www.kvirc.net/]
<FromGitter> <philfine> This is not going very will for crystal ... first useful thing get a mesage of a bug in compiler :D
Ven`` has joined #crystal-lang
<FromGitter> <philfine> Could not write to cache since I had no permissionss there
<FromGitter> <philfine> What about a serial connection library, anything ?
<FromGitter> <aisrael> @plainas A “simple” package index would work, yes, but most people expect full text search now *and* at the scale we’re talking about I would trust built-in FTS queries of Postgres or MySQL
ua has quit [Ping timeout: 248 seconds]
qard has joined #crystal-lang
ua has joined #crystal-lang
duane has joined #crystal-lang
alex`` has quit [Quit: WeeChat 2.0.1]
rohitpaulk has quit [Ping timeout: 248 seconds]
Ven`` has quit [Read error: No route to host]
Ven`` has joined #crystal-lang
<RX14> @plainas I think that syntax error is a bug
<RX14> I mean actually it works for me: https://carc.in/#/r/3mn9
<RX14> @aisrael there is a simple package index based off scraping github
Ven`` has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
yaewa has joined #crystal-lang
alex`` has joined #crystal-lang
moei has quit [Ping timeout: 248 seconds]
Ven`` has joined #crystal-lang
maattdd_ has joined #crystal-lang
maattdd_ has quit [Ping timeout: 268 seconds]
Ven`` has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
ikanobori has quit [Remote host closed the connection]
return0e_ has joined #crystal-lang
return0e has quit [Read error: No route to host]
dragonkh has joined #crystal-lang
<FromGitter> <marksiemers> I'm having issues reaching the crystal docs, api, and carc.in right now - anyone else? ⏎ The homepage is working just fine.
sz0 has quit [Quit: Connection closed for inactivity]
dyreshark has quit [Ping timeout: 256 seconds]
kosmonaut has quit [Ping timeout: 268 seconds]
maattdd_ has joined #crystal-lang
Liothen has quit [Ping timeout: 276 seconds]
maattdd_ has quit [Ping timeout: 260 seconds]
<FromGitter> <fridgerator> they are working for me
bazaar_ has joined #crystal-lang
olbat__ has joined #crystal-lang
olbat has quit [*.net *.split]
bazaar has quit [*.net *.split]
<lvmbdv> is /compiler/crystal/syntax/lexer.cr actually hand-written, no code generation like flex, yacc?
rohitpaulk has joined #crystal-lang
Liothen has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 240 seconds]
devil_tux has joined #crystal-lang
Liothen has quit [Changing host]
Liothen has joined #crystal-lang
<FromGitter> <bew> yes, handwritten
<FromGitter> <alexanderadam> Does anybody here knows whether any of the http clients support persistent sessions (for example like `net-http-persistent` in ruby had done it)? ⏎ Or how I could achieve this? ⏎ It's basically a pool of clients that sends automatically `keep-alive`'s, or did I misunderstand this?
<FromGitter> <alexanderadam> Ah, the example "reusing a connection" in https://crystal-lang.org/api/0.24.1/HTTP/Client.html should be the solution here, right?
protomikex has joined #crystal-lang
* protomikex
protomikex has quit [Remote host closed the connection]
<dragonkh> evening
<dragonkh> is it possible to call a block from inside another block? I'm trying to do this: def myMap(&block) ; array1.map{|value| block.call } ; end - but it no work
<dragonkh> in fact: def myMap(&block) ; block.call ; end - does not work - it seems you can't call a block like that
rohitpaulk has joined #crystal-lang
<FromGitter> <ezrast> @dragonkh Are you sure you're not leaving out some context? https://carc.in/#/r/3mo0
<dragonkh> ezrast - I'm trying to make this work: https://carc.in/#/r/3mo5
<dragonkh> I want the block passed into foo - to be applied to the map of myArray
<dragonkh> I don't know why it says foo was not expecting a block ?
<dragonkh> I guess what I want to do is not possible - I will have to write my own Iterator instead I guess
<FromGitter> <ezrast> You have to specify the type signature of the captured block - see https://crystal-lang.org/docs/syntax_and_semantics/capturing_blocks.html
kosmonaut has joined #crystal-lang
kosmonaut has quit [Client Quit]
<dragonkh> oh I see - hmm complicated
kosmonaut has joined #crystal-lang
<FromGitter> <bew> @dragonkh https://carc.in/#/r/3mo8
<FromGitter> <bew> if you capture the block, you need to specify its type in the method signature
<dragonkh> bew - ah very cool :) thanks
duane has quit [Ping timeout: 240 seconds]
<dragonkh> is there a way I can find the type of something and then use it - e.g. myString = "apple" ; theType = typeof(myString) ; p x.unsafe_as(theType)
<FromGitter> <bew> Well this already work
<FromGitter> <bew> But your unsafe_as is suspicious
<FromGitter> <bew> What are you doing?
<dragonkh> for some reason the compiler thinks its a string - hold on I paste code
<FromGitter> <bew> Ah yes no you can't save the result of typeof and use it in a `as`, you need to use `typeof` in the `as` (I don't usually use those tricks so not sure)
<dragonkh> actually my code works in the paster but not when its embedded in my module - https://carc.in/#/r/3moo
<dragonkh> hmm strange
<dragonkh> in my module - I have to have v.unsafe_as(klass) or it fails
<dragonkh> oh I figured it out - there was some pollution
Papierkorb has joined #crystal-lang
<dragonkh> hmm actually no - still not working as expected
<FromGitter> <bew> You usually never need unsafe_as, unless you're doing low level stuff
<FromGitter> <r00ster91> so theres `STDIN.read_timeout`. But it looks like this is just working on Input/Output operations. Not on things like http thingys. I have a situation right now that when internet is not enabled or if theres some other reason where the json request cannot be made that for some reason that it then just does nothing. I would need to reenable internet again so that it makes the request. ⏎ STDIN.read_timeout is
<FromGitter> ... doing nothing on that. its not canceling it after 5 seconds when i specify 5 seconds. ⏎ Is there some other way to cancel after 5 seconds?
<FromGitter> <r00ster91> do i really need to spawn some fiber and then wait 5 secs or what? i actually expected some Socket::Timeout or so
<FromGitter> <bew> @r00ster91 you're changing STDIN... not some other io which communicate with internet..
<FromGitter> <r00ster91> i know. Im asking if theres some other way then
<FromGitter> <fridgerator> if the http request fails, you want to re-try it in a loop?
<FromGitter> <bew> Other than that I'm like oprypin :p
<FromGitter> <r00ster91> nono it doesnt fails. it just does nothing
<FromGitter> <r00ster91> it just waits until its done getting this json
<FromGitter> <r00ster91> (it does nothing when it couldnt get the json for some reason)
<FromGitter> <jwaldrip> Is there anyway around this other than capturing a block? blocks that yield are always inlined, and this call leads to an infinite inlining
<FromGitter> <bew> can you show some code @r00ster91, it's quite abstract for now what you want to do/what you are doing
<FromGitter> <bew> @jwaldrip which one?
<crystal-gh> [crystal] bew opened pull request #5743: Add Enum.count (master...add-enum-count) https://git.io/vAVIY
<FromGitter> <jwaldrip> trying to refactor that so blocks are inline
<FromGitter> <bew> I'm curious about how you can have infinite inlining, should not be possible
alex`` has quit [Ping timeout: 256 seconds]
<FromGitter> <jwaldrip> pull it down.
<FromGitter> <jwaldrip> I think its because its self referencing
rohitpaulk has quit [Ping timeout: 264 seconds]
<FromGitter> <jwaldrip> I would be greatful if you could help to figure that out.
<FromGitter> <jwaldrip> @bew
<FromGitter> <bew> is there a spec I can run to replicate?
<FromGitter> <bew> or sth like that
<FromGitter> <jwaldrip> just run crystal spec
<FromGitter> <jwaldrip> you will see the error, as it wont even compile
<FromGitter> <bew> ok
<FromGitter> <jwaldrip> Also created a branch where I broke tree away from node: https://github.com/obsidian/oak/blob/tree/src/oak/tree.cr
<FromGitter> <jwaldrip> both fail with the same error
<FromGitter> <bew> wow looong error ^^
<FromGitter> <jwaldrip> :-)
<FromGitter> <philfine> Getting wierd problem here
<FromGitter> <philfine> Can I paste some code ?
<FromGitter> <philfine> I get "wrong number of block arguments (given 1, expected 0)"
<FromGitter> <bew> @jwaldrip same error with https://carc.in/#/r/3mpf
<FromGitter> <philfine> But when calling yield I am passing an argument
<FromGitter> <bew> you'll have to find a way to break the inlines somewhere @jwaldrip, maybe by capturing the block in a key place?
<FromGitter> <jwaldrip> Sure, but that is truly recursive
<FromGitter> <philfine> https://carc.in/#/r/3mpg
<FromGitter> <philfine> That is not my problem
<FromGitter> <philfine> Should I get that compile error ?
<FromGitter> <bew> @jwaldrip yours is also recursive I think
vivus has joined #crystal-lang
<FromGitter> <philfine> Seriously ... :)
<FromGitter> <bew> @philfine I don't understand your question/problem
<FromGitter> <philfine> in src/test_app1.cr:58: wrong number of block arguments (given 1, expected 0) ⏎ ⏎ ```write1("?") do |response| ⏎ ^~~~~~``` [https://gitter.im/crystal-lang/crystal?at=5a909c51a2194eb80da5ce7a]
<FromGitter> <philfine> https://carc.in/#/r/3mpg
<FromGitter> <bew> your carcin wasn't failing: https://carc.in/#/r/3mph
<FromGitter> <philfine> I thought the recursion was to my problem :D
<FromGitter> <philfine> Sorry for the "Seriously "
<FromGitter> <philfine> @bew Should it be failing for some less obvious reason
<FromGitter> <bew> @philfine seems that you're trying to have `write1` which optionnaly accept a block, which is not possible in Crystal: the method should accept a block, or it should not
<FromGitter> <bew> if you want to do a different behavior, make 2 methods
<FromGitter> <bew> one accepting a block, one who doesn't
<FromGitter> <philfine> Ok
<FromGitter> <philfine> Thanks ;)
rohitpaulk has joined #crystal-lang
<FromGitter> <vonKingsley> Is it possible to take a JSON mapping and get back a json string. ⏎ something like ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5a90a9ea53c1dbb7436c2f41]
qard has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]