<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>
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? :)
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> 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> 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>
<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> 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
<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
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?
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
<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>
<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