ChanServ changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | Fund Crystal's development: https://crystal-lang.org/sponsors | GH: https://github.com/crystal-lang/crystal | Docs: https://crystal-lang.org/docs | Gitter: https://gitter.im/crystal-lang/crystal
deavmi has joined #crystal-lang
straight-shoota has quit [Quit: ZNC 1.8.2 - https://znc.in]
straight-shoota has joined #crystal-lang
aquijoule_ has joined #crystal-lang
richbridger has quit [Ping timeout: 240 seconds]
deavmi has quit [Read error: Connection reset by peer]
deavmi has joined #crystal-lang
<FromGitter> <djberg96> no multiline comments yet?
<FromGitter> <Blacksmoke16> not a yet, just wont be a thing
<FromGitter> <djberg96> why's that?
<FromGitter> <djberg96> "Using single-line comments on every line is clearer."
<FromGitter> <djberg96> That's not what it's for
<FromGitter> <djberg96> It's for blocking out chunks of code that you're fiddling with, i almost never see them used permanently
<FromGitter> <Blacksmoke16> > There should be a shortcut in your editor to comment multiple lines at once.
<FromGitter> <djberg96> i don't always know in advance where it will end
<FromGitter> <Blacksmoke16> :shrug:
<Andriamanitra> djberg96: luckily you can (ab)use heredocs to simulate multiline comments :D https://play.crystal-lang.org/#/r/aee6
<FromGitter> <Blacksmoke16> i mean cant you just click at the start, scroll, scroll, shift + click at end, then ctrl + / (or whatever the shortcut is)
<FromGitter> <djberg96> Andriamanitra, hah, thanks, that works
<Andriamanitra> probably wouldn't leave anything like that in the final product, but it may be handy when you want to leave out some lines while testing things
<FromGitter> <djberg96> which all i ever use multiline comments for in practice
<FromGitter> <djberg96> i'm not sure i've ever seen ruby code with it, except for some inlined `if $0 == __FILE` code that the author was using to putter around with
<FromGitter> <HertzDevil> ruby has `=begin` and `=end` too
<FromGitter> <djberg96> @HertzDevil yes, i know, i'm saying i only use it during editing
<FromGitter> <djberg96> that, or it's the "this code is broke right now, do not look", so the readability isn't relevant
<FromGitter> <djberg96> anyway...i'll use heredocs :)
hightower3 has quit [Ping timeout: 256 seconds]
f1reflyylmao has joined #crystal-lang
f1refly has quit [Ping timeout: 260 seconds]
chachasmooth has quit [Ping timeout: 260 seconds]
avane has quit [Quit: ZNC - https://znc.in]
avane has joined #crystal-lang
chachasmooth has joined #crystal-lang
chachasmooth has quit [Ping timeout: 264 seconds]
chachasmooth has joined #crystal-lang
postmodern has joined #crystal-lang
<postmodern> does String.new(slice : Bytes, encoding : String) copy the contents of the slice?
<FromGitter> <naqvis> yes
<FromGitter> <naqvis> behind the scenes it uses iconv to perform the encoding conversion
<postmodern> awesome, realized i wasn't calling Hunspell_free_list in my hunspell bindings after i convert the char ** to Array(String) ... :/
<FromGitter> <naqvis> 👍
DTZUZU has quit [Read error: Connection reset by peer]
DTZUZU has joined #crystal-lang
_ht has joined #crystal-lang
<FromGitter> <aravindavk> > `evaluate-commands` in not recognized ⏎ ⏎ @alexherbo2 which version? Fixed in 0.36 https://github.com/crystal-lang/crystal/pull/9465
deavmi has quit [Ping timeout: 272 seconds]
deavmi has joined #crystal-lang
yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
yxhuvud has joined #crystal-lang
Xeago has quit [Ping timeout: 264 seconds]
<FromGitter> <alexherbo2> 1) 35
<FromGitter> <alexherbo2> is there a nicer way to implement a `each_client_with_session` method receiving a session and client?
<FromGitter> <alexherbo2> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=602507b00eed905f18a76266]
<FromGitter> <alexherbo2> I could just iterate and `yield`, but I wanted to forward to each to return an enumator if no block was given
<FromGitter> <alexherbo2> ``` client_list.each do |client| ⏎ yield client, session ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=602508780eed905f18a7645e]
<Andriamanitra> you could use an overload to handle the case where no block was given separately
postmodern has quit [Quit: Leaving]
deavmi has quit [Ping timeout: 240 seconds]
deavmi has joined #crystal-lang
f1reflyylmao is now known as f1refly
deavmi has quit [Quit: Eish! Load shedding.]
deavmi has joined #crystal-lang
<FromGitter> <Blacksmoke16> i had an idea the other day
<FromGitter> <Blacksmoke16> ``` def ===(other : ::Exception) : Bool ⏎ other.message === self ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=60253c851ed88c58d8356981]
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=60253c92aa6a6f319d1c4f99]
<FromGitter> <Blacksmoke16> or maybe even doing like `other.message.includes? self`
<FromGitter> <erdnaxeli:cervoi.se> not bad, but if you are changing your behavior according to the message, should not you make two subtypes instead?
<FromGitter> <Blacksmoke16> if you control the exception for sure
<FromGitter> <Blacksmoke16> even if it is, say like `File::Error`, still are various things it could mean
<straight-shoota> yeah that might be a nice feature, although it's usefulnes should be limited
<straight-shoota> typically you should use separate types for different errors
<straight-shoota> at least in higher level APIs
<FromGitter> <Blacksmoke16> yea are cases where that doesnt make sense. E.g. `ArgumentError`
<straight-shoota> hm, yeah that might be a good case
<FromGitter> <Blacksmoke16> or like "lower level" things, like http client if a request fails
<FromGitter> <Blacksmoke16> multitude of things that could cause that
<FromGitter> <alexherbo2> @Blacksmoke16 do you known a library to pretty print json like `jq`?
<FromGitter> <Blacksmoke16> if you're using the stdlib's `JSON::Serializable` there is `.to_pretty_json`
<FromGitter> <alexherbo2> the output is not colored no?
<FromGitter> <Blacksmoke16> no
<FromGitter> <Blacksmoke16> could just pipe it thru `jq` i guess
<FromGitter> <alexherbo2> is your `oq` intended to be used as a library as well?
<FromGitter> <Blacksmoke16> not really, but prob could be updated slightly to allow it. I.e. provide the IO versus assuming `ARGF` and `STDOUT`
<FromGitter> <Blacksmoke16> yea prob not a bad idea
<FromGitter> <asterite> `ArgumentError` is not something that you should handle. It means a bug in your code
<FromGitter> <asterite> Well, I guess if that's user input then it's fine to handle...
<FromGitter> <jrei:matrix.org> @Blacksmoke16: And the CLI would be easier to test this way
<FromGitter> <Blacksmoke16> for sure, working on it now actually ha
<FromGitter> <Blacksmoke16> so heres a question
<FromGitter> <Blacksmoke16> atm im doing like
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=60256664428d9727dd6d4e4f]
<FromGitter> <Blacksmoke16> `handle_error `used to essentially do like `abort "some string"`
<FromGitter> <Blacksmoke16> but it could also be used in a library context, im updating the method you call to return an `Int32` as the exit code of the job
<FromGitter> <Blacksmoke16> but how would you return from a method from a `rescue` block in a `spawn`?
<FromGitter> <Blacksmoke16> or maybe i should send the channel the exit code, that sounds like a better idea
<FromGitter> <Blacksmoke16> or maybe `Bool | Exception`
deimos_ has left #crystal-lang [#crystal-lang]
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=60256b1e24cd6b60d8329c09]
<FromGitter> <Blacksmoke16> yea that worked well
<FromGitter> <Daniel-Worrall> That's looking Rusty
<FromGitter> <Blacksmoke16> im open to other suggestions :p
sz0 has quit [Quit: Connection closed for inactivity]
<FromGitter> <Daniel-Worrall> no, I meant like the language, sending the exception up the line
<FromGitter> <Blacksmoke16> ah gotcha
<FromGitter> <Daniel-Worrall> > asterite starred crystal-lang/crystal 🤔
<FromGitter> <djberg96> I guess I've done something horribly wrong
<FromGitter> <djberg96> ```dependencies: ⏎ uname: ⏎ github: djberg96/crystal-uname ⏎ version: 0.2.0``` [https://gitter.im/crystal-lang/crystal?at=602584d6aa6a6f319d1d1d65]
<FromGitter> <djberg96> tried that in just a basic boilerplate project, it fails
<FromGitter> <djberg96> take out the version and it fails with `Failed git ls-tree -r --full-tree --name-only 2ee152aa19287770b9f7e0b7ee743843b7ce33ca -- shard.yml (). Maybe a commit, branch or file doesn't exist?`
<FromGitter> <Blacksmoke16> your tag needs to be like `v0.2.0` in GH
<FromGitter> <djberg96> ok, thanks
* FromGitter * djberg96 retags everything
_ht has quit [Remote host closed the connection]
postmodern has joined #crystal-lang
<postmodern> so why does `crystal init` include both "## Development" with "TODO: Write development instructions here" and a "## Contributing" section? What should the Development instructions be?
<postmodern> guessing something like `shards install` and `crystal spec`. Curious why it's left blank with a TODO.
<postmodern> do crystal Pointers have a way of attaching a finalizer? so if they get GCed, I could call some C library function to properly deallocate the thing the pointer points to
<FromGitter> <Blacksmoke16> dev instructions are like "heres how to develop the application locally. E.g. db setup, or external stuff"
<FromGitter> <oprypin:matrix.org> postmodern, no, instead u should tell the C lib to use GC.malloc or allocate memory yourself
<postmodern> hmm that may be a problem for hunspell bindings, if you don't explicitly close the dictionary object, but let GC deallocate it which leaves behind the allocated C pointer
<FromGitter> <oprypin:matrix.org> postmodern, show me the allocation functio n in C
<FromGitter> <oprypin:matrix.org> but i think the actual answer to your problem should not be an answer to your question
<FromGitter> <oprypin:matrix.org> you just need to use the most typical approach
<FromGitter> <oprypin:matrix.org> a class certainly can have a finalizer so it should call the dealloc function inself
<postmodern> basically i'm looking for something like Ruby's FFI::AutoPointer (https://www.rubydoc.info/github/ffi/ffi/FFI/AutoPointer)
<FromGitter> <oprypin:matrix.org> dont have autopointer. use a class which calls the needed function in its finalizer
<postmodern> and does the Class#finalize method have access to the instance variables still when it's called?
<FromGitter> <oprypin:matrix.org> sure
<FromGitter> <Blacksmoke16> given its an instance method i would assume so yes
<postmodern> i also assume i'd have to set some sort of @freed flag to indicate when the pointer was explicitly deallocated (such as when explicitly calling #close).
<FromGitter> <oprypin:matrix.org> oof that shouldn't be done by a C API if it's a good citizen
<FromGitter> <oprypin:matrix.org> never encountered such a need
<postmodern> well that's what FFI::AutoPointer handles for you. You can explicitly call #free, or if GC sweeps the auto-pointer it will check if it's been previously freed to prevent double freeing an old pointer.
<FromGitter> <oprypin:matrix.org> anyway (3) almost conventional example is https://github.com/oprypin/crsfml/blob/c3b775073fdba4ac6da47b06cec6e8b4753edb7c/src/window/obj.cr#L451