<FromGitter>
<HertzDevil> hah this book skips over untagged unions
<FromGitter>
<roduquen> Hey everyone, I have an issue at compilation and I don't get how to solve it, this is the error : ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ I am on it like for 3 hours I don't get at all what's my error, thanks by advance for any help [https://gitter.im/crystal-lang/crystal?at=6008c85bdfdbc1437fa07d09]
<FromGitter>
<Blacksmoke16> try doing like
<FromGitter>
<Blacksmoke16> `database_query.push(elem.merge({ "_id" => id } of String | Array(String)))`
<FromGitter>
<dukeraphaelng> ?Hey guys, do you know how to print the full stack trace during crystal spec --error-trace? When the stack trace is too long it only prints a part of it.
avane has joined #crystal-lang
<FromGitter>
<Blacksmoke16> using error-trace should print all that it has
<FromGitter>
<Blacksmoke16> is it not enough to find the issue?
<FromGitter>
<dukeraphaelng> nvm thanks! its just vscode being weird, the normal shell prints everything
<FromGitter>
<Blacksmoke16> 👍
<FromGitter>
<Dan-Do> > @Dan-Do arangocr doesn't look like it's been touched in a while. Is it really still in a good working condition? ⏎ ⏎ Sorry, I would have said that I use ArangoRb, of course with many monkey patches to convert ruby -> crystal :)
duane has quit [Ping timeout: 256 seconds]
duane has joined #crystal-lang
sagax has joined #crystal-lang
_ht has joined #crystal-lang
Stephie has quit [Quit: Fuck this shit, I'm out!]
Stephie has joined #crystal-lang
<FromGitter>
<rishavs> I so want to love arango (Specially foxx) but the dev experience on it has been so bad
<FromGitter>
<Blacksmoke16> is fully compile time type safe. I.e. wont compile if you typo a param name and/or try to inject a param of an invalid type
<frojnd>
@Blacksmoke16 Code example? of json file?
<FromGitter>
<Blacksmoke16> of the json and what you have so far yea
<frojnd>
How do I reference someone @gitter from irc?
<FromGitter>
<Blacksmoke16> just like that
<frojnd>
Ok
<FromGitter>
<Blacksmoke16> prefix their username with an `@`
<frojnd>
I'm playing in icr
<frojnd>
There I can require 'json'
<frojnd>
And also load a file
<frojnd>
Can i do it in carc?
<frojnd>
Load file
<FromGitter>
<Blacksmoke16> no, but could just make a HEREDOC with the contents
<FromGitter>
<Blacksmoke16> ogh, this json is meh. `verse_id` can either be a string or an array of strings? :/
<FromGitter>
<Blacksmoke16> why not just have an array of 1?
<frojnd>
Yeah... it can have also array
<frojnd>
Or just string
<frojnd>
But array always includes just strings
<frojnd>
Also if you notices it's more than just verse_id sometimes it's also verse_day, or smth else
<frojnd>
Like just verses
hightower2 has quit [Ping timeout: 264 seconds]
<FromGitter>
<phillvancejr> has anyone run into undefined symbols with C++ and Crystal? ⏎ ⏎ I've written a wrapper in C to a C++ class that uses c++'s fstream library to work with files. Interestingly I found that it works fine without fstream, however as soon as I try to use fstream I get undefined symbols for std::ofstream. ⏎ ⏎ I figured it was just a matter of passing the correct c++ linker flags, however even with
<FromGitter>
<asterite> I guess a gist or something that shows the files and what commands you run would be helpful. Crystal can't compile C++ code
<FromGitter>
<phillvancejr> I've precompiled the C++ files to object files, and Crystal is linking with normal C++ classes and even the iostream header code no problem its just fstream that is giving me problems. Here is my makefile ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=60099b63a2354e44ac9b48ef]
fifr[m] has quit [Quit: Bridge terminating on SIGTERM]
<FromGitter>
<asterite> I see. I know nothing about how to link against the c++ std, sorry. I do know that order passed to the linker matters, but I don't understand that either :-)
<FromGitter>
<phillvancejr> Thanks for trying :) it is very strange
<FromGitter>
<phillvancejr> The weirdest part is that the cc command Crystal uses on my system is clang and I can compile the same C++ file using clang with the same flags I'm passing to Crystal
<FromGitter>
<asterite> Oh. So to make things a bit more clearer, the `ldflags` that you specify there are passed when linking the Crystal program object files together with that `a` file.
<FromGitter>
<asterite> When you mean "can compile the same C++ file", what's that file?
<FromGitter>
<asterite> Maybe you need to also link against -lfstream
fifr[m] has joined #crystal-lang
<FromGitter>
<phillvancejr> You're probably right, it may be some linker flag. -lfstream doesn't work directly but this might be the right direction. The linked overflow answer says to use a C++ compiler but I don't think there is a way to make Crystal use clang++ instead of clang right?
<FromGitter>
<asterite> You can do `CC=clang++ crystal ...`
<FromGitter>
<andrewc910> An http response is written to the `io` of `HTTP::Server::Response` like: ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ Is there anyway to get just the body of a response after it's written? I can do this `io.to_s.split("\n").last` but it doesn't feel like the best solution. ... [https://gitter.im/crystal-lang/crystal?at=6009a823cf8b82773445bd4c]
<FromGitter>
<phillvancejr> Dang it still didn't work with CC=clang lol
hightower2 has joined #crystal-lang
<hightower2>
Blacksmoke16 just btw, where can one read what ART, ACF etc. stand for?
<FromGitter>
<Blacksmoke16> in the api docs, they just aliases for the components so there is less to type
<FromGitter>
<Blacksmoke16> i.e. `ACF = Athena::Config`, `ART = Athena::Routing`
<FromGitter>
<j8r> @andrewc910 What methods are you using?
<FromGitter>
<j8r> I tried `HTTP::Server::Response#output`
<FromGitter>
<jrei:matrix.org> @andrewc910: I see, you're making a kind of proxy
<oprypin>
@phillvancejr: compiler is irrelevant as part of Crystal invocation. everything should already have been compiler. and the linker (which is what crystal actually uses) doesn't care
<oprypin>
been compiled*
<FromGitter>
<j8r> @andrewc910 at least you can use `rpartition('\n')`, not sure how to improve it
<FromGitter>
<oprypin:matrix.org> hightower2, click on each tab at the top of https://athenaframework.org/Routing/ and the first thing on each page is the alias
<oprypin>
nice matrix caught up in 15min
<FromGitter>
<jrei:matrix.org> @andrewc910: what are you using exactly?
<FromGitter>
<jrei:matrix.org> I tried `HTTP::Server::Response.output.gets_to_end`
<FromGitter>
<oprypin:matrix.org> j8r (https://matrix.to/#/@jrei:matrix.org) looks like people on the other side are not seeing messages from Matrix at all 😂😂
<FromGitter>
<oprypin:matrix.org> it's borked
<FromGitter>
<oprypin:matrix.org> for over a day now
<FromGitter>
<jrei:matrix.org> true, damn
hightower2 has quit [Ping timeout: 256 seconds]
<FromGitter>
<jrei:matrix.org> ho, the matrix bridge sounds to work back... a bit
<FromGitter>
<andrewc910> I can get everything from the response except the body (unless i do something hacky). I have no problem ripping the body out of the io if i know it'll work. I don't think `io.to_s.split("\n").last` is the best solution. Would it be better to read the bytes? Is there a way to open up a class and add a helper method? I just can't figure out the best solution here :/
<FromGitter>
<Blacksmoke16> wouldnt that logic break if you did like `response << "foo\nbar"`?
<FromGitter>
<andrewc910> That's the gap between the http info at the top and the body at the bottom right? That's definitely one option. At the end of the day, i just want something that won't break 😢
<FromGitter>
<andrewc910> It's definitely better than splitting on \n lol
<FromGitter>
<Blacksmoke16> i thought this sounded familar
<FromGitter>
<Blacksmoke16> i use it in a spec context so not something that actually gets ran in prod
<FromGitter>
<andrewc910> I will give it a whirl..
<FromGitter>
<Blacksmoke16> basically it adds a dedicated io to also write the content to and exposes it
<FromGitter>
<Blacksmoke16> versus trying to parse the whole HTTP response
<FromGitter>
<andrewc910> Yeah i like that better than doing some string manipulation. I don't particularly like monkey patching but this does feel a bit better than string spliting.
<FromGitter>
<phillvancejr> @asterite @oprypin:matrix.org lol, would you believe that the problem was that I just forgot to compile my CPP.o files with the correct c++ std....
<oprypin>
@phillvancejr: yes there's nothing to prevent that then, c++ destructors are unique across all programming languages basically. you need to translate it into a different idiom, which is blocks. crystal blocks are closer to c++ destructors than Crystal destructors
<FromGitter>
<phillvancejr> Ok interesting. How would I do it with a block? Using ensure?
<oprypin>
@phillvancejr: bind the destructor as a call of its own, make a function that creates an object, yields it, then calls the destructor
<oprypin>
that's not always appropriate if the object needs to have a longer lifetime
<oprypin>
in that case there's no choice but to require an explicit destroy call from the end user
<oprypin>
think of File.closr
<oprypin>
e*
<FromGitter>
<phillvancejr> I see, interesting ok thanks that makes sense~
<FromGitter>
<asterite> Even `GC.collect` is not reliable because some things might be reachable from the stack. If you do `thing = nil` but that was a union type, it might be the case that the memory address of the object is still in the stack (this could be fixed later on, though)
<FromGitter>
<HertzDevil> crystal only uses boehm gc's c api, not the c++ api, so crystal never calls c++ destructors "natively"
f1reflyylmao is now known as f1refld
f1refld is now known as f1refly
HumanG33k has joined #crystal-lang
HumanG33k has quit [Remote host closed the connection]
HumanG33k has joined #crystal-lang
hightower2 has joined #crystal-lang
postmodern has joined #crystal-lang
<_ht>
While testing, it is convenient to declare some constants like MESSAGE to use throughout the test class. However, when I want to use the same constant name in another test file, I run into the issue that both contants are in the same scope.
<_ht>
Should I put each test in a separate module?
<_ht>
What are your suggestions?
<_ht>
Of course, I can define these constants in a separate test helper file or so, but I would like to keep the definition and use of these constants close together. Plus, in one test file, it might make sense to use a different value for a constant than in another
<FromGitter>
<Blacksmoke16> have you considered not using a constant
<FromGitter>
<Blacksmoke16> but a method that returns some default, but optionally can return what is passed to it
<_ht>
Ah, yes, that could work as well.
<_ht>
But I would not like to type the argument to this method over and over. Code duplication and all
<FromGitter>
<Blacksmoke16> i said optionally, i.e.
<hightower2>
(the first is error without error-trace, which reports the snippet that's not the actual error. And the second below is with error-trace, where it is visible that the error location really is)
<hightower2>
Is this something that could be improved or it is what it is?
<FromGitter>
<asterite> I don't understand. The two errors are the same, except the first one contains more frames?
<FromGitter>
<asterite> But yes, hiding frames was the wrong thing to do. I'd like to revert that but others don't want to, so 🤷
<hightower2>
Yes, but I would think that the first error should have displayed that frame in the middle.
<FromGitter>
<asterite> Oh, the compiler has no way to know which frame is the one you made the mistake in
<FromGitter>
<asterite> that's why it should display all frames... otherwise it's pretty much a guess... a guess I find wrong more than half the times
postmodern_ has joined #crystal-lang
postmodern has quit [Ping timeout: 256 seconds]
<hightower2>
yeah probably depends on the use case.. I do find it OK in general, except for specifically this type of cases where I go to convert a variable from one type to another, program-wide.
<FromGitter>
<jrei:matrix.org> why `p 'a' === 97 #=> true` but `p 'a' === "a" #=> false`?
<straight-shoota>
there's an actual discussion about this
<straight-shoota>
jrei: using triple equal sign for case equality operator is just a really bad decision
<straight-shoota>
because it looks like an equality operator, but it's not symmetric by design
<straight-shoota>
´==>´ would've probably been a better choice
<hightower2>
ok, how about... if this re. type comparison is going to stay as-is... can a command line switch be added which will just print a warning during compile when uncomparable types are compared? So a programmer can at least review them...
<hightower2>
I'm gonna check whether ameba catches this
<straight-shoota>
no and no
<straight-shoota>
there's nothing to catch
<straight-shoota>
it's not a code smell if you test for equality of different types
<hightower2>
Yes I mean I don't care about categorization... it doesn't necessarily have to be bad, after all that's why ameba can add exceptions
<straight-shoota>
there's nothing actionable for ameba, really
<straight-shoota>
there too many good reasons for having such equality tests to report it
<straight-shoota>
It might not be a bad idea to have a more strict and type safe equality operation, though
<hightower2>
Is this type of comparison allowed by the compiler as a special case, or it actually stems from any class being Comparable with any other class, even if no meaningful comparison is implemented?
<straight-shoota>
It's just ´Object#==(other)´ returns false
<straight-shoota>
or actually ´Value#==(other)´ and ´Reference#==(other)´
<straight-shoota>
and subtypes typically override ´#==(other : self)´
<hightower2>
ok it's not based on Comparable then, that's good since
<straight-shoota>
no, not related to Comparable
<hightower2>
ok so that great, I can at least override those 2 methods quickly and add a warning print for when I want to check.
<hightower2>
ok, thanks for the discussion
<straight-shoota>
definitely, you can do that
<straight-shoota>
it'll probably show you many cases where you wouldn't want any type restriction ;)
<hightower2>
sure, that's fine
<straight-shoota>
at some point I was also contemplating about == needing type safety
<straight-shoota>
but that's really not a practical problem
<FromGitter>
<Blacksmoke16> `<=>` will error if they aren't comparable
<hightower2>
yes, that's why I was surprised why this was going on
<straight-shoota>
yeah, but that's a different concept
<FromGitter>
<jrei:matrix.org> <=> is for inferior/superior/eqal
<hightower2>
straight-shoota, yes but you have to know the concept, and also you need to know on a class by class basis whether a Comparable or Value/Ref#== will actually end up being used.
<straight-shoota>
I don't follow
<straight-shoota>
what do you mean by the latter part?
<hightower2>
Maybe I'm missing something, I mean when I compare two values with ==, how do I know whether the implementation of == will come from them being Comparable, or they'll fallback to being compared with Val/Ref#== ?
<straight-shoota>
It's the same as with any method, the closes implementation is chosen
<straight-shoota>
*closest
<hightower2>
yes, that's what I mean. One must know on a class by class basis whether the == will end up comparing them through Comparable or Val/Ref==
<straight-shoota>
Why do you need to know that?
<hightower2>
because you just told me that there is no automated tool to tell me that, not even ameba
<hightower2>
So the only way is to know manually
<straight-shoota>
But *why* do you need to know that?
<hightower2>
because I just spent a lot of time figuring out why (something & something) != 0 was giving me true when it wasn't
<straight-shoota>
btw. many types define custom equality methods and don't use the defaults from Reference or Struct or so
<straight-shoota>
sry, I have no idea what you're talking about
<FromGitter>
<Blacksmoke16> fwiw `&` for enums prob means something diff than other somethings
<hightower2>
ok anyway, don't wanna monopolize the chat, it was a worthwile lesson in any case. I added a warning print to Value/Ref#== and caught some comparisons of Char to String which I didn't know where happening (and failing)
<FromGitter>
<Blacksmoke16> this is why you should write specs 😉
<FromGitter>
<Blacksmoke16> it was returning the `None` enum, which isnt the same as `0`
<FromGitter>
<Blacksmoke16> but `None.value == 0 # => true`
<straight-shoota>
> this is why you should write specs 😉
<straight-shoota>
exactly
<hightower2>
Blacksmoke16 yes that was my whole point... I didn't know that this was returning an enum type rather than an integer
<straight-shoota>
hightower2, okay I just see ne reason why you would need to know *how* an equality operator is implemented
<hightower2>
and the compiler didn't warn me
<straight-shoota>
The implementation should always make sense, if it doesn't, it needs to be fixed
hightower2 has quit [Read error: Connection reset by peer]
hightower2 has joined #crystal-lang
<hightower2>
I am reviewing the logs from a warning print in Value/Ref#==, and wondering whether this issue could have been solved by having == work only when coming from Comparable (and erroring otherwise), and having an operator similar but different than == which would be used when you don't want to prevent comparing uncomparable types (like all those cases listed in #2996 etc.)
<hightower2>
That operator could have been named =? for example. Like:
<hightower2>
"a" == 'a' ==> compile error (and the only sane thing to do, unless the user really makes these two types Comparable or defines a custom ==)
<hightower2>
"a" =? 'a' ==> false (the same what == currently does)
<straight-shoota>
yeah, type safe equality would be useful at times
<straight-shoota>
in fact, I've been preparing an RFC on that topic
<oprypin>
please do it as `====` operator
<straight-shoota>
good idea :+1:
<straight-shoota>
I've seen use cases mostly for specs, though
<straight-shoota>
like when I want to ensure an array contains only Int32 values, I can't use ´Array#==´ for that
<straight-shoota>
I also need to check the type of each value (or the Array's generic type argument)
<straight-shoota>
oprypin, next cool thing is `==^==` operator btw. :D
<straight-shoota>
not sure about the semantics, but it looks cool
<FromGitter>
<asterite> It would be nice if equality was type safe. Someone can try it and see how hard it is to make the std specs pass with that change, and how the code changes.
aquijoule_ has quit [Remote host closed the connection]