jhass changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.28.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
alexherbo207831 is now known as alex```
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
<FromGitter> <watzon> Glad someone does lol. I sure don't.
alex```6 has joined #crystal-lang
alex``` has quit [Ping timeout: 258 seconds]
ashirase has quit [Ping timeout: 245 seconds]
ashirase has joined #crystal-lang
<FromGitter> <mwlang> Shouldn't this prevent entire module from appearing in documentation? ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ce605dd75d9a575a62b0eb1]
<FromGitter> <Blacksmoke16> yes
<FromGitter> <Blacksmoke16> sure you dont have it defined somewhere else as well?
<FromGitter> <mwlang> how so?
<FromGitter> <mwlang> like another file for it? If so, no.
<FromGitter> <Blacksmoke16> like a `module ToFilter; end`
<FromGitter> <mwlang> nope.
<FromGitter> <Blacksmoke16> hm
<FromGitter> <mwlang> I'll push the project code to github in a few mins.
<FromGitter> <mwlang> just trying to make first commit somewhat decent.
<FromGitter> <Blacksmoke16> im sure you do, i just tried
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ce6075a879f4478c7c6ed99]
<FromGitter> <Blacksmoke16> and Tar wasnt in the docs
<FromGitter> <Blacksmoke16> oh
<FromGitter> <Blacksmoke16> try deleting the docs dir and redo `crystal docs`
<FromGitter> <Blacksmoke16> i dont think it cleans up files that you add nodoc to that are no longer used
<FromGitter> <watzon> It usually cleans them, but it could have fucked up somewhere.
<FromGitter> <watzon> Are there any resources anywhere for including rust in a Crystal project? I imagine it's similar to how you'd do it with C++.
<FromGitter> <mwlang> That did it!
<FromGitter> <Blacksmoke16> πŸ‘
<FromGitter> <mwlang> well, the project has a ways to go, but it's beginning to take shape: https://github.com/mwlang/binance Comments, suggestions for improving definitely welcome
<FromGitter> <mwlang> esp. as this is my first Crystal OSS project and coming from a Ruby background.
<FromGitter> <mwlang> documentation is gonna take some work, but I'm definitely trying to organize the code around what will generate organized docs.
<FromGitter> <mwlang> so far, not entirely happy with that aspect of things, but imagine I just need to get some practice under my belt.
<FromGitter> <Blacksmoke16> https://github.com/mwlang/binance/blob/master/src/binance.cr wouldnt it make more sense for mose of these to be enums?
<FromGitter> <Blacksmoke16> or how are they used?
<FromGitter> <mwlang> right now, just constants coming back from API calls.
<FromGitter> <mwlang> I haven't attempted enums, yet.
<FromGitter> <Blacksmoke16> they pretty handy
<FromGitter> <Blacksmoke16> adds some cool functionality
<FromGitter> <mwlang> I was just reading about 'em...reminds me of Pascal. :-D
<FromGitter> <Blacksmoke16> makes for nice type restrictions and adds handy methods
<FromGitter> <Blacksmoke16> HTTP::Status is an example
<FromGitter> <Blacksmoke16> then can do stuff like `response.status.success?`
<FromGitter> <Blacksmoke16> `response.status.not_found?` etc
<FromGitter> <mwlang> so you get the boolean "?" method for free?
<FromGitter> <Blacksmoke16> yes
<FromGitter> <mwlang> nice. I definitely like that.
<FromGitter> <Blacksmoke16> plus can define your own
<FromGitter> <Blacksmoke16> ``` def success? ⏎ 200 <= code <= 299 ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5ce60b4813e9854e334eaa15]
<FromGitter> <Blacksmoke16> like so
<FromGitter> <mwlang> funny thing: when I first switched from Delphi/Pascal to Ruby, I implemented an Enumerator gem and Rubyist thought I was nuts for wanting Enums in Ruby.
<FromGitter> <Blacksmoke16> is that not something that exists already?
<FromGitter> <mwlang> well, not really...Rubyists use symbols and hashes for everything frickin' thing.
<FromGitter> <Blacksmoke16> :S fair enough
<FromGitter> <mwlang> so I'm actually "unlearning" some habits I picked up in Ruby and recovering old long-lost habits from Delphi days.
<FromGitter> <Blacksmoke16> hehe, symbols might get removed eventually, so id just use strings
<FromGitter> <mwlang> one thing I did in this binance project was use classes, not structs for the incoming data. I'm not sure quite what the advantages of one over the other is, but I definitely had less hassles getting classes to work like I was thinking in the moment.
<FromGitter> <Blacksmoke16> classes are passed by reference while structs are value
<FromGitter> <Blacksmoke16> are two reads
<FromGitter> <mwlang> which means, if I take a struct and try to set it's property in some method call, I really didn't set it, did I?
<FromGitter> <Blacksmoke16> more like if you have an obj from a struct, and you pass that obj to a method that edits it, the original obj you passed isnt going to be changed, only the one within the method
<FromGitter> <Blacksmoke16> while a class would edit the original
<FromGitter> <Blacksmoke16> are some examples in those links, id suggest reading over them first
<FromGitter> <Blacksmoke16> rule of thumb is if the data is immutable, structs are better
<FromGitter> <Blacksmoke16> but if you want to be able to pass an obj around and have it all editing the same obj, classes
<FromGitter> <mwlang> yeah, that's just how I'm used to thinking of the programming solutions right now on account of my Ruby background.
<FromGitter> <mwlang> with working specs, I can try to redo as structs and see if it all works.
<FromGitter> <Blacksmoke16> πŸ‘
<FromGitter> <Blacksmoke16> not a fan of using a spec shard tho
<FromGitter> <Blacksmoke16> just adds something else that could go unmaintained, block your CI, make it that much harder for people to contribute
<FromGitter> <mwlang> oh yeah, just remembered where specifically I struggled...if I make the core class ServerResponse a struct and attempt to inherit to extend: "can't extend non-abstract struct Binance::Responses::ServerResponse"
<FromGitter> <mwlang> you mean spec2?
<FromGitter> <Blacksmoke16> yea
<FromGitter> <Blacksmoke16> just make your parent struct abstract?
<FromGitter> <mwlang> well, that got me further along.
<FromGitter> <mwlang> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ce60ec883ae782aeeb5182e]
<FromGitter> <Blacksmoke16> ok
<FromGitter> <mwlang> for spec2, I may remove it as you suggest. It's not actively maintained and I had to tweak and extend some of it for what I wanted to do as well...and that raises another point...I just realized the ```lib``` folder isn't checked into the repo, so my changes to any dependent shards aren't carried along with the project.
<FromGitter> <Blacksmoke16> mhm
<FromGitter> <Blacksmoke16> would have to fork it and use your fork as a dep
<FromGitter> <mwlang> another vote for casting it out altogether. :-/
<FromGitter> <Blacksmoke16> i kinda like the simplicity of the stdlib module
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ce60fb58f019114ae9e8f79]
<FromGitter> <Blacksmoke16> :shrug:
<FromGitter> <mwlang> I'm just used to some of the extended functionality of Ruby's rspec. The tools like "let", "let!", "subject", "its" and so on really help to DRY up one's specs.
<FromGitter> <mwlang> but I think also, there's less specs to write for Crystal programs because the compiler is catching a lot of the stuff one would often write specs for in Ruby.
<FromGitter> <watzon> Why would symbols be removed?
<FromGitter> <Blacksmoke16> they dont really do anything diff than strings
<FromGitter> <Blacksmoke16> if they get removed it would be like `x = :foo`
<FromGitter> <watzon> I get that they don't serve the same function as Ruby's symbols, but they still serve a purpose don't they?
<FromGitter> <Blacksmoke16> there isnt really a benefit instead of `x = "foo"`
<FromGitter> <Blacksmoke16> they would be exclusive to autocasting enum members afaik
<FromGitter> <Blacksmoke16> i.e. if you have an enum like
<FromGitter> <Blacksmoke16> ```enum ⏎ One ⏎ Two ⏎ Three ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5ce610866366992a94064f4c]
<FromGitter> <Blacksmoke16> and a method like `def add(num : Num)`
<FromGitter> <Blacksmoke16> could do like `add :three`
<FromGitter> <mwlang> If they're gonna be removed, they should be removed fairly soon.
<FromGitter> <mwlang> before Crystal gets too much traction.
<FromGitter> <mwlang> but from my point of view, symbols do add readability to the code.
<FromGitter> <Blacksmoke16> they also used for named tuple keys
<FromGitter> <Blacksmoke16> also that casting of symbol to enum works currently btw ^
<FromGitter> <Blacksmoke16> anyway, im off to bed o/
alex```6 has quit [Quit: The Lounge - https://thelounge.chat]
alexherbo2 has joined #crystal-lang
<FromGitter> <mwlang> g'nite same for me.
alexherbo24 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 248 seconds]
alexherbo24 is now known as alex````
<FromGitter> <watzon> One major annoyance for me is the lack of a `block_given?` macro
<FromGitter> <renich> Can anyone help me with this? https://play.crystal-lang.org/#/r/6ylt. ⏎ ⏎ I need to get an array instead of a string. ⏎ Also, it would be good to have a `Versions.values` method for getting all the values within an array. ⏎ ... [https://gitter.im/crystal-lang/crystal?at=5ce6197aecdf942b4c2cfaf5]
<FromGitter> <renich> The keys array should be: `["hostname", "bios_version", ...]`. The values array should be the same.
<FromGitter> <renich> :S
<FromGitter> <watzon> @renich ideally when asking for help try and shrink your problem down to the minimum code possible that demonstrates your problem
<FromGitter> <watzon> Makes things a bit easier to figure out
<FromGitter> <renich> @watzon yeah... I know. It's hard to do that when you don't get macros. I mean, yes, the yaml might be a bit too much...
<FromGitter> <renich> sorry...
<FromGitter> <watzon> Yeah try shrinking it as much as you can and I'll take a look
<FromGitter> <sam0x17> I almost.... *almost* wish there was a way of specifying macros where it's just a normal crystal function that returns a string that is the source code
<FromGitter> <sam0x17> in Rust I definitely wish that
<FromGitter> <renich> @watzon OK
<FromGitter> <renich> @watzon OK, how's this? https://play.crystal-lang.org/#/r/6ylu
<FromGitter> <watzon> @renich So you want `content` to be an array?
<FromGitter> <watzon> Why are you using CSV in the first place if you want an array? You have an array before doing the CSV building.
<FromGitter> <watzon> I don't think I'm understanding what is wanted
<FromGitter> <renich> @watzon well, I need to parse some yaml files.
<FromGitter> <renich> And the boss wants them in a spreadsheet. So I need to flaten the yaml files and put them in a csv
<FromGitter> <renich> It's easier to iterate an array. This is why I asked for it.
<FromGitter> <renich> Because, that output, it's just for one server in one location
<FromGitter> <renich> I need to normalize the output of all servers in all locations.
<FromGitter> <renich> Some of them have more nics and stuff.
<FromGitter> <watzon> Ahh ok, yeah I'm not sure if I can help. CSVs aren't my forte.
<FromGitter> <watzon> Maybe take a look at how it's done here https://github.com/tokland/yaml2csv
<FromGitter> <renich> @watzon OK. Could you help me by making the output that keys gives, be an array in the form of: `[hostname, "bios_vendor", ...]`?
<FromGitter> <renich> I need the values in the same format as well.
<FromGitter> <renich> OK
<FromGitter> <renich> Oh, that might help me much! :D
<FromGitter> <renich> Ah, but that's ruby. They're not dealing with macros there...
<FromGitter> <renich> Oh, man. I didn't know yaml was so hard to manage in crystal...
<FromGitter> <renich> Y really need to get my macro chops going...
<FromGitter> <Coalpha> Hi all. I've just been looking into crystal and I was wondering if there's any way to declare a variable (and it's type) without assigning to it.
<FromGitter> <Coalpha> Never mind, just found my answer, must have skipped over some of the book
<FromGitter> <watzon> @Coalpha you mean just assigning its value as `nil`?
woodruffw has quit [Ping timeout: 252 seconds]
_whitelogger has joined #crystal-lang
<FromGitter> <renich> Would someone take a look at this? https://play.crystal-lang.org/#/r/6ymt. My problem is in line 64. Basically, I need a way for doing the keys vs i.name comparison. It doesn't work if I remove `"" #`
_whitelogger has joined #crystal-lang
ShalokShalom has quit [Remote host closed the connection]
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
ShalokShalom has joined #crystal-lang
hightower2 has quit [Ping timeout: 252 seconds]
ashirase has quit [Ping timeout: 272 seconds]
ashirase has joined #crystal-lang
<FromGitter> <j8r> How can I print the Crystal version on my Crystal program?
<FromGitter> <j8r> without subprocess
alex```` has quit [Ping timeout: 272 seconds]
alex```` has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
Raimondi has quit [Quit: WeeChat 2.4: Β‘Chau!]
<FromGitter> <Val> ``````
<FromGitter> <Val> Crystal::VERSION
<FromGitter> <j8r> yes, thanks
<FromGitter> <j8r> For LLVM, I've done `require "llvm"; LLVM.default_target_triple`
ShalokShalom has quit [Ping timeout: 258 seconds]
<FromGitter> <bew> @watzon when you say `Because the program won't compile` in the crystal version of `first_and_last`, I'd suggest to show the compile error right here
<FromGitter> <Blacksmoke16> @watzon no because that would give the var a type of nil, which in some cases is needed
<FromGitter> <Blacksmoke16> can do like `@var : Int32` but ofc it has to be given a default value or initialized in the initializer
<FromGitter> <Blacksmoke16> same idea with local vars as well, just have to assign them before you can use them
_whitelogger has joined #crystal-lang
<FromGitter> <mwlang> can ```crystal docs``` be leveraged into generating the README.md of the project?
alex```` has quit [Quit: The Lounge - https://thelounge.chat]
Raimondi has joined #crystal-lang
alexherbo2 has joined #crystal-lang
<z64> not entirely sure how that would work, as currently its the other way around - an existing README.md is used by the docs gen as the main page
<z64> that said, you can use the generated `docs/index.json` to build whatever you like
alexherbo28 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 248 seconds]
<FromGitter> <mwlang> ok, I didn't realize the ./README.md was the main page of the docs generated. So, I'll look at that more. Only just now trying to think through documenting the typical README.md that github displays and the embedded comments markups so I'm not writing examples twice.
hightower2 has joined #crystal-lang
alexherbo280 has joined #crystal-lang
alexherbo28 has quit [Ping timeout: 248 seconds]
<FromGitter> <Blacksmoke16> just have a link in the readme to your api docs?
jeremycw has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
alexherbo2801 has joined #crystal-lang
alexherbo280 has quit [Ping timeout: 248 seconds]
Raimondi has quit [Quit: WeeChat 2.4: Β‘Chau!]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 248 seconds]
rohitpaulk has joined #crystal-lang
jeremycw has quit [Ping timeout: 272 seconds]
rohitpaulk has quit [Ping timeout: 272 seconds]
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
<FromGitter> <asterite> @mwlang look what I found https://github.com/crystal-lang/crystal/issues/6449 :-) . I'll try to fix it later
<FromGitter> <Blacksmoke16> πŸ’―
alexherbo28010 has joined #crystal-lang
alexherbo2801 has quit [Ping timeout: 248 seconds]
<FromGitter> <kingsleyh> evening - I'm looking for anyone interested in helping out on my Crystal based blockchain platform in any capacity - there will be future rewards available - I'm currently in a fundraising incubator program - so there is a real chance of investment - send me a message if you are remotely interested :) - https://sushichain.io
dragonkh has joined #crystal-lang
<FromGitter> <drum445> Hello, is there a way to initialise a new class via a macro?
<jhass> (first solution accepts non strings too)
<FromGitter> <drum445> thanks mate, I sent an invalid playground though
<FromGitter> <drum445> My class name string is inside a var
<FromGitter> <drum445> is it still possible please?
<jhass> macros are executed at compile time
dragonkh has quit [Quit: Textual IRC Client: www.textualapp.com]
<jhass> so they cannot reference runtime values
<FromGitter> <drum445> The class names are in an array
<FromGitter> <drum445> and I loop through them and want to initalise them
<jhass> why do you need a macro?
<FromGitter> <drum445> I couldn't think of another way to initialise a class from a string
<FromGitter> <Blacksmoke16> if you're storing the strings in the array, why not just store the actual class name
<FromGitter> <Blacksmoke16> `[MyClass, OtherClass]` vs `["MyClass", "OtherClass"]`
<FromGitter> <drum445> What type of array would that be though
<FromGitter> <Blacksmoke16> wouldnt have to type it
<FromGitter> <Blacksmoke16> since compiler know via the items in the array
<jhass> Union type of each members .class
<FromGitter> <drum445> It's a bit weird, but the array is populated on run time from a lot of function calls
<FromGitter> <drum445> MyClass.add("TestClass")
<FromGitter> <drum445> for example
<FromGitter> <Blacksmoke16> could you just not make it a string when you go to add it?
<FromGitter> <drum445> Ideally needs to be a string
<FromGitter> <Blacksmoke16> why?
<FromGitter> <drum445> the class name is a substring
<FromGitter> <drum445> Like `TestController@helloWorld`
<FromGitter> <drum445> Which I want to turn into `TestController.new.helloWorld`
<FromGitter> <Blacksmoke16> could use annotations, is what i do for athena
<FromGitter> <Blacksmoke16> but depends on the context i guess
<jhass> smells like you're approaching the problem too much with a dynamic typed languages hat tbh
alexherbo28010 is now known as alexkid
alexkid is now known as alexkidd
<jhass> but if you can require a common baseclass you could have a macro generate a case/when for all of the BaseType.subclasses matching "Foo" to Foo
<jhass> essentially resolving your string at runtime to the right class type
<FromGitter> <drum445> so there's no way to initialize a class from a string var holding that class name?
<FromGitter> <wontruefree> @kingsleyh this is super interesting. It looks like this project has slowed down
<FromGitter> <kingsleyh> @wontruefree yeah had to slow down a bit due to various life stuff getting in the way - but ramping up again now
<FromGitter> <kingsleyh> @wontruefree I've just joined a fund raising incubator so get things kickstarted off again
<jhass> but again, this seems fighting the language and trading compile time for runtime errors
<FromGitter> <kingsleyh> @wontruefree please feel free to join the Telegram channel on the website and help out if you feel like it :)
<FromGitter> <kingsleyh> lots of technical challenges in Crystal coming up :)
<FromGitter> <drum445> @jhass you're probably right, thanks for helping though mate
<FromGitter> <wontruefree> Thanks for the info I will try and build it tonight
<jhass> yw :)
Raimondi has joined #crystal-lang
<jhass> for me a good mindest to approach this stuff is "how would I write this without any magic?" "how would I write this if boilerplate is no concern?" and then "which of the two is the nicer API when I hide the boilerplate with macros?"
<jhass> and that's also a good way to think about macro usecases "uh, too much typing, let's automate that typing"
<jhass> try to write macros that produce code you could've written by hand
<FromGitter> <drum445> Indeed, it does seem strange not to be able to intialize a class from a string
<FromGitter> <drum445> especially when all the class strings are there to begin with
<FromGitter> <drum445> sorry, another question
laaron has quit [Remote host closed the connection]
<FromGitter> <drum445> tyty
laaron has joined #crystal-lang
<FromGitter> <aemadrid> I’m getting an error `undefined constant HTTP::Status` but AFAIK that is defined in the language, right?
<FromGitter> <jwoertink> Are you on crystal 0.28.0?
<FromGitter> <aemadrid> ``` ⏎ LLVM: 3.9.1 ⏎ Default target: x86_64-apple-macosx`````` [https://gitter.im/crystal-lang/crystal?at=5ce71defef853135c810c346]
<FromGitter> <aemadrid> is that new?
<FromGitter> <jwoertink> ah. Yeah, HTTP::Status is new
<FromGitter> <jwoertink> you'd need to upgrade crystal
<FromGitter> <aemadrid> cool, I’ll try that
alexkidd has quit [Quit: The Lounge - https://thelounge.chat]
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/6yv0 i think im so close
<FromGitter> <Blacksmoke16> but seem to be missing something...
return0e_ has quit []