<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.
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>
<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
<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
<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?
<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>
<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
<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]
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>
<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
<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
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
<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>
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> 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