ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.30.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
alex``` has quit [Ping timeout: 245 seconds]
sorcus has quit [Ping timeout: 264 seconds]
<companion_cube> is there a kind of smart pointer? say, like this: https://carc.in/#/r/7jom
<companion_cube> I'm not exactly sure why this is not in the stdlib
<companion_cube> to be able to embed structs in other structs
<FromGitter> <Blacksmoke16> i mean you can have ivars that are typed to other structs
<FromGitter> <Blacksmoke16> but i dont know much about pointers
<companion_cube> what's an ivar?
<FromGitter> <Blacksmoke16> instance variable
<companion_cube> ah yeah
<FromGitter> <Blacksmoke16> like your `@ptr`
<companion_cube> I mean, if you want recursion
<companion_cube> you can't do that because the size would be infinite
<companion_cube> (say, if you want to represent a tree)
<companion_cube> but I imagine you might as well use a class…
<FromGitter> <Blacksmoke16> look into https://crystal-lang.org/api/master/JSON/Any.html
<FromGitter> <Blacksmoke16> thats essentially what it is
<companion_cube> ah yes, exactly the kind of things I'm thinking of, thanks
<FromGitter> <Blacksmoke16> np
<companion_cube> akthough the recursion is through Array/Hash
<companion_cube> what if you want only one element in the recursion…
<FromGitter> <Blacksmoke16> like a tree as you said where it consists of x nodes that can each have x nodes?
<companion_cube> or a linked list
<companion_cube> like `alias List = Nil | Cons; record Cons, Int32, List`
<companion_cube> need some pointer for the recursion
<companion_cube> (I just realized that without polymorphic aliases, this is quite irrelevant anyway ^^)
<FromGitter> <Blacksmoke16> why do you need the alias?
<FromGitter> <Blacksmoke16> when you can just type it to `Cons?`
<companion_cube> for the recursion
<companion_cube> yeah yeah, imagine if it's slightly more complicated, like a red-black tree
<companion_cube> I guess, better have `class List(T) end; class Cons(T) < List(T) … end` and then case on it being nil. Anyway.
<companion_cube> it's just me missing sum types.
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/7jop like so?
<companion_cube> well no, an array introduces an indirection (maybe a static array, but still)
<companion_cube> red black trees have at most two children, and you typically want them to be fields, not in an array
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/7jor
<FromGitter> <Blacksmoke16> dont even need the parent class https://play.crystal-lang.org/#/r/7jos
<companion_cube> yeah ,but you use a class
<FromGitter> <Blacksmoke16> ah, is the issue where you cant use a struct?
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/7jou because of that
<companion_cube> well I'm wondering if it's possible to have a union of structs with recursion, like Json::Any, but where the recursion doesn't use Array/Hash
<companion_cube> yep, because of that
<FromGitter> <Blacksmoke16> dunno
<companion_cube> so I'm thinking there sholud be a Box/Ref that is like a one-element Array, basically
<companion_cube> like Box in rust
<companion_cube> ahhh wait
<companion_cube> https://crystal-lang.org/api/0.30.1/Box.html almost, but not quite that :(
<FromGitter> <Blacksmoke16> implement your own type wrapping https://crystal-lang.org/api/master/StaticArray.html?
<companion_cube> or just wrapping Pointer, as I do above
<FromGitter> <Blacksmoke16> :shrug:
<companion_cube> (which is why it should be standard)
<FromGitter> <Blacksmoke16> make a forum thread and see what others think
<companion_cube> ✔
absolutejam1 has joined #crystal-lang
absolutejam1 has quit [Ping timeout: 245 seconds]
<companion_cube> (I hope asterite adds sealed struct/class :P)
chemist69_ has quit [Ping timeout: 246 seconds]
chemist69 has joined #crystal-lang
<companion_cube> hmmm, codepoints are Int32, not UInt64?
_whitelogger has joined #crystal-lang
<FromGitter> <watzon> Yeah for some reason
<FromGitter> <watzon> Never understood that either
<companion_cube> the inability to do Int? is quite annoying :/
<companion_cube> yeah sounds ike this should change before 1.0
ht_ has joined #crystal-lang
_whitelogger has joined #crystal-lang
<FromGitter> <watzon> This is gonna take a while, but I'm excited
absolutejam1 has joined #crystal-lang
ht_ has quit [Quit: ht_]
absolutejam1 has quit [Ping timeout: 265 seconds]
absolutejam1 has joined #crystal-lang
absolutejam1 has quit [Ping timeout: 245 seconds]
chachasmooth has quit [Ping timeout: 264 seconds]
chachasmooth has joined #crystal-lang
absolutejam1 has joined #crystal-lang
<FromGitter> <bew> @Blacksmoke16 about crserializer' custom strategies, can you give an example of existing ones? (like group/version)
livcd has joined #crystal-lang
Human_G33k has quit [Read error: Connection reset by peer]
HumanG33k has joined #crystal-lang
hightower2 has joined #crystal-lang
sorcus has joined #crystal-lang
alex``` has joined #crystal-lang
<Yxhuvud> @companion_cube : btw, if you want an internal list instead of an external you can do something like https://gist.github.com/yxhuvud/c7e520fd2f6928205441c9739e38fb78
<FromGitter> <spTorin> How I can keep some uniq values with fast access on check existence value. Like `[1, 5, 78, 12].includes?(12)`, but array is big and do this many times. Think what `set` is good for it, but speed `includes?` on set is 10x slower then `includes?` on array.
<FromGitter> <spTorin> Like hash table, but not need value and need only key.
<Yxhuvud> spTorin: That shouldn't be the case if the list is indeed large. Can you show us your code and benchmarks?
<FromGitter> <spTorin> In my code speed of `array.includes?` is enough. It’s just interesting if there are structures for quick searching in elements. ⏎ `array.includes?` - O(n) ⏎ `hash.has_key?` - O(log n)
<FromGitter> <spTorin> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d7a1b4885e8096c180329b6]
<FromGitter> <spTorin> Don't know why set slower. In docs `Set uses Hash as storage`.
<Yxhuvud> I'm not certain what is going on there - if I change the size to 100000000 it doesn't change the time of the array case, so it looks to be optimized out
<Yxhuvud> (and also change the value to seek for to be at the end)
<FromGitter> <spTorin> Now I looked at the size of the array and the location of the search element, it seems that the speed does not really change. Why? Indeed, the comparison goes element by element.
<FromGitter> <spTorin> ```code paste, see link``` ⏎ ⏎ Same speed... magic... [https://gitter.im/crystal-lang/crystal?at=5d7a1e5bb15da36b28ecde4b]
sorcus has quit [Ping timeout: 246 seconds]
<FromGitter> <bararchy> @Sija you're here?
sagax has quit [Quit: Konversation terminated!]
<FromGitter> <Blacksmoke16> @bew ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d7a33bf0fc49226624cfdd8]
<FromGitter> <Blacksmoke16> i.e. the `#groups=` setter on the context handles adding that strategy, same idea if you were to do like `context.version = "1.25.0"`
<FromGitter> <Blacksmoke16> whereas if you had custom ones it would be more lik
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d7a345162f0416c19aefa8f]
<FromGitter> <Blacksmoke16> or ofc apply conditional logic etc
<FromGitter> <Blacksmoke16> i mean its flexible enough where the user can do it however they like, im just trying to think of all the ways i can be done to make sure everything work as expected
<FromGitter> <dscottboggs_gitlab> why does this work (https://carc.in/#/r/7jsp) while this does not (https://carc.in/#/r/7jsq)?
absolutejam1 has quit [Ping timeout: 276 seconds]
absolutejam1 has joined #crystal-lang
<FromGitter> <j8r> https://carc.in/#/r/7jsw
<FromGitter> <dscottboggs_gitlab> I see
<FromGitter> <dscottboggs_gitlab> thanks
sagax has joined #crystal-lang
jrayhawk has quit [Quit: leaving]
jrayhawk has joined #crystal-lang
alex``` has quit [Ping timeout: 245 seconds]
alex`` has joined #crystal-lang
absolutejam1 has quit [Ping timeout: 276 seconds]
ht_ has joined #crystal-lang
alex``` has joined #crystal-lang
alex`` has quit [Ping timeout: 246 seconds]
<FromGitter> <jwoertink> The `Concurrent::Future` has a `:nodoc:` https://github.com/crystal-lang/crystal/blob/master/src/concurrent/future.cr#L1 Should it be like that?
<FromGitter> <jwoertink> oh, I guess there's a top level method `future`
<FromGitter> <jwoertink> I'm assuming it's meant to use that instead
alex``` has quit [Quit: WeeChat 2.5]
<FromGitter> <kingsleyh> @watzon hey sorry I'm not working on the Crystal Idea plugin anymore - too busy on SushiChain
<FromGitter> <kingsleyh> It would take me several months to complete the original vision I had for it
<FromGitter> <kingsleyh> I think the best bet would be to get Jetbrains to build it
<companion_cube> hopefully a LSP server will emerge first
<FromGitter> <kingsleyh> I wrote the D Language intellij plugin and it took a lot of help from Jetbrains devs to get it done and I handed it off to another team who are still constantly improving it
<FromGitter> <kingsleyh> yes - Scry does seem to work pretty well with Intellij
<FromGitter> <kingsleyh> if you take my base intellij plugin and install the LSP plugin and Scry
<FromGitter> <kingsleyh> a fully functioning intellij plugin is awesome though - with full refactoring, hints, completion, project view, test runner, tooling for shards etc - that was my original vision
<FromGitter> <watzon> It would be really nice if JetBrains built it
<FromGitter> <watzon> But it will probably take then years if they ever do
<companion_cube> not before 1.0 anyway
return0e has quit [Read error: Connection reset by peer]
return0e has joined #crystal-lang
dannyAAM has quit [Quit: znc.saru.moe : ZNC 1.6.2 - http://znc.in]
dannyAAM has joined #crystal-lang
sorcus has joined #crystal-lang
<FromGitter> <stronny> hey guys! ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ Is this a known issue or should I submit a new one? [https://gitter.im/crystal-lang/crystal?at=5d7a8ff8ced9d31a52745a09]
<FromGitter> <stronny> without the last line it works, so this probably has something to do with Tuples or Values
absolutejam1 has joined #crystal-lang
<FromGitter> <watzon> I'd check the issues in the crystal repository, but it's not something I've seen before
<FromGitter> <asterite> I don't think you can have an instance variable of type `Enumerable` yet (well, you can but it crashes)
<FromGitter> <JohnDowson> Why does this ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ works? [https://gitter.im/crystal-lang/crystal?at=5d7a9d4462f0416c19b237b4]
<FromGitter> <Blacksmoke16> i mean neither of those works?
<FromGitter> <didactic-drunk> Why doesn't an Array of Atomic values work?
<FromGitter> <watzon> @didactic-drunk example?
<FromGitter> <didactic-drunk> I think it has to do with Atomic as a Struct, but how would I make it work?
<FromGitter> <JohnDowson> Corrected. The first one errored with not enough arguments, second one works
<FromGitter> <Blacksmoke16> well whats `Boo::Far`?
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/7jvu
<FromGitter> <watzon> Chances are it's because you're not setting the type of `&block`
<FromGitter> <watzon> @didactic-drunk as far as your question, I have no clue
<FromGitter> <watzon> I never use Atomics
<FromGitter> <didactic-drunk> @asterite? Array of Atomic broken.
<FromGitter> <watzon> What I'm wondering is why `Char#letter?` doesn't work for the entire unicode space. It seems to work with Cyrillic, but not Japanese, Chinese, Hindi, etc.
ht__ has joined #crystal-lang
ht_ has quit [Ping timeout: 246 seconds]
ht__ is now known as ht_
<FromGitter> <kinxer> What do you mean by "errored out with not enough arguments"?
<FromGitter> <JohnDowson> Uhh, I can't replicate it now. ⏎ https://play.crystal-lang.org/#/r/7jwt ⏎ this is sort of thing that wasn't working, but it clearly works now
<FromGitter> <Blacksmoke16> 👍
<FromGitter> <watzon> Ok this is driving me crazy. I need a way to tokenize a string, without using regex. The problem is I need it to be utf8 compatible (ie. it needs to work with hindi, japanese, etc) and it needs to remove tokens that contain anything that's not a letter character.
<FromGitter> <watzon> Doing it with Regex is easy, but it's also extremely slow
<FromGitter> <Blacksmoke16> tokenize meaning get array of all chars? or?
<FromGitter> <stronny> utf8 is encoding, but looks like you need to parse it into unicode codepoints and then interate over them?
<FromGitter> <watzon> Tokenize meaning separate a string into words
<FromGitter> <stronny> https://crystal-lang.org/api/0.30.1/Char.html#ascii_letter?-instance-method ?
<FromGitter> <watzon> But it looks like the regex might actually not be the slow part
<FromGitter> <watzon> @stronny doesn't work with hindi, japanese, chinese, etc
<FromGitter> <stronny> can you give an example?
<FromGitter> <kinxer> @watzon How are you defining your letter sets?
<FromGitter> <watzon> `इ.letter?` is false
<FromGitter> <stronny> should it be true?
<FromGitter> <watzon> @kinxer I'm not right now. I really don't want to have to create a whole character table for this.
<FromGitter> <kinxer> That's a fair point. It should probably be true in the standard library.
<FromGitter> <watzon> Idk why it doesn't
<FromGitter> <watzon> `Unicode.letter?` should work for those character sets imo
<FromGitter> <watzon> @stronny yes, that is a valid hindu letter
<FromGitter> <kinxer> Also, "letter" is probably not the right term to use here, but that's another thing entirely.
<FromGitter> <watzon> Maybe not, but idk what else you'd call it that's language agnostic
<FromGitter> <stronny> probably smth to do with these https://en.wikipedia.org/wiki/Unicode_character_property
<FromGitter> <watzon> Shouldn't be, those characters match with regex
<FromGitter> <watzon> `tokens = string.split(/[\p{S}\p{N}\p{P}\p{C}]+/)` works just fine
<FromGitter> <kinxer> Maybe "grapheme". My pedanticism is irrelevant to your problem, though...
<FromGitter> <watzon> Basically splits on whitespace, numbers, punctuation, and invisible control characters
<FromGitter> <kinxer> So your issue with using regex is performance?
<FromGitter> <stronny> idk if that's a good idea to support these lists inside Crystal itself
<FromGitter> <stronny> @watzon you may override these methods as a quick solution
<FromGitter> <watzon> @kinxer yeah pretty much. I'm matching on some very large strings.
<FromGitter> <watzon> @stronny idk how quick a solution that would be, it would be about the same as building a character mapping table
<FromGitter> <Blacksmoke16> maybe useful?
<FromGitter> <watzon> It looks like the regex might not be as bad as I thought though
<FromGitter> <watzon> @Blacksmoke16 hmm I didn't know that was a thing
<FromGitter> <JohnDowson> Fun fact: japanese doesn't really require you to ever separate words with anything at all
<FromGitter> <watzon> Could be useful in the future
<FromGitter> <watzon> @JohnDowson true. Neither do some middle eastern languages I believe
<FromGitter> <watzon> Not a real issue for me though. The main goal is filtering out characters I don't want.
<FromGitter> <Blacksmoke16> could new one of those up then use `#reject`
<FromGitter> <stronny> link with existing libs that can deal with categories? smth like https://begriffs.com/posts/2019-05-23-unicode-icu.html
<FromGitter> <watzon> It looks like the slow part of my tokenization might have been the other part though, where I'm breaking each token up into characters, running `each_cons` on them, and then building smaller strings and adding them to an array
<FromGitter> <watzon> I just wrapped that part in a `spawn` block and it made everything almost instantanious
<FromGitter> <watzon> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d7aa807d3283306ba2e7d39]
<FromGitter> <stronny> ummmm
<FromGitter> <stronny> well, does it work as expected?
<FromGitter> <watzon> Yep, for now anyway haha
<FromGitter> <stronny> are you sure?
<FromGitter> <watzon> My previous tokenization method worked fine until I threw Hindi at it
<FromGitter> <stronny> you fibers run after your method returns
<FromGitter> <kinxer> It doesn't look like you're doing anything with the fibers you spawn.
<FromGitter> <kinxer> Oh, no, actually I'm wrong. Listen to @stronny .
<FromGitter> <watzon> You're right, I need to yield to the fiber
<FromGitter> <watzon> Doesn't seem to be an issue in my code for a reason, but running it by itself doesn't return anything
<FromGitter> <stronny> what should it return?
<FromGitter> <watzon> Eh nvm
<FromGitter> <watzon> Spawn doesn't fix shit
<FromGitter> <watzon> With MT it would
<FromGitter> <stronny> with MT you'll have a massive race condition
<FromGitter> <watzon> True, unfortunately
<FromGitter> <stronny> do you really need i18n?
<FromGitter> <stronny> I prefer to just ignore anything that's not English honestly
<FromGitter> <watzon> Yeah it's kinda the purpose of this code
<FromGitter> <watzon> I'm tokenizing files in other languages for training
<FromGitter> <JohnDowson> split tokens among the threads, wait for threads, join results into groupings?
<FromGitter> <stronny> well, I think the right way is to use external C libs
<FromGitter> <watzon> @JohnDowson that would work
<FromGitter> <stronny> it's not even about speed, it's about correctness
<FromGitter> <watzon> Well I can get the correctness pretty easily, but I'd like to get a bit more performance out of it
<FromGitter> <watzon> And I definitely don't want to resort to using C, that's not worth it
<FromGitter> <stronny> I mean use them from inside Crystal
<FromGitter> <watzon> Yeah I know, but if I have to write C code and write bindings for it I've already lost 😄
<FromGitter> <stronny> whay do you need each_cons? what are you doing there?
<FromGitter> <watzon> It's part of the training. I'm building a language detector which uses a Bayes classifier. `each_cons` is breaking each token up into bite size pieces that my classifier can use to determine what letters are closer to each other in any given language.
<FromGitter> <stronny> do you need a separate array for that? can you feed each grouping directly?
<FromGitter> <watzon> I just need the result of `#tokenize` to be an array of Strings where each string is a piece of a token with a length no greater than 3.
<FromGitter> <watzon> I wish there was a `map_cons` or something. I hate having to use `each_cons` and push each one to an array
<FromGitter> <stronny> I think there are lots of allocations that you don't really need
<FromGitter> <Blacksmoke16> try using the reader then map?
<FromGitter> <Blacksmoke16> idk if that would help
<FromGitter> <stronny> String.split can take a block, String.each_char is an Iterator
<FromGitter> <Blacksmoke16> got some sample code we can benchmark @watzon ?
<FromGitter> <watzon> Just a sec
<FromGitter> <Blacksmoke16> or is it not simple?
<FromGitter> <stronny> #each_cons has `reuse` arg
<FromGitter> <stronny> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d7aad94d5c523462f7066af]
<FromGitter> <stronny> can you clarify what's going on here? you split, then join, then downcase, why?
<FromGitter> <watzon> https://carc.in/#/r/7jxz
<FromGitter> <watzon> I want all the tokens to be downcased for training, otherwise the same string could be seen differently by the classifier because the case is different
<FromGitter> <stronny> do you need an array though?
<FromGitter> <watzon> Yes
<FromGitter> <asterite> @didactic-drunk I'm not Crystal :-)
<FromGitter> <watzon> The classifier has to take that array and make a frequency table
<FromGitter> <stronny> can you show the classifier?
<FromGitter> <stronny> I suspect it will iterate the array, split the strings and inspect each char again
<FromGitter> <watzon> It doesn't. I'm overriding the default Tokenizer it's using there, but it doesn't end up splitting the strings again. That's what the whole purpose of the tokenizer is.
<FromGitter> <watzon> All it does is assign each token to a hash and counts the occurrences. Then does some math to determine the probability that a particular token belongs to a category.
<FromGitter> <asterite> @watzon in your code you might be able to do `each_cons(@min_size, reuse: true)` to reuse the array that's yielded to the block, since anyway you just `join` and `downcase` it so it doesn't matter if it's the same array between each iteration. Might speed up things a bit. Also you probably want to `cons.map!(&.downcase)` first to avoid a second array
<FromGitter> <watzon> Ooh nice!
ht_ has quit [Quit: ht_]
<FromGitter> <watzon> I think you *are* Crystal, @asterite
<FromGitter> <watzon> 😉
<FromGitter> <stronny> I would refactor the library
<FromGitter> <watzon> Tbh I wrote it a while ago and it does need some refactoring
<FromGitter> <Blacksmoke16> `without reuse 3.78k (264.41µs) (± 4.27%) 187kB/op fastest` ⏎ `with 4.38k (228.49µs) (± 1.73%) 159kB/op fastest`
<FromGitter> <stronny> initialize with an empty freq table, then take one token at a time and mutate the table
<FromGitter> <asterite> if I'm crystal I should be able to merge my markd PR ;-) ⏎ but I can't so I'm not
<FromGitter> <Blacksmoke16> any ideas on https://github.com/crystal-lang/crystal/issues/8136 ?
<FromGitter> <stronny> now for something completely different
<FromGitter> <stronny> https://play.crystal-lang.org/#/r/7jx1 ⏎ any way to make the syntax better?
<FromGitter> <stronny> I need a hash of Structs
<FromGitter> <stronny> mutable Structs
<FromGitter> <stronny> @Blacksmoke16 trailing `\r`?
<FromGitter> <Blacksmoke16> dont think so
<FromGitter> <asterite> @Blacksmoke16 you said you'll make a PR for it
<FromGitter> <Blacksmoke16> for a diff issue, was thinking of having `xml.expand` raise on error, but also add `xml.expand?` that returns nil on error
<FromGitter> <Blacksmoke16> but that issue is why it returns nil when you pass `ARGF` but expands fine when you do `ARGF.gets_to_end`
<FromGitter> <stronny> different initialize methods
<FromGitter> <stronny> IO vs String
<FromGitter> <Blacksmoke16> right, which would indicate there is an issue with the IO one
<FromGitter> <stronny> however, ``` ⏎ io = File.open(ARGV.first) ⏎ xml = XML::Reader.new(io) ⏎ ⏎ ```works``` [https://gitter.im/crystal-lang/crystal?at=5d7ab294d3283306ba2ed1eb]
<FromGitter> <watzon> Fun fact: apparently the vast majority of hindi characters come up as "unassigned" under unicode categories
<FromGitter> <watzon> Yay me
<FromGitter> <stronny> where did you check that?
<FromGitter> <Blacksmoke16> hmm, strange
<FromGitter> <watzon> I just checked using carc.in and running hindi characters though a regular expression
<FromGitter> <asterite> it seems like a bug in ARGF
<FromGitter> <stronny> @watzon ah, you mean in Crystal? ⏎ yes, that was the first thing I've shown you
<FromGitter> <Blacksmoke16> @asterite sure seems like it
<FromGitter> <asterite> i know how to fix it
<FromGitter> <Blacksmoke16> 😮
<FromGitter> <Blacksmoke16> ❤️
<FromGitter> <asterite> Try this: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d7ab431d3283306ba2ee20a]
<FromGitter> <asterite> it prints an empty string at the end
<FromGitter> <asterite> argf.cr line 79 should be read_count == 0, I think
<FromGitter> <asterite> if somebody wants to send a PR (with tests!). I don't have time, sorry
<FromGitter> <Blacksmoke16> i prob can do when i get home if no one beats me to it
<FromGitter> <Blacksmoke16> i monkey patched that into my example and it worked 💯
return0e has quit [Ping timeout: 246 seconds]
<FromGitter> <asterite> Cool!
<FromGitter> <stronny> so, any advice on hash of mutable structs?
<FromGitter> <watzon> Why do you need mutable structs? They're typically a bad idea, which I'm sure you already know
<FromGitter> <stronny> I disagree, they are imo a very good idea
absolutejam1 has quit [Ping timeout: 246 seconds]
<FromGitter> <stronny> for now I think this will do: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d7abf9e2e8fd94630c0e486]
<FromGitter> <asterite> > any advice on hash of mutable structs? ⏎ don't :-)
<FromGitter> <stronny> I refuse to allocate! =)
<FromGitter> <asterite> if you mutate struct the hash value will change, you need to call rehash anyway
<FromGitter> <stronny> it's in V, not in K
<FromGitter> <asterite> ah, right
<FromGitter> <stronny> by mutation I mean reassignment anyway
<FromGitter> <asterite> we have `Array#update` that receives a block with the value and updates that index with the block's value
<FromGitter> <asterite> we could probably add it to Hash too
<FromGitter> <stronny> would be very nice
<FromGitter> <asterite> I thought about it many times, it will avoid a double hash lookup
<FromGitter> <asterite> if you want you can send a feature request issue in GitHub
<FromGitter> <stronny> ```crystal$ grep -r ary . | wc -l ⏎ 1294``` [https://gitter.im/crystal-lang/crystal?at=5d7ac35ad3283306ba2f6328]
<FromGitter> <stronny> I think you are Crystal after all
<FromGitter> <watzon> 😂
<FromGitter> <watzon> At least there's 1294 pieces of him in Crystal
absolutejam1 has joined #crystal-lang
<FromGitter> <watzon> Crystal is merely a horcrux
absolutejam1 has quit [Ping timeout: 276 seconds]
return0e has joined #crystal-lang
sorcus has quit [Ping timeout: 245 seconds]
<FromGitter> <watzon> What would be the best way to emulate Ruby's `eval`?
<FromGitter> <watzon> I know `eval` is generally a bad idea, but I have a good reason
<FromGitter> <Blacksmoke16> *do you*
<FromGitter> <asterite> > I think you are Crystal after all ⏎ lol :-)
<FromGitter> <watzon> It's for an interpreter type environment, so yes :)
<FromGitter> <watzon> Don't worry, it will be sandboxed
<FromGitter> <asterite> What would be the best way to emulate Ruby's `eval`? --> `nil.not_nil!`
<FromGitter> <watzon> 😂
<FromGitter> <watzon> I know I could save the string as a file and then invoke the compiler and execute it, but I'm wondering if there's a more streamlined approach
<FromGitter> <stronny> no
<FromGitter> <stronny> tell us the good reason
<FromGitter> <watzon> > It's for an interpreter type environment, so yes :) ⏎ ⏎ Already did
<FromGitter> <watzon> I'm writing an interpreter
<FromGitter> <stronny> please clarify
<ukd1_> \q
ukd1_ has quit [Quit: leaving]
<FromGitter> <watzon> It's for a bot which can execute crystal code and return the result
<FromGitter> <watzon> Similar to https://t.me/rextester_bot
<FromGitter> <stronny> well, okay. there is the Play with its source, there are several I think repls, you can try investigating how it's done there
<FromGitter> <watzon> I already know how it's done there, that's why I'm asking if there's a more streamlined approach. Those tend to be much more complicated than this is.
<FromGitter> <watzon> But I figured it would be a no
<FromGitter> <stronny> not easily at least
<FromGitter> <watzon> Oh well, should be interesting to figure out
<FromGitter> <watzon> On another note, it would be really handy if the `Time` class had a `#with_timeout` method. So you could do ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d7ad5ee72fe12511195606e]
<FromGitter> <stronny> after poking around I currently think there is no good way to do it
<FromGitter> <stronny> you can't kill a fiber
<FromGitter> <watzon> True
<FromGitter> <stronny> you can't fork either
<FromGitter> <stronny> go's model was a mistake imo
<FromGitter> <stronny> what's inside the timeout?
<FromGitter> <watzon> A lot about Go was a mistake
<FromGitter> <stronny> there is no general solution, but there are partial ones
<FromGitter> <stronny> I mean Crystal adopting Go's model was a mistake
<FromGitter> <stronny> go itself is a lost cause
<FromGitter> <watzon> > what's inside the timeout? ⏎ ⏎ Could theoretically be anything, in this case it would be executing an external process and waiting for it to complete
<FromGitter> <stronny> anything? no. Process.wait? yes
<FromGitter> <stronny> ``````
<FromGitter> <stronny> ```spawn do ⏎ sleep 5.seconds ⏎ child.kill ⏎ end``` ⏎ ⏎ easy [https://gitter.im/crystal-lang/crystal?at=5d7ad79cba12e064485eaaa2]
<FromGitter> <watzon> I mean, I know how to do a simple timeout. It would just be nice to have a built in solution like Ruby does
<FromGitter> <stronny> crystal is nothing like ruby though besides syntax similarity
<FromGitter> <watzon> Oh I know
<FromGitter> <stronny> Ruby has threads, you can kill a thread
absolutejam1 has joined #crystal-lang
<FromGitter> <stronny> there is no separate instruction flow in Crystal that schedules fibers, they cooperate to yield execution to one another
<FromGitter> <stronny> threads are scheduled by kernel, they are almost the same as processes that share heap
<FromGitter> <Blacksmoke16> @asterite what exactly was the bug with ARGF?
<FromGitter> <Blacksmoke16> it wasn't reading when there was more data left to read?
<FromGitter> <stronny> by the way, what should the timeout do? stop the Process.wait call?
<FromGitter> <JohnDowson> allright, it happened again
<FromGitter> <Blacksmoke16> 😮
<FromGitter> <JohnDowson> ``` ^----- ⏎ Error: wrong number of block arguments (given 1, expected 0)`````` [https://gitter.im/crystal-lang/crystal?at=5d7ada08c82c2e0d7ec58ac6]
<FromGitter> <Blacksmoke16> got a playground link?
absolutejam1 has quit [Ping timeout: 245 seconds]
<FromGitter> <JohnDowson> it's too big for playground sadly
<FromGitter> <Blacksmoke16> what happens if you remove the `|w|`
<FromGitter> <stronny> maybe show us the ui.window?
<FromGitter> <JohnDowson> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d7adb6cd5c523462f71c1d2]
<FromGitter> <JohnDowson> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d7adb80b84cb24c7ebc09bf]
<FromGitter> <stronny> I think you should type &block
<FromGitter> <stronny> `&block : CyrseUI::Window -> Return_type | Nil`