ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.34.0 | 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
return0e has quit [Read error: Connection reset by peer]
return0e has joined #crystal-lang
mistergibson has quit [Quit: Leaving]
hpyc9 has quit [Quit: ZNC 1.7.5 - https://znc.in]
hpyc9 has joined #crystal-lang
<FromGitter> <kinxer> @neutrinog `Prism::Common::Objects::Plain` is cheeky but should probably be renamed to have the correct spelling. :P
deavmi has quit [Read error: Connection reset by peer]
deavmi has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 240 seconds]
ur5us has joined #crystal-lang
ur5us has quit [Remote host closed the connection]
ur5us has joined #crystal-lang
ur5us has quit [Ping timeout: 260 seconds]
ur5us has joined #crystal-lang
ur5us has quit [Ping timeout: 260 seconds]
zorp has joined #crystal-lang
alexherbo2 has joined #crystal-lang
ur5us has joined #crystal-lang
claudiuinberlin has joined #crystal-lang
ur5us has quit [Ping timeout: 260 seconds]
hpyc9 has quit [Killed (Sigyn (Stay safe off irc))]
<FromGitter> <acook> Is there a way in a Crystal macro to load up an external file and treat it like it was inline Crystal? It just occurred to me that in Ruby I could do like `module Namespace; eval File.read "foo.rb"; end` to force the contents of a file into a namespace, and I wondered if I could do something like that with a Crystal macro.
<FromGitter> <naqvis> have you tried `read_file` macro? https://crystal-lang.org/api/0.34.0/Crystal/Macros.html#read_file(filename):StringLiteral-instance-method
ua has joined #crystal-lang
ua has quit [Read error: Connection reset by peer]
ua has joined #crystal-lang
<FromGitter> <acook> Ah I was looking in the wrong place for macros, that might be worth looking into. It returns a StringLiteral version of the file it says. But that won't let me evaluate the String Literal as Crystal code. Hmm.
<FromGitter> <acook> (at compile time)
<FromGitter> <naqvis> beneath that, there is another macro :) ⏎ ⏎ https://crystal-lang.org/api/0.34.0/Crystal/Macros.html#run(filename,*args):MacroId-instance-method
<FromGitter> <naqvis> Crystal doesn't support dynamic invocation, so things will be evaluated at compile time
<FromGitter> <naqvis> if you are looking for some dynamic invocation of piece of code, then you are out of luck here
_ht has joined #crystal-lang
<FromGitter> <acook> I'm looking for it to do it's thing at compile time. I'm not trying to do runtime shenanigans.
<FromGitter> <naqvis> πŸ‘
<FromGitter> <acook> If I'm reading it right `run` compiles and runs an external Crystal file and returns its output as a StringLiteral?
<FromGitter> <acook> Sorry, MacroId
<FromGitter> <naqvis> yeah
<FromGitter> <acook> Hmm. That isn't the most convenient but that might work with an intermediary program.
<FromGitter> <naqvis> what is it you are trying to achieve
<FromGitter> <acook> A simple macro that calls out to a fairly small Crystal program that just does `puts "module #{ARGV[1]}; #{File.read ARGV[0]}; end;"`would wrap the one file... but I'd also need to hijack `require`. That'd be a little more work.
<FromGitter> <acook> I'm trying to force external libraries to behave ;)
<FromGitter> <acook> The general use case is being able to wrap any import in a namespace to keep it from clobbering anything with the same names in the global namespace.
<FromGitter> <acook> For example, there are no restrictions on Shards actually defining top level constants that are identical to their names. So a shard named "foo" might define "module Bar".
<FromGitter> <acook> This is a problem when some other shard called "bar" also defines "Bar"
<FromGitter> <acook> Yesterday we were talking about how it'd be useful if something like `module Namespace; require "foo"; end` would wrap the contents of `foo.cr` in that namespace, but there's a lot of weird edgecases to consider.
<FromGitter> <acook> So I could write a preprocessor that would hijack `require` and wrap the files in the appropriate namespace. That would have the desired result, until such a time that Crystal itself comes up with a better solution.
<FromGitter> <naqvis> this seems like a bigger challenge
<FromGitter> <acook> I mean yeah probably
<FromGitter> <naqvis> as wrapping required files is one part, but major task is modifying the code which is referring to those require files functionality
<FromGitter> <naqvis> wrapping code in namespace, would also require accessing code to approach that similar fashion
<FromGitter> <acook> It could if they do `::OriginalNamespace` but if they use relative paths it should still work
<FromGitter> <naqvis> also I haven't seen any codebase which doesn't make use of namespacing in crystal
<FromGitter> <naqvis> but i'm not negating the case πŸ˜†
<FromGitter> <acook> I ran into the issue because two shards with different names use the same toplevel namespace, it's understandable but annoying
<FromGitter> <naqvis> aahh
<FromGitter> <naqvis> you got a jackpot lol
<FromGitter> <acook> It'd be easier to fork and change the namespace myself, but I'd still want to find a general purpose solution and not have to fork and maintained forks of a bunch of people's stuff
<FromGitter> <naqvis> agree and hope Crystal could have improved `require` functionality like aliasing on the spot to avoid clashes
<FromGitter> <acook> It'd also make it possible to have multiple copies of the otherwise same code, which could be good or bad depending on your perspective.
<FromGitter> <naqvis> I don't think alias will actually brought the whole same code-base during compilation
<FromGitter> <naqvis> it would be just a syntactic sugar to name required module differently
<FromGitter> <naqvis> like other likes do this work
HumanGeek has joined #crystal-lang
<FromGitter> <acook> It's not just sugar though, because decisions need to be made in the compiler as to reopening classes and for files that define multiple top level constants. This is a language design limitation because of the freedom Crystal gives.
<FromGitter> <acook> `foo.cr` could contain `module Foo;end; module Bar;end` so what does `require "foo" as "baz"` do to `Bar`?
<FromGitter> <acook> I feel like I need to make a small repo of potentially problematic requires because it's hard to explain the problems I see one line at a time
Human_G33k has quit [Ping timeout: 256 seconds]
ur5us has joined #crystal-lang
olbat has quit [Max SendQ exceeded]
<FromGitter> <naqvis> i would say that would behave like "baz::Bar"
<FromGitter> <naqvis> kind of required to access to those aliased module using the alias prepended
ur5us has quit [Ping timeout: 260 seconds]
HumanGeek has quit [Ping timeout: 250 seconds]
HumanG33k has joined #crystal-lang
<FromGitter> <acook> Yeah I think that's the only sane way to do it
<FromGitter> <acook> There's still so many weird edge cases
<FromGitter> <naqvis> true
<FromGitter> <pynixwang> no package, only module
<FromGitter> <pynixwang> can be done by add `package` like golang
HumanG33k has quit [Ping timeout: 256 seconds]
HumanG33k has joined #crystal-lang
<FromGitter> <alex-lairan> I have an error when I build ameba : ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ Any idea ? [https://gitter.im/crystal-lang/crystal?at=5e9440571aaf8e4b8e7c418d]
<FromGitter> <alex-lairan> I have only 1Go ram available
<FromGitter> <stronny> swap?
<Stephie> More ram somehow
<oprypin> swappity swap
<oprypin> alex-lairan, like, swap is actually the way to go. i can compile some stuff on my VPS with 512MiB
<FromGitter> <stronny> what was there about zram?
<FromGitter> <alex-lairan> Okay, I will download more ram :D ⏎ ⏎ Thankfully I just found that scaleway new servers cost the same for double memory. ⏎ My server will go from 1Go RAM to 2Go RAM + 2Go Swap. ⏎ ... [https://gitter.im/crystal-lang/crystal?at=5e944a4c5d148a0460021fa2]
<FromGitter> <stronny> why just 2G swap though?
<FromGitter> <stronny> make it 32 or more
<FromGitter> <alex-lairan> It costs money ;)
<FromGitter> <stronny> how?
<FromGitter> <alex-lairan> Cloud pricing ^^
<FromGitter> <asterite> Anthony: use read file and then paste that into the program. There's no need to use run
<oprypin> my provider says please dont use swap but i wouldnt use a provider that would prevent that
<FromGitter> <stronny> oooh, they just give you 20G
<FromGitter> <stronny> @alex-lairan you could mount swap temporarily with this `Block Storage SSD 5,000 IOPS Free €0.08/GB/month`
<FromGitter> <stronny> and just pay them few cents for the time you actually need it
<FromGitter> <alex-lairan> Oh, yes thanks.
hpyc9 has joined #crystal-lang
<Stephie> @alex-lairan be careful with scaleway, they at leased *used* to be have terribly unreliable storage. Make sure anything important on a scaleway VM is backed up.
<FromGitter> <stronny> backup is universally a good idea anyway lol
deavmi has quit [Read error: No route to host]
deavmi has joined #crystal-lang
deavmi has quit [Read error: Connection reset by peer]
deavmi has joined #crystal-lang
<FromGitter> <alex-lairan> Yea, the scaleway is just my server, all the data goes to the databases
<oprypin> Stephie, so on Windows i found that during compiler's operation, if in a particular spot I hit `raise NotImplementedError.new`, the compiler process crashes immediately with exit code -1073741571
<oprypin> thaaats not good
<Stephie> that is not good, at all
<Stephie> everything's broken just pretend it's not
<Stephie> wait
<Stephie> stack overflow
<Stephie> is that *it*?
<oprypin> i dont know, why is it overflowing specifically when encountering an exception
<Stephie> idk
<Stephie> i dont want to find out
<oprypin> the internet seems to say it's buffer overflow rather than stack overflow which is more specific
olbat has joined #crystal-lang
<Stephie> uhh
<Stephie> buffer overflow doesnt cause
<Stephie> hmm
<Stephie> maybe it is just "memory protection violation"
<oprypin> anyway i'll have a repro once the PRs settle down
<Stephie> stack or heap
<Stephie> so yeah
<Stephie> equivalent to sigsegv
<oprypin> i think so
<Stephie> 0xc0000005
<FromGitter> <stronny> how do you debug in windows? anything like gdb there?
<Stephie> yeah
<Stephie> @stronny windbg
<Stephie> i run it in visual studio
<Stephie> use the visual studio debugger
<FromGitter> <stronny> what does it say?
<oprypin> umm i wish i knew how to use that
<oprypin> to me it just says it crashed and shows address locations of the call stack, (raw addresses) that's it
<oprypin> windbg i mean
<repo> is it possible to set instance vars of an object even if it hasn't defined a setter?
<FromGitter> <stronny> monkey patch and add a method
<repo> mmh
hpyc9 has quit [Killed (Sigyn (Stay safe off irc))]
<oprypin> oof
<repo> what about private methods? can i force call them?
<FromGitter> <stronny> monkey patch and add a method =)
<repo> meh
<FromGitter> <stronny> why?
<repo> because that will make the method available everywhere else
<FromGitter> <stronny> well I'm sorry
<repo> don't be :)
<FromGitter> <stronny> Crystal doesn't implement a precise ACL on who can call what
<FromGitter> <stronny> you may try to use a module
<repo> in what way?
<FromGitter> <stronny> let me cook up an example
<FromGitter> <stronny> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e945dee6823cb38acca9470]
<FromGitter> <stronny> private module should only be visible from this same file
<repo> yeah
<repo> ah
<repo> but wouldn't including it make it included in all other parts of the code?
<FromGitter> <Blacksmoke16> whats the actual use case/
<FromGitter> <Blacksmoke16> ?
<repo> setting the primary key of a record after inserting
<repo> (yeah i'm giving writing my own orm a shot)
<FromGitter> <Blacksmoke16> how do you insert it? `#save` or a repo approach of like `Model.insert`?
<repo> repo approach
<FromGitter> <Blacksmoke16> `Repo.insert`*
<repo> which is why it's tricky
<FromGitter> <Blacksmoke16> make a setter but `# :nodoc:` it?
<repo> yeah
<FromGitter> <Blacksmoke16> or make it protected
<repo> hm?
<FromGitter> <Blacksmoke16> then you would be able to call it from within your ORM's namespace
<FromGitter> <Blacksmoke16> but not the outside
<repo> i could?
<repo> thought only inheriting classes
<FromGitter> <Blacksmoke16> mmm
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/8vqd
<FromGitter> <Blacksmoke16> but would only work if the model is defined in your ORM's namespace :/ so meh
<repo> ic
<FromGitter> <stronny> what's the access model here? what code should be able to do something special?
<repo> another thing: how do i define the type NamedTuple without any members?
<FromGitter> <Blacksmoke16> named tuple?
<repo> crystal doesn't like this
<repo> obv resulting from a macro expansion
<repo> ah
<repo> probably missing begin end
<repo> hm no
<FromGitter> <Blacksmoke16> `NamedTuple.new`?
<repo> the type
<FromGitter> <stronny> `T = typeof(NamedTuple.new)`
<repo> heh
<repo> probably i don't need the type. trying with the instance
<FromGitter> <Blacksmoke16> whats the NT for anyway?
masterdonx2 has joined #crystal-lang
MasterdonX has quit [Ping timeout: 264 seconds]
<FromGitter> <ondreian> @stronny good thought on `tcpdump` I can see that there is a tcp response, but for some reason `socket.gets` is still hanging. ⏎ ⏎ I did a `sock.peek # => Bytes[65, 9, 9, 80, 65, 83, 83, 87, 79, 82, 68, 10]` and as you can see it's sending `10` or `\n` so it really should have flushed to to the `socket.gets` call
<FromGitter> <stronny> a shot in the dark here: try to get rid of explicit set ascii encoding
<FromGitter> <stronny> default utf8 is ascii compatible anyway
<FromGitter> <ondreian> huh, that did it
<FromGitter> <stronny> file a bug
alexherbo2 has quit [Read error: Connection reset by peer]
sagax has quit [Ping timeout: 258 seconds]
alexherbo2 has joined #crystal-lang
<FromGitter> <asterite> @ondreian is `sync?` true? did you flush?
<travis-ci> crystal-lang/crystal#b6e157b (master - Merge pull request #9026 from straight-shoota/fix/tls): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/674417839
travis-ci has joined #crystal-lang
travis-ci has left #crystal-lang [#crystal-lang]
<FromGitter> <stronny> he's reading, not writing
<FromGitter> <asterite> he's writing in one part, reading in the other
<FromGitter> <stronny> he's seeing bytes in the socket buffer already
<FromGitter> <asterite> and I believe the reading depends on the writing to have gone through
<FromGitter> <stronny> the problem is `gets` doesn't recognize the delimiter somehow
<FromGitter> <stronny> > I did a sock.peek # => Bytes[65, 9, 9, 80, 65, 83, 83, 87, 79, 82, 68, 10] and as you can see it's sending 10 or \n so it really should have flushed to to the socket.gets call
<FromGitter> <ondreian> I just created a much smaller repro in a pure crystal echo server on localhost only which I ran by `cat reproduce_issue.cr | crystal eval`with the same result: https://play.crystal-lang.org/#/r/8vqs
<FromGitter> <stronny> you can just `crystal reproduce_issue.cr` dude, no need for eval
<FromGitter> <ondreian> oh, nice pro-tip.
<FromGitter> <Blacksmoke16> (is a shortcut to `crystal run reproduce_issue.cr`
<FromGitter> <stronny> `#!/usr/bin/env crystal` in shebang works like acharm btw
<FromGitter> <ondreian> I haven't played with crystal since like 18.x.x release, so I've still got a lot of catching up to do on all the newer things. appreciate the tips
<FromGitter> <stronny> anytime
<FromGitter> <asterite> oh, there's encoding "ascii"...
<FromGitter> <asterite> what's that for?
<FromGitter> <asterite> not that it shouldn't work, but maybe that's not needed?
<FromGitter> <stronny> the only reason I can think of is to raise on any char > 127
<FromGitter> <ondreian> It's a very old service, early 1990's in fact, and I was initially just doing it to be safe as @stronny said, i'd prefer an explicit error if I'm doing something wrong somewhere versus silently just writing to the socket
<FromGitter> <ondreian> unless I explicitly `write_byte` somewhere
<FromGitter> <ondreian> mostly just was creating a finite problem around a real world service to see how far crystal had come since i last evaluated it.
<FromGitter> <asterite> Yeah, seems to be a bug. Please report it. That code to reproduce it is perfect πŸ‘
<FromGitter> <asterite> commenting that it works... and all specs still pass. So I don't know what effectively happens if we remove that. Maybe it was written before the next checks were written
<FromGitter> <asterite> Yeah... that seems to be the case
<FromGitter> <ondreian> I opened an issue here: https://github.com/crystal-lang/crystal/issues/9056 for it
deavmi has quit [Quit: Eish! Load shedding.]
deavmi has joined #crystal-lang
_ht has quit [Remote host closed the connection]
_ht has joined #crystal-lang
<FromGitter> <asterite> Thank you!
gangstacat has quit [Quit: Ĝis!]
sagax has joined #crystal-lang
<hightower2> Hey wasn't there a setting on Fiber to control whether it can migrate between CPUs?
<FromGitter> <Blacksmoke16> are you looking to make it so it wont?
<hightower2> I'd be fine with migrating, just don't see an option which I thought I must enable
gangstacat has joined #crystal-lang
<FromGitter> <naqvis> you can specify if you want spawned fiber to run in same worker thread ⏎ ⏎ ```spawn same_thread: true do ......``` ⏎ ⏎ or else scheduler will be free to schedule on any thread (if you have enabled -Dpreview_mt flag) [https://gitter.im/crystal-lang/crystal?at=5e947f9038198d56a19c90a7]
<FromGitter> <Blacksmoke16> ^
claudiuinberlin has quit [Quit: Textual IRC Client: www.textualapp.com]
gangstacat has quit [Quit: Ĝis!]
gangstacat has joined #crystal-lang
<hightower2> ah that's where I remembered that there was an option for it
deavmi has quit [Quit: Eish! Load shedding.]
deavmi has joined #crystal-lang
DTZUZU2 has joined #crystal-lang
DTZUZU has quit [Ping timeout: 256 seconds]
postmodern has joined #crystal-lang
travis-ci has joined #crystal-lang
travis-ci has left #crystal-lang [#crystal-lang]
<travis-ci> crystal-lang/crystal#6c4f5f6 (master - Add Log#with_context (#9058)): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/674501591
mistergibson has joined #crystal-lang
darkstardevx has quit [Read error: Connection reset by peer]
mistergibson has quit [Client Quit]
<FromGitter> <lbarasti> Crystal 0.34 introduced exhaustive `case`, but the compiler still infers the type of the return value of the case statement to be `Int32 | Nil` in the following ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e94b83538198d56a19d5f2e]
<FromGitter> <Blacksmoke16> its just a warning atm
<FromGitter> <Blacksmoke16> is my understanding
<FromGitter> <lbarasti> I understand that the warning points out when a `when` clause might be missing
<FromGitter> <lbarasti> but we seem to be missing the point if we still have to go ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ in order to get the right type out of the expression [https://gitter.im/crystal-lang/crystal?at=5e94b8b25b98016d6a329579]
<jhass> the issue is changing this right now would have possibly broken existing code by changing types. https://github.com/crystal-lang/crystal/pull/9045 changes this behavior
<FromGitter> <stronny> Apologies, I don't understand the intention here. Why are you matching a constant?
<jhass> I guess it's just an example to illustrate the point
<FromGitter> <lbarasti> correct
<FromGitter> <lbarasti> Thanks @jhass, that's exactly the issue I was looking for
<FromGitter> <stronny> well then my complaint would be for compiler to understand that `Direction::Up` would never be `.down?` and warn about *that*
<FromGitter> <asterite> will never happen in real code
<FromGitter> <stronny> why does Crystal even allow `case`ing constants?
<FromGitter> <lbarasti> Just so I get this right, the switch from warning to compilation error is distinct from getting the above returning the best type
<FromGitter> <lbarasti> but the two are conflated in the same PR?
<jhass> mmh, I would say they're two aspects of turning this from a compiler warning into a semantic the language provides
<jhass> think of the warning as a notice that your code will be affected by the upcoming semantic change
<FromGitter> <lbarasti> πŸ‘
<FromGitter> <axetion> Hey, I'm trying to build a 32-bit shared object on a 64-bit system but I'm having some trouble with it... I have 32-bit versions of all the other libraries like pcre that would get linked in, but Crystal itself doesn't seem to have brought 32-bit versions of the static libraries like libgc.a and libcrystal.a with it, so it throws linker errors. Is there a good way to set this up?
<FromGitter> <stronny> I say docker
<jhass> libgc.a you should be able to to replace with your own or distro's 32bit build of bdw-gc
<jhass> doesn't need to be static, can be dynamic
<jhass> libcrystal.a you'll have to get a 32bit build yourself, the Makefile target is here https://github.com/crystal-lang/crystal/blob/master/Makefile#L102
<jhass> but yeah, bothering with 32bit in 2020 is interesting :D
<FromGitter> <axetion> Yeah, it's a rather strange usecase... I'll try seeing if I can build a 32-bit libcrystal from source then, thanks
<FromGitter> <stronny> I have an x86 vm still
<FromGitter> <stronny> too much hassle to reinstall, it works
darkstardevx has joined #crystal-lang
darkstardevx has quit [Remote host closed the connection]
darkstardevx has joined #crystal-lang
<oprypin> how can i write a file in utf-16 format without using iconv?
<FromGitter> <stronny> don't forget BOM
<oprypin> ye
<oprypin> `str = "cafΓ©"; slice = "\ufeff#{str}".to_utf16.to_slice; ???convert to Slice(UInt8)???; File.write("fn", slice)`
<oprypin> anyone help with the ???
<FromGitter> <stronny> `void*` lol
<FromGitter> <stronny> if you want to play it safe and orderly then I guess io.write_bytes with the corrent format
<jhass> Could kinda just Slice.new(slice.to_unsafe.as(UInt8*), slice.size * sizeof(UInt16)) but feels like there should be something nicer
<oprypin> yea
<oprypin> i feel like there should be as in, *should be*, not as in "probably is there"
<FromGitter> <axetion> Got it working. That was surprisingly easy (I guess I didn't realize there's not that much in libcrystal.a lol)
<FromGitter> <axetion> Thanks all
<jhass> maybe stdlib should package this into a Bytes.from_slice
<FromGitter> <stronny> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e94c1f116f84f0461768490]
<jhass> or maybe Slice should just have a to_io? idk
<oprypin> stronny, the funny thing is i dont care about endinanness
<FromGitter> <stronny> utf16 will make you care!
<FromGitter> <jwoertink> Does anyone else see `Exception Error writing to socket: Broken pipe (IO::Error)` often?
<oprypin> nono the way written there protects from it
<oprypin> the BOM also would get byteorder-flipped. thats its point
<FromGitter> <jwoertink> We get that error a lot, but since upgrading to 0.34 it's gone up 10x
<FromGitter> <stronny> okay then `io.write_bytes(u16, (rand > 0.5) ? IO::ByteFormat::LittleEndian : IO::ByteFormat::BigEndian)`
<oprypin> πŸ˜‚
<oprypin> thanks jhass. havent found anything better
<oprypin> well this is a bit better `slice = slice.to_unsafe.as(UInt8*).to_slice(slice.size * sizeof(UInt16))`
<jhass> heh, I guess
blassin has joined #crystal-lang
<jhass> but yeah I think I tripped over this in the past too, we should think about how Slice's that aren't Bytes should interact with IO
<oprypin> yes
blassin has quit [Client Quit]
<FromGitter> <stronny> yes
<FromGitter> <stronny> also what would help is an integrated binary format akin to JSON/YAML, so we could do my_class.to_bytes like we do .to_json
<FromGitter> <stronny> @jwoertink that's a bad case of underground hammering, please provide as much context as you could so we may have a chance to help you
<FromGitter> <stronny> > slice.size * sizeof(UInt16) ⏎ `slice.bytesize`
<oprypin> noice
<FromGitter> <alex-lairan> oprypin thanks for crsfml, I have fun right now :)
zorp has quit [Ping timeout: 264 seconds]
<FromGitter> <straight-shoota> jhass, oprypin: https://github.com/crystal-lang/crystal/pull/8852
_ht has quit [Remote host closed the connection]
deavmi has quit [Read error: Connection reset by peer]
<jhass> yeah, if it's just for UTF-16 I agree with the points there
deavmi has joined #crystal-lang
<jhass> can we generally say writing a Slice(Something) to an IO is nothing we should support?
<jhass> Seems like a sane container for marshalling a list of something to bytes
ur5us has joined #crystal-lang
acook has quit [Ping timeout: 250 seconds]
<oprypin> i thumbed that one down myself πŸ˜‚πŸ˜‚πŸ˜‚πŸ˜‚πŸ˜‚πŸ˜‚πŸ˜‚πŸ˜‚πŸ˜‚πŸ˜‚πŸ˜‚πŸ˜‚πŸ˜‚πŸ˜‚πŸ˜‚πŸ˜‚πŸ˜‚πŸ˜‚πŸ˜‚πŸ˜‚πŸ˜‚πŸ˜‚πŸ˜‚
<oprypin> like, when it was made. and now i need it
<oprypin> alex-lairan, :>
teardown has quit [Ping timeout: 256 seconds]
teardown has joined #crystal-lang
<FromGitter> <straight-shoota> > can we generally say writing a Slice(Something) to an IO is nothing we should support? ⏎ ⏎ I don't think there's a generic and portable way to do that. You'll need some kind of format
<FromGitter> <stronny> there is
<oprypin> straight-shoota, one could just pass the byteformat endianness
<FromGitter> <straight-shoota> I'm not talking about byte level format
<FromGitter> <stronny> maybe add `success?`
<FromGitter> <stronny> cool!
<oprypin> i'll make a PR when a dependent PR is merged (soon)
<FromGitter> <straight-shoota> The problem is more complex data types than numbers. In `Slice(T)`, `T` can be anything. How do you represent data structures, containers, pointers (?!) etc...
<oprypin> dont care if it's merged πŸ˜‚ i just had to do it
<FromGitter> <stronny> the same way you do with JSON, recursively, having something for scalar types
<FromGitter> <straight-shoota> Oh JSON is easy because it's text based and only understands a couple of data types.
<FromGitter> <stronny> you don't represent pointers
<FromGitter> <stronny> pointers lose their meaning as they leave the process
<FromGitter> <stronny> one way is to represent bytes they point to, another is to raise
<oprypin> i think we should support "Slice(Something) to an IO" when we support "Something to an IO"
<FromGitter> <straight-shoota> oprypin, yeah that should be feasible
<oprypin> which is trivially done by adding `def IO::write_stuff(stuff, format : IO::ByteFormat); stuff.each { |x| write_bytes(x, IO::ByteFormat::LittleEndian) }; end`
<oprypin> but probably can be optimized which could be even better
<FromGitter> <straight-shoota> not soo trivial...
<FromGitter> <stronny> there is a problem though
<FromGitter> <straight-shoota> what about size?
<FromGitter> <stronny> yes
<oprypin> wait, what *about* size
<FromGitter> <stronny> you have a `Slice(Slice(Int8))` and then you have [0, 0, 0, 0, 0]
<FromGitter> <stronny> is it [[0], [0, 0, 0], [0]] or something else?
<oprypin> stronny, no, dont support *that*
<oprypin> no recursion
<oprypin> that does `stuff.each { |x| x.to_io(self, format) }`
<oprypin> that will prevent recursion
<FromGitter> <stronny> so just `IO.write_slice`? :thinking_face:
<oprypin> yea
<FromGitter> <stronny> but your original wish was to just dump the bytes with no loops no conversions no nothing
<oprypin> ah, the optimization is rgiht there. if format == SystemEndian: see prior code sample
<oprypin> no idea tbh if everything fits together
<FromGitter> <stronny> needs an organic example
zorp has joined #crystal-lang
<FromGitter> <straight-shoota> You need a size not because of recursion but because you need to know the boundaries
<FromGitter> <stronny> you can write it yourself
<FromGitter> <stronny> there is of course no universal standard for this
<FromGitter> <stronny> sometimes there is no need to write it at all, like in this case (UTF16 file)
<FromGitter> <straight-shoota> > you can write it yourself ⏎ ⏎ Then I don't need a default serialization for slice at all
<FromGitter> <stronny> yes, we know that =)
<FromGitter> <straight-shoota> What's described here is serialization of a pointer sequence. But slice is poitner + size. If we can't serialize that, we don't to it halfway.
<FromGitter> <stronny> pointer + size = memory slice
<FromGitter> <stronny> it has fixed size in any case
travis-ci has joined #crystal-lang
travis-ci has left #crystal-lang [#crystal-lang]
<travis-ci> crystal-lang/crystal#9a9fc86 (master - Treat cookies which expire in this instant as expired (#9061)): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/674616815
<FromGitter> <stronny> I think the overarching point here is this: Crystal is not very helpful for dealing with binary data at the moment, do we-, and how do we make it better?
<FromGitter> <stronny> we all know there is no one generic solution that fits every hole, but we also know some holes are more common than the others
<FromGitter> <straight-shoota> I disagree. Crystal is really good at implementing binary data formats
<FromGitter> <straight-shoota> Just a few days ago I wrote an RCON client and it was really great to do: https://github.com/straight-shoota/rconcr
<FromGitter> <stronny> well, I'm interfacing with ssh-agent and I'm not entirely satisfied
<FromGitter> <stronny> I guess it's a matter of taste
<FromGitter> <straight-shoota> Maybe
<FromGitter> <straight-shoota> But when interfacing with specific protocols, you need to implement the protocol.
<FromGitter> <straight-shoota> Not a generic Crystal binary format
<FromGitter> <stronny> dumping a slice to io seems useful in any case
<oprypin> straight-shoota, can i suggest the name "NOCR"
<oprypin> "rconocr"
<oprypin> gosh the possibilities are endless
<oprypin> but this is not necessarily better, just silly