<FromGitter>
<bew> watzon: This is a port of the Go version to Crystal: https://carc.in/#/r/2kgw (disclamer: I have no idea what I'm doing)
<watzon>
I love the disclaimer lol. Thanks bew
rohitpaulk has joined #crystal-lang
<FromGitter>
<rufusroflpunch> is there a way to assign a splat argument to an instance variable? I would think that the compiler could infer the type since a splat creates a tuple, but it doesn't seem to
rohitpaulk has quit [Ping timeout: 248 seconds]
<FromGitter>
<rufusroflpunch> if there isn't a way, is there some way I'm missing for a method to receive a tuple via a splat and store it for later use in a different method
<FromGitter>
<rufusroflpunch> this yields the long "can't infer the type of instance variable" message
<FromGitter>
<rufusroflpunch> but it seems to me, since tuple are always known at compile time, that the compiler should be able to infer the type of the instance variable
<FromGitter>
<mgarciaisaia> @rufusroflpunch I don't think it has to do with the splat, but with the fact that instance variables type's *have to* be explicitely declared
<FromGitter>
<rufusroflpunch> @mgarciaisaia but that doesn't seem to be true. there are times when the compiler can infer the type (such as assigning an undeclared literal to an instance variable)
<FromGitter>
<rufusroflpunch> sorry, I meant to say: (such as assigning a literal to an undeclared instance variable)
<FromGitter>
<mgarciaisaia> Have you seen the full error message? It states the ~8 cases by which you can declare the type
<FromGitter>
<mgarciaisaia> Your example would work if you [could?] declare the type of `args` in the method's signature
<FromGitter>
<mgarciaisaia> I'm not even sure if that's doable with splats, but if you could do something like `def method(*args : Tuple(Int, String, MyThing))`, then it should compile I think
<FromGitter>
<rufusroflpunch> yeah, I've seen it. I'm just curious about two points: 1) Why is this a case where the compiler can't determine the type for inference? Since a splat creates a tuple, it must, by definition, be known at compile time, so I would think that inference would be possible. 2) If I can't save a splat to an instance, is there some other way to capture that as state for later use?
<FromGitter>
<mgarciaisaia> The underlying issue is that instance variables can change it's assignment at any point in time (your code could switch to a different fiber - let alone whenever we got concurrency working) so you need to specify and restrict its - if not, compile times were sooooooooooooo high
<FromGitter>
<mgarciaisaia> There was a time in which Crystal didn't have this restriction (your code would have worked in, I don't know, Crystal 0.16? 0.18? don't recall), but adding it really simplified lots of stuff
<FromGitter>
<rufusroflpunch> hrm
<FromGitter>
<mgarciaisaia> I wasn't *that into* the team at that time, but I recall hearing some of the discussions about this
<FromGitter>
<codenoid> please somebody make mongo driver for crystal
<FromGitter>
<rufusroflpunch> I would guess a mongo driver is no small task. the code for that driver alone looks fairly gnarly
<FromGitter>
<rufusroflpunch> @mgarciaisaia thanks for that link. I actually remember that post now
<FromGitter>
<rufusroflpunch> sort of ruins of my plans. lol. guess I'll need to be rethinking some things
_whitelogger has joined #crystal-lang
<FromGitter>
<fridgerator> @codenoid mongo.cr was just updated 19 days ago
_whitelogger has joined #crystal-lang
_whitelogger has joined #crystal-lang
_whitelogger has joined #crystal-lang
alex`` has joined #crystal-lang
<FromGitter>
<fridgerator> the array is zero indexed, the first object is at `array[0]`
<FromGitter>
<fridgerator> the last one is at `array[array.size -1]`, or just `array[-1]`
Philpax_ has joined #crystal-lang
Philpax has quit [Ping timeout: 240 seconds]
fenicks has quit [Quit: Leaving.]
fenicks has joined #crystal-lang
fenicks has quit [Ping timeout: 255 seconds]
<FromGitter>
<cevarief> @fridgerator Why the output is different between 4,0 and 5,0. Both exceeds array.size - 1.
<FromGitter>
<danlucraft> @cevarief that's a good question! I looked at the docs https://crystal-lang.org/api/0.23.1/Array.html#%5B%5D%28start%3AInt%2Ccount%3AInt%29-instance-method and guessed that it was because you can do array[4, -1] to count backwards from the end.... however the source code shows that this method doesn't accept negative arguments
<FromGitter>
<danlucraft> @cevarief I deleted a message that was about me misreading the docs doh
<FromGitter>
<danlucraft> it's a good question!
<FromGitter>
<danlucraft> This is the same behaviour as Ruby.
<FromGitter>
<danlucraft> But array[5] being Index out of bounds is NOT the same behaviour as Ruby
DTZUZO has quit [Ping timeout: 240 seconds]
<FromGitter>
<cevarief> @danlucraft Yes, either it’s a bug or it’s on purpose. We don’t know yet why 😄
<vegai>
because initializing from a Float is probably an intuitive thing to do
<hightower3>
Hey, if I have an abstract class with the implementation of method x(), and then I subclass that class, I see I can't call "super". How do I make it so that both the default implementation from the abstract class and my own custom addition gets executed then?
<vegai>
ah, found something. Crystal::Macros.#raise
<vegai>
which is trying to implement a BigDecimal type for arbitrary full precision decimals
<vegai>
I suppose it's a bit more than halfway done, but would be nice to hear if it's a dumb idea :)
<vegai>
btw, how can I make "make doc" generate docs for this library?
<FromGitter>
<bew> ``It's implemented as a layer on top of `BigRational`.`` why?
<RX14>
vegai, make a makefile which runs crystal doc?
<vegai>
RX14: there's already a "make doc" target, but somehow, docs for my lib is not generated by it
<RX14>
show me your makefile?
bmcginty has quit [Ping timeout: 240 seconds]
<FromGitter>
<bew> you should add your include in `src/big.cr` I think
<FromGitter>
<bew> because `src/docs_main.cr` requires this file to populate docs
<RX14>
vegai, oh wait are you modifing the compiler?
<vegai>
bew: seems logical, since gmp doesn't have a bigdecimal itself, I think. It could be a BigInt too, though -- that's how people usually implement it I think
<vegai>
RX14: no, just the std
<RX14>
yeah sorry thats what i meant
<RX14>
when you said "my lib"
<vegai>
ah, sorry for the confusion
<RX14>
it doesn't sound like you're modifying the stdlib
bmcginty has joined #crystal-lang
<vegai>
bew: yeah, that did it. Thanks.
<vegai>
if you're wondering about the motivation for this library, I'm mainly thinking about financial calculations
<vegai>
where the loss of precision of floats isn't tolerated, and where BigRational's API may be too clunky
alibby1 has joined #crystal-lang
<oprypin>
vegai, how does BigFloat not fit your needs?
<oprypin>
this inflexibility is the main downfall of this method, well other than being trivial
<oprypin>
i'd just remove it ¯\_(ツ)_/¯
<Papierkorb>
Yes, if it's replaced by a pure gsub(Hash | NamedTuple)
<oprypin>
but then you get the inflexibility of "to \b or not to \b"
<Papierkorb>
I'd expect that function to replace matches anywhere, not only at boundaries
<oprypin>
someone else would expect otherwise and get bitten
<Papierkorb>
Thank god for documentation
<FromGitter>
<bew> someone can try to write two backslash (not in inline code) from IRC?
<Papierkorb>
The functionality is fine, the function is improvable
<Papierkorb>
\\
<FromGitter>
<bew> do you see 2 or one in IRC?
<FromGitter>
<bew> I see one in gitter
<Papierkorb>
IRC should see two
<Papierkorb>
Wait a second \n bew, is this \n in a third \n actually fourth line?
<FromGitter>
<bew> no, oneline, with `\n` written
<FromGitter>
<bew> (so they're escaped)
<oprypin>
Papierkorb, it's just markdown getting rendered on gitter side
<Papierkorb>
So .. it just eats double \\ - Webapps are the future ~
<oprypin>
expected behavior, basically
<Papierkorb>
Why would you want to not print \\
<Papierkorb>
using some run-of-the-mill markdown.js lib is no excuse
<FromGitter>
<bew> yeah, who manager the IRC->Gitter bot?
<FromGitter>
<bew> manage*
<oprypin>
hi
<Papierkorb>
it makes sense *for this*, but backslashes?
<oprypin>
Papierkorb, it's just markdown, you can use \_ to write `_` then how do you write `\_`
<FromGitter>
<bew> would be nice to escape the backslashes, to properly see the ¯_(ツ)_/¯ :D
<oprypin>
it's not easy to escape markdown exactly the same as gitter expects it. not with standard library markdown parser.
<FromGitter>
<bew> hum..
<Papierkorb>
oprypin: I'd hope that their markdown parser is smart enough with _
<Papierkorb>
Everything else is just broken
<oprypin>
i don't see your point
<Papierkorb>
_this_ can be used this_should_not and neither in ¯\_(ツ)_/¯ - Aka, if there's no space before it or no word-char after it, it's not meant to underline
<oprypin>
so you mean to say that markdown in gitter is broken?
<oprypin>
well yeah, that's just another reason i'm afraid of trying to replicate the brokenness
<FromGitter>
<bew> ahah you broke gitter formatter: `not and neither in ¯\` is in italic
<Papierkorb>
if it doesn't work like that, then that's broken
<FromGitter>
<krypton97> sub is much faster than gsub
<vegai>
oprypin: BigFloat has the same loss of precision
<oprypin>
krypton97, so you're saying that doing one replacement is much faster than doing N replacements?
<FromGitter>
<bew> it replaces in the whole string
<FromGitter>
<krypton97> Ok, so I ran this one wrk -d 60 -t 20 -c 1015 http://127.0.0.1:3000/ and got the following output
<FromGitter>
<krypton97> accept: Too many open files (Errno) ⏎ 0x4130be: ??? at ?? ⏎ 0x4454fc: main at /home/alex/Documents/crystal-0.22.0-1/src/socket.cr 226:11 ⏎ 0x7f443d7f3671: __libc_start_main at ?? ⏎ 0x40e1fa: *start at ../sysdeps/x86*64/start.S 122:0 ... [https://gitter.im/crystal-lang/crystal?at=59996dceee5c9a4c5fdde845]
<FromGitter>
<krypton97> Does it mean that it can't handle that many users?
<oprypin>
hit the system limit for file descriptors?
<FromGitter>
<krypton97> Hm, I ran the benchmark with 1015 concurrent connection
<FromGitter>
<krypton97> that wouldnt be nice to happen in production
<oprypin>
how do we index all these irc answers in a search engine :(
<Papierkorb>
?handle-limit
<oprypin>
more like DedBot
<oprypin>
no but i mean a search engine
<oprypin>
forced stackoverflow posts?
<Papierkorb>
not at all. will find more false positives than anything useful
<Papierkorb>
if people knew what they're looking for, they wouldn't ask and just google it (well, most would)
<oprypin>
that doesn't work when there's almost never an answer in google
<oprypin>
maybe they do search for it and never find it and eventually give up
<Papierkorb>
what? on file handles? There are billions, five of which are actually good
<FromGitter>
<bew> oprypin, you're asking about where/how do we store the knowledge-base around crystal?
<oprypin>
yes
<oprypin>
Papierkorb, the person doesn't know that this is not crystal-specific, and the person knows that searching crystal-specific stuff doesnt work, so your argument doesnt work
rohitpaulk has quit [Ping timeout: 248 seconds]
<FromGitter>
<bew> ok, wasn't sure. No idea though, SO answers would be best I think, but it means we'll need to write & answer a lot of questions before people will start using SO I think (I have no idea actually)
<Papierkorb>
But it's a non-issue. IRC is there to answer questions, many of which are similar. building a bot which knows whats up with a really good hit rate is hard to get right.
<Papierkorb>
Or rather, it has been a non-issue in my decade of IRC usage
<Papierkorb>
That's why a simple `?` command is so helpful to guide people
<Papierkorb>
Or whatever it's called
rohitpaulk has joined #crystal-lang
<FromGitter>
<codenoid> thanks ^^ @oprypin @bew
<FromGitter>
<codenoid> is `.fetch(s)` used for check *is value available on LIB * ?
<FromGitter>
<bararchy> It's interesting how many programmers don't recognize and know how to solve the `Too many open files` issue, unles Crystal is your first lang ofc :) or if you never made a server before Crystal ?
<FromGitter>
<bew> Maybe it's because in Crystal everything 'looks' easy, you try bigger things than you're used too?
<FromGitter>
<bararchy> IDK, it's really interesting, the first I hit the `too many open files` issue was when trying to convert a C# to work on MONO with Linux, the main programmer was not a Linux user and never used Linux before, so when we hit it I was like, maybe it's a mono issue ? and then started digging
<FromGitter>
<bararchy> I have to say that if we can add `Too many open files (could be Sockets and other file type devices)` it could maybe help people avoid confusion ?
<FromGitter>
<bararchy> Or something even more verbose ?
<FromGitter>
<krypton97> just got this issue now lol
<oprypin>
krypton97, that's the only reason why we're talking about it
<oprypin>
bararchy, that does not change anything, people will still think it's about crystal
<FromGitter>
<krypton97> take a look on rust, I find it much harder even than c
<FromGitter>
<bararchy> Hm... Maybe `(Check you operating system limits for maximum files)`
<FromGitter>
<krypton97> I know, saw this issue on github
<FromGitter>
<krypton97> and a solution as well
<FromGitter>
<bew> @bararchy @oprypin: thoses errors are `Errno` exception, and usually Errno errors are not crystal's, so we could add a prefix message saying that it's a system error, or sth?
<FromGitter>
<bew> (not a crystal error)
<FromGitter>
<bararchy> Good idea
<oprypin>
errno should not be a thing in the first place and no, it being a system error does not necessarily mean it's something wrong with the system
<FromGitter>
<bew> yeah I know, but it can help redirect users I think
<FromGitter>
<bew> (need better phrasing of course)
<FromGitter>
<bew> @codenoid We can't do anything about it I think, the person in charge of the shard will see your issue one day, and reply to you on it
<FromGitter>
<bararchy> I saw a ticket regarding removing the Errno completly right ?
<FromGitter>
<bararchy> what would be instead ?
<FromGitter>
<bararchy> a system specific error ?
<FromGitter>
<bararchy> Windows::Error....
<FromGitter>
<bararchy> Unix::Error
<FromGitter>
<bararchy> etc.. ?
<FromGitter>
<bararchy> Because that will also be good enough I guess
<watzon>
Works the same as homebrew, but is cross platform linux
<oprypin>
pls
<oprypin>
if you're on centos maybe you'd want that
<watzon>
Definitely makes installing some packages a little easier
<oprypin>
in my experience you use this when you are on a distro that you hate
<oprypin>
and i was in that situation once and did use it in fact but it's not very good
<FromGitter>
<bew> watzon which distro are you on?
<FromGitter>
<bararchy> pacman & yaourt is enough for me :)
<watzon>
Manjaro, so I won't be using it a ton because I have the beauty of pacman and AUR
<watzon>
But some AUR packages just don't get updated
<FromGitter>
<bew> the update them x)
<oprypin>
which packages, for example?
RelaxBox has joined #crystal-lang
<watzon>
No example right now. I've run into several though in the past
<watzon>
And sometimes I just don't feel like updating them
<watzon>
I have in the past though
office_boy has joined #crystal-lang
<FromGitter>
<krypton97> Knew about linuxbrew for a while but couldnt install it
<FromGitter>
<krypton97> Is it the same as homebrew?
<oprypin>
yes and no
<watzon>
Basically. It's a fork and I feel like they may use the same bottles
<watzon>
Not 100% sure on that one though
<oprypin>
yes, and at any time you're prone to run into some mac specific hack and package fails to install
<FromGitter>
<krypton97> oo, it worked
<office_boy>
How would one go about using spec to capture output from `put` and test it? Like for Ruby you could do something like: `expect(STDOUT).to receive(:puts).with("RSpec test")`
<office_boy>
`puts`*
<oprypin>
office_boy, there's no easy way. you can make your code more testable and universal by not assuming stdout
<office_boy>
Thanks a lot @oprypin, but what you said first does make more sense I guess
office_boy has quit [Remote host closed the connection]
office_boy has joined #crystal-lang
office_boy has quit [Read error: Connection reset by peer]
Groogy has joined #crystal-lang
<Groogy>
Morning!
<FromGitter>
<bew> 3p.m. morning! ;)
<Groogy>
heh yeah, my day-rythm is super weird since my vacation
office_boy has joined #crystal-lang
<FromGitter>
<bew> ahah have a good breakfast then!
office_boy has quit []
<FromGitter>
<bararchy> @codenoid , I know I'm not the first to tell you, if you want people to try and help, you need to give more info then this :\ ⏎ What code produced this ? what allocations are you doing ? are there small loops that use those allocations ?
<FromGitter>
<bararchy> etc..
fenicks has joined #crystal-lang
<FromGitter>
<bew> is it possible to make a fiber that waits for a started process to finish without blocking other fibers?
<Groogy>
well after everytime you check you yield?
<Groogy>
though it depends on that other fibers also yield
<FromGitter>
<bew> they do, but I think this will check a lot per second, I'd like to be kinda notified that the process closed
<Groogy>
so depending on workload of the other fibers you might be checking once a second, or even more less
<FromGitter>
<bew> yeah I know, the thing is, I have 1 other fiber that does work every second
<FromGitter>
<bew> and currently I check after the passed second if the process is still alive
<FromGitter>
<bew> and if it's not, exit
<Papierkorb>
Does that other fiber take 1s to compute though?
<FromGitter>
<bew> no, it tkes a few ms
<Papierkorb>
Then you shouldn't notice, especially not in a release build
<Papierkorb>
debug builds are noticably slower when many fibers and channels are involved
<Groogy>
the slowest part is probably gonna be the kernel call itself :D
<FromGitter>
<bew> when I said "without blocking other fibers", I meant "without blocking the main tread" (like when I use `process.wait` inside that fiber)
<Papierkorb>
... that blocks the thread?
<FromGitter>
<bew> huh wait a minute, I may have messed up sth else
<oprypin>
its not supposed to block just use process.wait
<FromGitter>
<sdogruyol> As many others like parallel
<FromGitter>
<sdogruyol> :)
<Papierkorb>
oprypin: Channels doc is just "meh", concurrent::future doesn't even appear in the docs
<FromGitter>
<bew> nvm, I've found my issue, I was doing input stuff into the other fiber, and noticed that `Process#wait` closes that io, so it's logic it wasn't working ><
<FromGitter>
<bew> I love how crystal is readable: `until lemon.terminated?; sleep 0.1; end`
<Groogy>
^^
<Groogy>
When I get boleite to a more usable case I'll be going through to make shit more readable
<Groogy>
Though I do love I can just read the compiler code
<Groogy>
there's no overuse of dumb macros or weird conventions like redefining enums for the sake of defining enums
<FromGitter>
<bew> yeah it's awesome
<Groogy>
(i.e in FreeImage library, there is literally a FI_ENUM define)
<Groogy>
FI_ENUM(SomeEnum) => enum SomeEnum
<FromGitter>
<bew> when you need to get your code more readable, I'd love to help. Readability (and modularity) is (maybe too much) king to me, and I like to transform code to my quality standard, it's a very rewarding process
<FromGitter>
<bew> Groogy ^
<Groogy>
^^ thanks
John__ has joined #crystal-lang
RelaxBox has quit [Ping timeout: 240 seconds]
<crystal-gh>
[crystal] MakeNowJust opened pull request #4862: Remove unnecessary parenthesis from `Cast#to_s` result (master...fix/crystal/cast-to-s-unnecessary-paren) https://git.io/v5fUV
<FromGitter>
<krypton97> Has anyone worked with time package
<FromGitter>
<krypton97> I'm looking for a format pattern that could generate me the date as 20 Aug 2017
<Groogy>
gah how do I properly translate this into a good exception message (the exception also prints out the actual OpenGL enum name)
<Groogy>
"Given when the set of state for a command is not legal for the parameters given to that command. It is also given for commands where combinations of parameters define what the legal parameters are."
<FromGitter>
<bew> oO
<Groogy>
i.e it is let's say if you tell it this is a TEXTURE_2D in a parameter but what you actually gave it was a 3D texture
<oprypin>
what
<Groogy>
that's the description for GL_INVALID_OPERATION, and I need to turn that into something that fits into a short exception message
<Papierkorb>
`Invalid argument(s) given`
<Papierkorb>
that's super generic, but if it's all you know..
<Groogy>
no that's GL_INVALID_ENUM and GL_INVALID_VALUE
<Groogy>
GL_INVALID_OPERATION is more like invalid state
<Papierkorb>
Then just write that?
<Papierkorb>
"Invalid operation for state of object" or "The current state forbids this operation"
<FromGitter>
<bew> what is the syntax to re-raise an exception again?
<Groogy>
"when LibGL::INVALID_OPERATION; "A function called with invalid state or combination of parameters.""
<Groogy>
?
<FromGitter>
<bew> can't find it in doc nor in sources
<RX14>
just raise the exception you caught
<RX14>
...
<FromGitter>
<bew> oh, indeed ><
<FromGitter>
<bew> not mentioned in the docs though
<RX14>
because it's obvious?
<Groogy>
raising is in essence just "pushing an object up the stack to the next handler"
<Groogy>
in the simplest term
<RX14>
well more accurately it's searching up the stack for a handler
<Groogy>
though I think Crystal requires it to inherit from Exception?
<FromGitter>
<bew> yeah maybe, I vaguely remembered the PR for that, and only remembered there were multiple proposed syntax.. Perfect then
<RX14>
yes
<RX14>
thing is this isn't syntax
<FromGitter>
<bew> you're right, what is it then? grammar?
<RX14>
raise is a method
<Papierkorb>
It's nothing special in reality
<RX14>
the rescue ex : Foo is syntax
<Papierkorb>
But it should be mentioned, as it may indeed not be obvious to a newcomer
<RX14>
really? I guess literally all the languages i've used have done reraising that way
<RX14>
i don't think re-raising is anything special at all
<FromGitter>
<bew> it was in #4482, and multiple "grammar" were proposed (create new exception, and attach old trace, etc..).
<RX14>
I don't think of it as anything more than catching an exception then passing it to raise again
<Papierkorb>
RX14: in Ruby, it's just `raise` without any error
<Papierkorb>
any argument*
<RX14>
yeah well ruby's weird
<RX14>
and i'm pretty sure you can do it the other way
<Papierkorb>
that's the canonical way. The other way may (?) rewrite the backtrace.
<Papierkorb>
In C++, it's just `throw;` too
<RX14>
ruby
<Groogy>
well ruby saves the exception in $!
<Groogy>
so raise with nothing just reraises that exception
<Groogy>
or at least that was the deal back when I used Ruby
<Papierkorb>
So, no, it's not always "just throw the same thing again"
<RX14>
i love ruby but i really don't think it's very sensible in some of the choices it made
<oprypin>
RX14, in Python `raise` means reraise the same exception, and also Python keeps the chain of exceptions that led up to this point, and so these have a different effect
<RX14>
i guess i'm the weird one
<Papierkorb>
RX14: I'm baffled how against you're adding a little note in the *learning material* to avoid confusion
<RX14>
i just din't think it was a big deal
<RX14>
clearly i'm wrong
<Papierkorb>
I mean, people may just try re-raising the same error but wonder if it's the right way. At least, that'd be me
<RX14>
it should be added to the docs if all those languages do it differently
<Groogy>
ugh renaming every single class in the framework xD
<FromGitter>
<kazzkiq> I'm trying to return a `Int32`out of a `db.scalar`, but it seems to only return boolean values.
<Groogy>
it had grown way bigger faster than I expected
<RX14>
well it's not a high priority: just use nil
<Groogy>
well if the result of a function is null it will not be nil
<Groogy>
it will be a Pointer(Void).null
<RX14>
i agree it should work as you say
<RX14>
but why do you need it
<Groogy>
no it would just make my code look prettier
<Groogy>
rather than doing Pointer(Void).null.as(Test::T)
<RX14>
why not use nil then
<RX14>
instead of null
<RX14>
use Test::T? and then assign nil in the finaliser
<Groogy>
because then I have to check both .nil? and .null?
<RX14>
why
<RX14>
why would it become null
<Groogy>
if a function returns null?
<FromGitter>
<bew> Groogy a little prettier can be written as `nil.as(Test::T)`
<RX14>
when would it return null
<RX14>
and in that situation you'd always want to raise
<Groogy>
a lib function
<Groogy>
in C
<Groogy>
returning null
<RX14>
but you wouldn't do that
<RX14>
in your example
<Groogy>
no in my example it's a case of making sure subsystems shut down in correct order
<RX14>
you'd never want a wrapper for a C object to contain a null reference
<Groogy>
when the finalizer kicks in
<RX14>
no i understand your answer
<RX14>
and i'm saying
<RX14>
for that usecase nil does better than null
DeBot has joined #crystal-lang
<RX14>
and you should never assign a null pointer to @ptr
<Groogy>
well in my specific code where I am using this, it is a surface that needs to be destroyed before the entire subsystem destroys the native representation of the surface. So the ptr needs to be reset so it doesn't keep pointing at it. If that would be made a union of Nil and Ptr then I have to check for nil in everything while the native implementation understands a null pointer and will behave correctly
<Groogy>
to that
<RX14>
but in your example you check for nil
<RX14>
also if you're saying that the "native implementation understands a null pointer"
<RX14>
you can just pass the ivar and nill will become null
<RX14>
which it understands
<Groogy>
no I can't
<Groogy>
because of fun definition not taking a nil
<Groogy>
types don't let you pass it
<RX14>
no it takes a pointer
<Groogy>
eh the lib type
<RX14>
nil#to_unsafe is null
<RX14>
which is where we started
<Groogy>
yes but type doesn't care :P
<RX14>
it works
<Groogy>
the type keyword
<RX14>
but we've established that nil is converted proeprly
<Groogy>
it doesn't take a union
<Groogy>
because the type doesn't respond to #to_unsafe
<RX14>
but the union will be converted into the pointer, surely
<Groogy>
no
<Groogy>
it is a pointer
<RX14>
Pointer#to_unsafe -> self
<Groogy>
and a nil
<RX14>
Nil#to_unsafe -> null
<RX14>
have you tried it?
<Groogy>
just tested it
<Groogy>
doesn't work
<Groogy>
argument 'window' of 'LibGLFW3#destroyWindow' must be LibGLFW3::Window, not (LibGLFW3::Window | Nil)
<Groogy>
should say "still doesn't work"
<RX14>
try calling to_unsafe manually
<FromGitter>
<bew> can you carc.in your example?
<Groogy>
lfw_surface.cr:11: undefined method 'to_unsafe' for Nil (compile-time type is (LibGLFW3::Window | Nil))
<Groogy>
¯\(°_o)/¯
<RX14>
huh weird
<Groogy>
I've been through this before
<FromGitter>
<codenoid> mongo datanoise work fine with my vultr 16.04 0.23.1 :/
<Papierkorb>
Sometimes, it also forgets that `lib` structs have an #initialize setting all fields. Wasn't able to pinpoint it yet, it just disappears later.
<Groogy>
so guessing nil is just specially handled instead of creating a pointer? I guess since you would know the return type you would want
<FromGitter>
<bararchy> Oh, I thought select should be avoided at all cost because it blocks the event loop
<RX14>
no that's IO.select
<FromGitter>
<bararchy> Or was it IO.select ?
<RX14>
which was removed
<RX14>
by me
<FromGitter>
<bararchy> LOL , OK wasn't sure :)
<FromGitter>
<bararchy> So select != IO.select
<RX14>
yes
<RX14>
select case works using select actions
<RX14>
which are only implemented on channels so far
<RX14>
IO.select worked on IO::FileDescriptor
<RX14>
using the select syscall
<RX14>
which was legacy from before we had libevent, most likely
<FromGitter>
<bararchy> So , if I use a Chanel with Proc so that it will take each functions and call it inside a new Fiber , I can basically have a fully functional Timeout like mechanism
<oprypin>
bararchy, i told you once before about your misconception regarding `select`
<RX14>
@bararchy but you won't be able to create any sort of timeout because you won't be able to stop whatever you're doing after the timeout is up
<RX14>
so it'll just keep running even though it's not needed
<FromGitter>
<bararchy> oprypin , I remembered now , it was with @sdogruyol , I have such a nightmare from IO.select that it keeps coming like a PTSD haha
<FromGitter>
<bararchy> RX14 I see , well then , I guess I should avoid those kind of things and just set IO timeouts instead
<RX14>
if you're doing IO you use IO timeouts
<RX14>
if you'renot doing IO you can't use IO timeouts
<RX14>
i don't get what you'
<RX14>
re trying to achieve
<FromGitter>
<bararchy> I mean , I should plan my patterns around IO based timeouts (socket work) and not wrapping Timeout around functions that use IO inside
<FromGitter>
<bew> I want to prevent a specific field from appearing when doing `pp obj`, how do I do this?
<FromGitter>
<bew> I tried to look for the method used to pp a class, but couldn't find it
<RX14>
@bew pp uses the pretty printer
DTZUZU has joined #crystal-lang
<FromGitter>
<bew> where is the class instance pretty_printer?
<FromGitter>
<bew> it's not in class.cr
<RX14>
what?
<FromGitter>
<bew> oh nvm, it's in reference.cr
<RX14>
it'd never be in class.cr
<RX14>
that's for metaclass
<RX14>
the base impl is in object.cr
<RX14>
and then reference and struct probably override that
<FromGitter>
<bew> I've found it, thanks!
<Groogy>
need to do my dishes... but I wanna code more Crystal (¯ε¯ )
<FromGitter>
<bew> Crystal is addictive ^^
<crystal-gh>
[crystal] maxfierke opened pull request #4863: Don't mark ivar as nilable if super present and non-nilable (fix #4764) (master...mf-fix_issue_4764) https://git.io/v5f3u
<RX14>
is this a perfect PR from a first time contributor? That's awesome
<FromGitter>
<sdogruyol> I wonder if it's first time Crystaling
<FromGitter>
<danlucraft> @cevarief presumably array[too_big_index] is not nil like in Ruby because that would make the return value of [] a nullable type and it's more useful to have [] not ALWAYS return a nullable type
w-p has quit [Quit: Lost terminal]
<FromGitter>
<bararchy> How can I rand a charset between a..z ?
<oprypin>
bararchy, rand(a.ord, z.ord).chr
<oprypin>
>> rand('a'.ord, 'z'.ord).chr
<DeBot>
oprypin: wrong number of arguments for 'rand' (given 2, expected 0..1) - https://carc.in/#/r/2kkq
Groogy has quit [Read error: Connection reset by peer]
<FromGitter>
<bew> oh, I was going on `'a' + rand(26)`, but yours is better
Groogy has joined #crystal-lang
alex`` has quit [Quit: WeeChat 1.9]
<jokke>
would there be any noticable performance gain if the to_s method generated by the ecr macros did more sophisticated stuff like calculating the length of the strings that will be inserted into the template for then allocating a string of the exact length of the substituted template and overwriting the relevant bytes in the template string?
<jokke>
or would thet be something llvm would do anyways
<jokke>
*that
<oprypin>
no performance gain
<jokke>
ok
<jokke>
thought so
<jokke>
i havent looked into how String#+ is implemented
<FromGitter>
<bew> Is it possible to prevent a private member from being accessed when including the parent container? https://carc.in/#/r/2kl8
olbat has quit [Ping timeout: 264 seconds]
olbat has joined #crystal-lang
olbat has joined #crystal-lang
olbat has quit [Changing host]
<FromGitter>
<johnjansen> huh ... i think you are out of luck there @bew
<FromGitter>
<bew> Yeah that's what I think too.. although I'm not sure it's the behavior people are expecting
<FromGitter>
<johnjansen> its composition, and totally by design, otherwise there would be alot you couldnt achieve with composition ...
<FromGitter>
<johnjansen> you are effectively cutting and pasting the code when you do `include ModuleName`
<FromGitter>
<johnjansen> *effectively*
<FromGitter>
<bew> hum.. makes sense, thx
<Groogy>
yeah I have a couple of internal structures etc in Boleite
<Groogy>
I just put them inside another module called Private