ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.33.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
<watzon> Haha that's awesome. Now you should try taking a Crystal project, building it using `--cross-compile --target "x86_64-unknown-linux-gnu"` and then try using zig to do the linking
ur5us has quit [Ping timeout: 246 seconds]
ur5us has joined #crystal-lang
_whitelogger has joined #crystal-lang
ur5us has quit [Ping timeout: 260 seconds]
_whitelogger has joined #crystal-lang
ua has quit [Ping timeout: 240 seconds]
ua has joined #crystal-lang
<watzon> Holy fuck. Zig actually make work to cross compile Crystal for other platforms.
<watzon> * Holy fuck. Zig actually may work to cross compile Crystal for other platforms.
<watzon> *may work
_ht has joined #crystal-lang
_ht has quit [Remote host closed the connection]
_ht has joined #crystal-lang
ur5us has joined #crystal-lang
<FromGitter> <confact> does it exist a way to extend an enum? I want to be able to add module or similar to it to handle DB stuff.
<FromGitter> <eddloschi> @watzon cross compiling crystal with zig didn’t work on my machine
<oprypin> stronny, uhh in some sense, probably. i'd be happy to figure out a solution if something currently doesnt work with dbus
ur5us has quit [Ping timeout: 260 seconds]
<FromGitter> <aamir-s18> Hallo everyone. I am trying to write a program in crystal and I've got an error which I am trying to fix it... I am getting this error ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e7b3111f778a11920b08286]
<FromGitter> <aamir-s18> And the function is looking like this. ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e7b3143e7ae032e73c687bd]
dannyAAM has joined #crystal-lang
<FromGitter> <oprypin> @aamir-s18 more minimal repro ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e7b352245c46b22fa3bd15c]
<FromGitter> <oprypin> if token might be nil, the program cannot work. you have to ensure that it's not nil, indeed
postmodern has quit [Quit: Leaving]
<FromGitter> <aamir-s18> @oprypin Thank you!
<FromGitter> <msa7> Hi. I have question about HTTP::Client.get, please reply here https://stackoverflow.com/questions/60847886/closed-stream-ioerror-with-httpclient-gethttps
defection has joined #crystal-lang
defection has left #crystal-lang [#crystal-lang]
<FromGitter> <fenicks> Hi guys. How can I avoid conversion when printing this kind of number? ⏎ ⏎ ```puts 0.0000584674565152 ⏎ # 5.84674565152e-5``` [https://gitter.im/crystal-lang/crystal?at=5e7b463851abce3ece0f08fc]
<FromGitter> <j8r> you can use `pp`
<FromGitter> <j8r> hum, `p!` sorry
<oprypin> msa7, uhh `puts "0.0000584674565152"`
<oprypin> sorry, meant for @fenicks
<FromGitter> <j8r> I don't think those are a solution, because it won't work if it is variable
<oprypin> `a = "0.0000584674565152"; puts a`
<oprypin> the other ones yes
<FromGitter> <j8r> oprypin, @fenicks probably has a variable which is a `Float64`
<FromGitter> <stronny> @oprypin dbus lib totally needs some love, currently it's not very usable at all at Crystal level. I mean `DBus` API, not `LibDBus`. But even the lib could use some improvements, for example shouldn't `connection_read_write_dispatch` have a `@[Raises]` anno?
<oprypin> stronny, yea looks appropriate to have that
<oprypin> tbh connection_read_write_dispatch is not usable because it's blocking
<FromGitter> <stronny> It's fine for my usecase
<FromGitter> <stronny> basically I need a custom dbus-monitor
<FromGitter> <stronny> what I miss the most is a way to deal with messages. You have some code in `Pending#reply` but it's not easy to use that generally
<oprypin> fenicks, anyhow, the number gets converted as soon as you write it out because it's stored in hexadecimal. then one needs to convert it back to decimal when printing
<Stephie> crystal seems to "just work" on LLVM 10 for once
<oprypin> fenicks, you can use this `printf("%.14f\n", 0.0000584674565152)` but it hardcodes the number of decimal places
<FromGitter> <stronny> would BigDecimal help?
<oprypin> and if u don't hardcode it, then it reaaaally dumps things `puts sprintf("%.50f", 0.0000584674565152).rstrip('0') #=> 0.00005846745651519999931351734279161291851778514683`
<oprypin> stronny, hm probably
<oprypin> very good idea. this works exactly. `require "big"; puts BigDecimal.new("0.0000584674565152")`
<oprypin> stronny, i think you want server functionality? i never got around to that :(
<oprypin> some of that functionality could indeed be logically derived from what's there currently
<oprypin> what this really needs is event loop integration and never using blocking calls
<oprypin> or hope for crystal threading support and hack with blocking calls anyway
<FromGitter> <stronny> would it be possible to convert dbus messages to/from Crystal classes like JSON/YAML?
<oprypin> stronny, i think so. but again, my thought process stopped just short of figuring that out
<oprypin> really wish i had finished that one ;p
<FromGitter> <stronny> yeah, I've figured that much
<FromGitter> <stronny> dbus is a huge project
<FromGitter> <j8r> oprypin or `printf "%.50f", 0.0000584674565152`?
<oprypin> stronny, one could generate a class (with a technique similar to json) that accepts only exactly these types and then is able to be converted to 1) an array like that and 2) a signature like that
<FromGitter> <confact> Say I have a module in a struct, like Type::Namespace. And I want to use a macro to run new on Type. but {{@type}} is returning Type::Namespace. Is it any way to solve that?
<FromGitter> <Blacksmoke16> do you need a macro?
<FromGitter> <Blacksmoke16> `new "foo"`?
<FromGitter> <Blacksmoke16> or really is that a problem? `{{@type}}.new`?
<FromGitter> <Blacksmoke16> oh, you want to have `@type` based on the type the module gets included in?
<FromGitter> <confact> yes :)
<FromGitter> <Blacksmoke16> ```macro included ⏎ your_macro ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5e7b55f151abce3ece0f3d0a]
<FromGitter> <Blacksmoke16> but im pretty sure initializers would just work, assuming you're not doing anything custosm?
<FromGitter> <confact> and how do I get the type? Or will it be `@type` then?
<FromGitter> <confact> I am doing highly custom. trying to extend enum to be able to use it in a ORM :)
<FromGitter> <Blacksmoke16> `@type` would represent the included type in that case
<FromGitter> <confact> nice, thanks. Got another issue now that it thinks the module is not defined. I guess as it is a struct and not initialized (as it is enum)
<FromGitter> <Blacksmoke16> oh?
<FromGitter> <confact> get this error now: ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ Any way for me to get the specific type of the enum? [https://gitter.im/crystal-lang/crystal?at=5e7b5861e7ae032e73c7150e]
Flipez has quit [Quit: The Lounge - https://thelounge.github.io]
Flipez has joined #crystal-lang
<FromGitter> <Blacksmoke16> ah right
<FromGitter> <Blacksmoke16> i ran into that before
<FromGitter> <Blacksmoke16> have to use an actual enum i think?
<FromGitter> <confact> I can gist my code. I am trying to add support for enum to Avram, without needing to use a wrapper around an enum.
<FromGitter> <stronny> do you need a Nil there?
<FromGitter> <Blacksmoke16> ^ that error is coming from `enum.cr` in stdlib
<FromGitter> <Blacksmoke16> could maybe try using `.from_value` and let it raise
<FromGitter> <Blacksmoke16> rescue/return nil
<FromGitter> <confact> i use `.from_value` - let me share the code :)
<FromGitter> <Blacksmoke16> and what is `{{@type}}` in this context? some actual enum?
<FromGitter> <Blacksmoke16> idt this would work if its not
<FromGitter> <stronny> why macro there?
<FromGitter> <stronny> wouldn't `include` do the job natively?
<FromGitter> <Blacksmoke16> oh try like
<FromGitter> <stronny> also `extend` class methods
<FromGitter> <Blacksmoke16> ```struct Enum ⏎ macro inherited ⏎ include AvramEnum ⏎ end ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5e7b5acc46214713a082b836]
<FromGitter> <Blacksmoke16> which would prob cause the methods to be added to the actual enum versus the parent type
<FromGitter> <stronny> I guess I'm missing something here, but my first guess would be to just patch `Enum` with no macros
<FromGitter> <confact> oh, cool! I don't get that error anymore. But I got the error that it can't access ColumnType constant in the module now. Am I doing something wrong you can see there?
<FromGitter> <Blacksmoke16> whats the error?
<FromGitter> <confact> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e7b5b8c0686790f6184270f]
<FromGitter> <confact> Type here is the actual Enum.
<FromGitter> <Blacksmoke16> try `User::Lucky::ColumType`
<FromGitter> <confact> this is inside the `db` lib, but i tried to change the type of the column: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e7b5c530686790f61842995]
<FromGitter> <Blacksmoke16> mm yea now we're into the lucky internals which im not familiar enough with
<FromGitter> <confact> I think if i just make it possible for it to get ColumnType from the module it should work fine. It seems it can't get into the module's constant in the actual Enum here.
<FromGitter> <confact> can it be because it is an `alias`?
<FromGitter> <Blacksmoke16> im not sure
<FromGitter> <confact> I think I know the issue. It is a bit of moment 22. I have to use inherited to get the actual enum to cast it correctly from DB. But for setting up the module, constant and such, it needs to be in Enum, as that is the "type".
<FromGitter> <confact> so both you @Blacksmoke16 and @stronny are right here.
<FromGitter> <confact> how would you do @stronny to cast the actual enum inside the enum?
<FromGitter> <Blacksmoke16> i think he means just do like
<FromGitter> <Blacksmoke16> ```struct Enum ⏎ def to_db... ⏎ end ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5e7b6076f778a11920b13077]
<FromGitter> <confact> Lucky is not built like that sadly.
<FromGitter> <Blacksmoke16> rip
<FromGitter> <asterite> @confact what are you trying to do?
<FromGitter> <stronny> ``````
<FromGitter> <stronny> ```code paste, see link``` ⏎ ⏎ would also work I think [https://gitter.im/crystal-lang/crystal?at=5e7b676e46214713a082e1fe]
<FromGitter> <confact> I am pretty sure this won't work. As I looked in the code. They want the methods to be self. Then the enum will be Enum and not the actual enum right?
<FromGitter> <confact> @asterite I am trying to instead of having a wrapper around enum, using the actual enum for the Lucky type you helped with yesterday i think. It would look much nicer that way. ⏎ ⏎ I came this far: https://gist.github.com/confact/9f2e9048935ce33196697f3393223910
<FromGitter> <confact> Problem with that gist is it can't access the constant ColumnType as it is only added on inherited.
<FromGitter> <confact> and `Avram::Type` in Lucky module is also doing an `macro included do extend self` which is used for Lucky to parse and stuff. So my code will probably not work.
<FromGitter> <confact> Tell me to re-explain if my babel make no sense :D
<FromGitter> <stronny> > They want the methods to be self. Then the enum will be Enum and not the actual enum right? ⏎ I'm unclear what you mean by that
<FromGitter> <stronny> I'm unclear what you mean by that
<FromGitter> <confact> sure, i will try to make it more clear. I am not hundred percent sure how macro with self/initialize work. But lucky want to call `.parse` on class, and not on instance of it. Not sure how Enum handle that. Will it call on the actual enum (say `enum Status`, will it call it on Status?) or will it call it on Enum, the struct?
<FromGitter> <stronny> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e7b6d58da0214537b056edf]
<FromGitter> <stronny> should print `Test`
<FromGitter> <stronny> with zero explicit macros
<FromGitter> <confact> I notice that `ColumnType` can only be accessed if it is moved to Enum struct directly, and not with macro. I guess it is because it has to be in the class? Then maybe my theory is correct. I don't know how I can cast an actual enum in the enum class though. Extended would not work as it is a struct.
<FromGitter> <confact> oh, okay. I think I understand. I will see what I can do.
<FromGitter> <stronny> `s/self.class/self/` and it works as expected
<FromGitter> <confact> @stronny tried extend. It can't find the ColumnType constant (alias) ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e7b709e51abce3ece0f9ff8]
<FromGitter> <confact> and if I use include instead: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e7b71269ee48969283475da]
<FromGitter> <stronny> include won't work
<FromGitter> <stronny> I mean you can do both at the same time
<FromGitter> <stronny> include for constants, extend for class methods
<FromGitter> <confact> I get from_value issue anyway. I guess it can not be done :)
<FromGitter> <stronny> drop `self.`
<FromGitter> <confact> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e7b7b79f778a11920b197a2]
<FromGitter> <fenicks> @j8r Effectively it is a variable.
<FromGitter> <asterite> if you get "undefined constant" it means the type doesn't exist
<FromGitter> <stronny> show how you define `from_value`
<FromGitter> <asterite> I know it's obvious, but if that's the error then macros, or anything else, are not the problem. The type is not defined
<FromGitter> <asterite> If you could reduce the code and show it without also including Lucky stuff, it'll be easier to help
<FromGitter> <fenicks> @oprypin @j8r it's a Float64. It's works with BigDecimal, thanks guys: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e7b848faf5fed77485fbe7e]
<FromGitter> <j8r> @fenicks you can just use `printf`
<FromGitter> <j8r> `p sprintf("%.8f", 0.0000584674565152) #=> 0.00005847`
<FromGitter> <naqvis> is it possible to define a new *primitive* type in crystal? `alias`ing is just a simple alias and any extension mades are applied to aliased built-in primitives.
<FromGitter> <confact> @asterite I tried to remove most of the Lucky stuff in https://gist.github.com/confact/27d62ee6ca27a47182bd1a665f9b6a3f so you can try it as well. ⏎ ⏎ create an enum call Role. and try to run `Role::Lucky.parse(value)`
<FromGitter> <fenicks> @j8r Nice, works well with `printf`et `sprintf`.
cyberarm has quit [Ping timeout: 240 seconds]
<oprypin> naqvis, i think it would basically be `struct`
<FromGitter> <naqvis> yeah, but how can we use it without instantiation? like those primitives works
<FromGitter> <naqvis> I understand behind the scenes primitives are struct, but for them compiler do the magic of instantiation as one needn't invoke `initialization`
<FromGitter> <naqvis> I hope someday crystal can allow types re-definitions (not just simple aliasing) like other languages. I don't know Ruby, but wish it was there in Ruby as every reference for new feature is looked at how things works in Ruby 😆
<oprypin> naqvis, no, structs actually are how it should be done. the inaccessible thing is just creating through literals
<oprypin> `record MyInt, foo: Int32`
<FromGitter> <naqvis> Yes, but my point was defining types which behaves like language primitives.
<FromGitter> <naqvis> one can define value types, but their invocation or usage doesn't follow the behavior of primitives
<FromGitter> <naqvis> `MyInt` though value type, but one can't use that like primitive type
<FromGitter> <naqvis> and need to invoke new to instantiate it
<oprypin> naqvis, no no hold on... you're basically saying that you want to add new syntax to the language on the fly
<oprypin> please explain what exactly you're missing and/or how it could hypothetically be done better
<FromGitter> <naqvis> ```alias MyInt = Int32 ⏎ a : MyInt = 0 # => works``` [https://gitter.im/crystal-lang/crystal?at=5e7b9d539ee489692835174c]
<oprypin> that's weakly typed, we dont do that here
<FromGitter> <Blacksmoke16> pretty sure it ends up just being `a : Int32 = 0`
<FromGitter> <Blacksmoke16> aliases are just replaced with their reference
<FromGitter> <naqvis> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e7b9dbcc8dae04d8fababfc]
<oprypin> yes, Blacksmoke16, but i think the point is that there is no mechanism that actually allows a different type to behave like that
<FromGitter> <naqvis> and this is what i was trying to convey in my initial post
<FromGitter> <Blacksmoke16> not without reopening `Int32`
<FromGitter> <naqvis> `alias` is just a rename
<oprypin> naqvis, so use struct
<FromGitter> <naqvis> 😆
<FromGitter> <naqvis> ```a = MyInt.new(0)```
<FromGitter> <naqvis> man that's ugly 😆
<oprypin> yes
<FromGitter> <naqvis> and that was my question and point in initial post :)
<oprypin> people end up doing `a = MyInt[0]` 😑
<FromGitter> <naqvis> yeah, i've done that in past,
<FromGitter> <drum445> How can I check if an object is an array?
<FromGitter> <Blacksmoke16> `obj.is_a? Array`?
<FromGitter> <naqvis> ```pp [1,2,3].is_a?(Array) # => true ⏎ pp 1.is_a?(Array) #= false ⏎ ``` [https://gitter.im/crystal-lang/crystal?at=5e7ba049fb1252280f499a5a]
<FromGitter> <naqvis> as @Blacksmoke16 said above, use `is_a?`
<FromGitter> <drum445> Legend, god bless
Human_G33k has joined #crystal-lang
<FromGitter> <asterite> @confact sorry, can you provide full code? That gist compiles file. If I add `Role::Lucky.parse` that doesn't work but that's okay because such method doesn't exist
<FromGitter> <asterite> Also maybe explain what are you trying to achieve. Including a module in all enums is a very bad smell
<FromGitter> <confact> I want that method to exists. ^^ ⏎ ⏎ I'm trying to make enum support to Avram without need to wrap it inside a class. So instead of status: enumwrapper.new(:opened) i would like to just do status: :opened. ⏎ ⏎ Types in avram add a lucky module to types structs to handle database type like to and from and parse it. [https://gitter.im/crystal-lang/crystal?at=5e7bacf0fb1252280f49bd42]
<FromGitter> <confact> @asterite ^
<FromGitter> <confact> I will add the model to the gist to understand the context. But it will be a bit avram in it.
<FromGitter> <confact> @asterite now you got everything except for avram shard and all that. the enum file i want to work to be able to get ColumnType and parse method.
travis-ci has joined #crystal-lang
travis-ci has left #crystal-lang [#crystal-lang]
<travis-ci> crystal-lang/crystal#e5bc86b (master - LLVM 10 support (#8940)): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/666932611
Human_G33k has quit [Remote host closed the connection]
Human_G33k has joined #crystal-lang
<FromGitter> <asterite> @confact There's no way to do what you can do. You can't `include` stuff into Enum, it's a current limitation. Also `macro inherited` won't trigger for Enum subclasses.
<FromGitter> <asterite> Please open feature request for at least doing `include` and `extend` for Enum, they should be pretty easy to implement
<FromGitter> <confact> Okay, thanks for checking @asterite. And sorry for bombing this chat. I'll open an issue for that!
renich has joined #crystal-lang
<FromGitter> <asterite> No problem! I'm actually implementing it already :-)
<FromGitter> <asterite> But only for `include` and `extend`. I think you had an `avram_enum` macro, so you could include the module there, no need to use `inherited` (which will not work anyway)
<FromGitter> <stronny> idk, extend works for me
<FromGitter> <asterite> You mean, `enum Foo; A; extend B; end` compiles fine for you? I get a syntax error
<FromGitter> <stronny> ah, no, I mean `struct Enum; extend A end`
<FromGitter> <asterite> Oh, yeah, that works. But I wouldn't do that, I wouldn't touch all enums
ur5us has joined #crystal-lang
masterdonx2 has joined #crystal-lang
MasterdonX has quit [Ping timeout: 250 seconds]
travis-ci has joined #crystal-lang
travis-ci has left #crystal-lang [#crystal-lang]
<travis-ci> crystal-lang/crystal#e200fce (master - Merge pull request #8935 from crystal-lang/bring-back-flush-on-newline): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/666973176
<DeBot> https://github.com/crystal-lang/crystal/pull/8935 (Add `IO::Buffered#flush_on_newline` back and set it to true for non-tty)
<FromGitter> <andrewc910> How would you all go about this? ORM in use is Jennifer. ⏎ ⏎ User: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e7bc94a03bc1d028516bfb3]
postmodern has joined #crystal-lang
<FromGitter> <andrewc910> The idea is users have many apps but apps have many users. I used a join table. I just need to find a way to query between apps & users in an efficient manner.
<FromGitter> <andrewc910> i wrote this but it will query the db way to much for large projects: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e7bc9ae08f131108fb2e473]
<FromGitter> <Blacksmoke16> wouldnt it just be select from mapping_table where user_id = user.id?
<FromGitter> <andrewc910> What do you mean?
<FromGitter> <Blacksmoke16> er nvm
<FromGitter> <Blacksmoke16> you could do this in one query i think, would be like has_many through?
<FromGitter> <andrewc910> through would solve my problem but idk if jennifer supports it :/
<FromGitter> <andrewc910> No it doesn't. That's why i am stuck
<FromGitter> <Blacksmoke16> it has `has_and_belongs_to_many` tho
<FromGitter> <Blacksmoke16> isnt that what you want?
<FromGitter> <andrewc910> I couldn't get it working :( Then i did some reading on rails (since there is more documentation & guides) and this method was recommended to avoid `has_and_belongs_to_many`. ⏎ ⏎ I will give `has_and_belongs_to_many` another go.
<FromGitter> <Blacksmoke16> oh really? welp
<FromGitter> <Blacksmoke16> either way seems you need has_many_through
<FromGitter> <andrewc910> Okay, i will play around some more! Thanks :)
<FromGitter> <Blacksmoke16> could always just lookup how that is done and do some raw SQL thing?
<FromGitter> <andrewc910> @Blacksmoke16 i actually got the `has_and_belongs_to_many` relation working & it's working how i needed. Was pretty this time around. Don't why i couldn't get it working a few hours ago. I thought about the sql route as i just spent the last 2 weeks studying it. Wanted to try the relations of the orm before i went down that route.
<FromGitter> <Blacksmoke16> xD
<FromGitter> <Blacksmoke16> good to hear
_ht has quit [Remote host closed the connection]