RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.25.1 | 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
<crystal-gh> [crystal] jwoertink opened pull request #6453: rename alias HTTP::Handler::Proc to HTTP::Handler::HandlerProc (master...pr-6386) https://git.io/fNugT
<FromGitter> <bew> what kind of modification you're thinking about?
<FromGitter> <Blacksmoke16> removing a key
<FromGitter> <bew> huh an array doesn't have any key, I don't get it
duane has joined #crystal-lang
<FromGitter> <Blacksmoke16> no i mean i have an array of objects
<FromGitter> <Blacksmoke16> like `Array(Foo)`
<FromGitter> <Blacksmoke16> where the output could look like
<FromGitter> <Blacksmoke16> ```{ ⏎ "name": "John" ⏎ }, ⏎ ...``` [https://gitter.im/crystal-lang/crystal?at=5b5a6719bd17b96159073a7f]
duane has quit [Ping timeout: 264 seconds]
<FromGitter> <Blacksmoke16> like say i didnt want the age key in each obj
<FromGitter> <bew> but if you do `obj.to_json` it should have the key?
<FromGitter> <Blacksmoke16> doesnt really matter, is more of a 1 off thing
duane has joined #crystal-lang
<FromGitter> <bew> you can ignore a field
<FromGitter> <Blacksmoke16> using JSON::Serializable?
<FromGitter> <bew> yes
<FromGitter> <Blacksmoke16> thought of that but need to read it from json first :/
duane has quit [Ping timeout: 256 seconds]
<FromGitter> <bew> there's nothing building to do that, you may want to checkout how it is generated, copy most of it, and remove some things
<FromGitter> <bew> built-in*
<FromGitter> <Blacksmoke16> fair enough
wontruefree has joined #crystal-lang
wontruefree has quit [Quit: this is not the client you are looking for]
<FromGitter> <sam0x17> is it possible to use an environment variable (or a command line parameter) in a macro?
<FromGitter> <sam0x17> need some way to not require a particular file under certain compilation circumstances
alex`` has joined #crystal-lang
<FromGitter> <sam0x17> nvm this did what I want https://crystal-lang.org/docs/syntax_and_semantics/compile_time_flags.html :)
<FromGitter> <drinkmorewaters> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5b5ab1305301255724cad98c]
<FromGitter> <drinkmorewaters> Can anyone tell me if these are the same, as i am taking Javacript code and trying to replicate the results in Crystal. I believe this is called a "Constructor"
<FromGitter> <drinkmorewaters> Feels like i did it wrong as the Crystal code is much faster and a hell of a lot smaller/cleaner.
<FromGitter> <DanilaFe> Well, you're not creating anything like a "class". You're just calling a function.
<FromGitter> <drinkmorewaters> Also, is there a reason why Javascript allows functions within functions but Crystal seems to not like a function within a function.
<FromGitter> <DanilaFe> The JavaScript equivalent of what you wrote would be, ⏎ ⏎ ```function fruit(name, color, shape) { ⏎ console.log('A ' + name + ....) ⏎ }``` [https://gitter.im/crystal-lang/crystal?at=5b5ab1c0db8bd24550b68411]
<FromGitter> <drinkmorewaters> @DanilaFe Ok so this.name = name is a class with name being a class?
<FromGitter> <icyleaf> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5b5ab21eb9a1803f205ef53c]
<FromGitter> <DanilaFe> ^
<FromGitter> <DanilaFe> That would be the same functionality as your JS
<FromGitter> <drinkmorewaters> Ok awesome guys, thanks i will play with that now.
<FromGitter> <sam0x17> javascript allows nesting functions and in javascript functions are objects and objects are functions
<FromGitter> <DanilaFe> Wait, crystal doesn't allow nested functions?
<FromGitter> <drinkmorewaters> @sam0x17 Is there a reason why Crystal would choose not to follow that pattern? Does it create a headache?
jokke1 has quit [Ping timeout: 256 seconds]
<FromGitter> <DanilaFe> Crystal is a compiled language, so I imagine nested functions are a lot more of a headache
jokke1 has joined #crystal-lang
<FromGitter> <DanilaFe> You can get pretty close with blocks and procs (closures, which are the same as JS functions if I remember correctly)
<FromGitter> <drinkmorewaters> Also is a struct in Crystal similar to a struct in Ruby?
<FromGitter> <sam0x17> @drinkmorewaters yes javascript is a very different language since it is dynamic you can do things that would be illegal in crystal. Ruby is also dynamic, but it uses proper object oriented patterns instead of javascript where you can literally type this.whatever or some_object.whatever and assign them to whatever you like on the fly (which can lead to super dangerous / hard to catch errors)
<FromGitter> <sam0x17> because crystal is compiled, all the types and everything have to check out at compile time, so that is why it is more picky, but it is so, so worth it
<FromGitter> <DanilaFe> Well, JavaScript is weird because every object is just a key / hash
<FromGitter> <bew> @drinkmorewaters a struct in Crystal is 'almost' like a class, but allocated on the stack (whereas classes are allocated on the heap)
<FromGitter> <sam0x17> yeah that's a better way of thinking of it basically everything in javascript is a hash
<FromGitter> <drinkmorewaters> So in the end, i'll probably shoot myself in the foot by following Javascript as a guideline lol.
<FromGitter> <DanilaFe> You can shoot yourself in the foot using JavaScript by itself
<FromGitter> <drinkmorewaters> Would it be better to reference another typed language such as Go to do comparisons?
<FromGitter> <sam0x17> ruby would probably be the best
<FromGitter> <sam0x17> we get a lot of ruby questions
<FromGitter> <sam0x17> as in people coming from ruby
<FromGitter> <drinkmorewaters> I am reading about Ruby structs and classes but it's not easy as they do have slight differences that i cannot workout as of yet.
<FromGitter> <sam0x17> its a totally different thing in ruby
<FromGitter> <sam0x17> in ruby Struct is a convenience class that lets you create DSLs easily because you can define an entire hierarchy of objects without writing a bunch of classes
<FromGitter> <sam0x17> like how javascript lets you just assign random properties willy nilly, Struct in ruby sort of lets you do that
<FromGitter> <sam0x17> in crystal, a Struct is totally unrelated to that
<FromGitter> <bew> reading about it, a ruby struct is just a way to easily generate a class with some fields
<FromGitter> <sam0x17> yup
<FromGitter> <bew> kinda like `record` here in crystal (but it generates immutable Crystal struct)
<FromGitter> <drinkmorewaters> Ok, so much more structured. I just can't find it out without some sort of tutorial at the moment.
<FromGitter> <DanilaFe> Have you seen the Crystal book? https://crystal-lang.org/docs/
<FromGitter> <drinkmorewaters> Yeah it's in no way meant for beginners.
<FromGitter> <sam0x17> you basically want to learn the difference between passing by value and passing by reference , which is a concept especially prevalent in C++
<FromGitter> <sam0x17> have you ever used Java? I can explain it in a java sort of way
<FromGitter> <drinkmorewaters> I've not used any languages, this is my first week, i want to learn Crystal but i'm probably making a mistake as i'm hitting wall after wall.
<FromGitter> <drinkmorewaters> Just because my enthusiasm outpaces the amount of content available.
<FromGitter> <icyleaf> You need learn only one language, be focus!
<FromGitter> <sam0x17> https://stackoverflow.com/questions/373419/whats-the-difference-between-passing-by-reference-vs-passing-by-value this might help just keep in mind as you read the answers that in crystal "passing by value" is structs and "passing by reference" is classes. In general you usually want to use classes for most things imo
<FromGitter> <bew> may I ask why you're so enthusiast about Crystal even though you don't know well any language? (that's what I understood from you at least)
<FromGitter> <sam0x17> this is interesting to me because I plan to introduce my 11 year old nephew next week to programming via crystal
<FromGitter> <sam0x17> in all honesty you could just use classes for now and ignore structs until you have time to come back later and understand them. You can totally get by without them
<FromGitter> <drinkmorewaters> @bew Speed, simplicity, structure (Types) safety, compiled (much easier than Ruby to figure out what went wrong, portable binary.
<FromGitter> <drinkmorewaters> @bew new frameworks, not as bloated, if i start now i can get a better understanding, Rails 5 is so large and has so much stuff that i feel bogged down almost instantly.
<FromGitter> <bew> interesting ;)
<FromGitter> <drinkmorewaters> @sam0x17 Ok, i'll checkout classes too and how to work with them.
akaiiro has quit [Ping timeout: 268 seconds]
<FromGitter> <bew> @sam0x17 awesome! you may have a hard time explaining the errors from the compiler to you nephew though ^^
<FromGitter> <sam0x17> @drinkmorewaters if you dont mind me asking, what sort of background are you coming to programming from?
<FromGitter> <sam0x17> @bew yeah I'm pretty excited lol
Raimondi has quit [Remote host closed the connection]
<FromGitter> <DanilaFe> I feel like Crystal errors are pretty good, but the trace for them is very long and verbose
<FromGitter> <bew> is it its 1st programming language? @sam0x17
<FromGitter> <sam0x17> yes he's messed around with some sort of "programming" at school but it was probably that blocks thing or whatever its called
<FromGitter> <bew> scratch..
<FromGitter> <sam0x17> yes that
<FromGitter> <drinkmorewaters> @bew Is that a decent enough answer? People learnt Ruby as their first language, i can't see why Crystal would be more complex, considering it puts more contraints in place to fix errors? ⏎ @sam0x17 I was doing Shopify stores, front end design, i wanted to know more about what was happening, i knew no Javascript or any language, i want to build things for myself. Or maybe just understand tech to
<FromGitter> ... better guide my future, as everything will be based on tech. ⏎ ⏎ If i am too be honest, would you recommend i scrap Crystal until theirs more beginners stuff and just stick to Javascript, Ruby or Python (The one everyone recommends) [https://gitter.im/crystal-lang/crystal?at=5b5ab7775301255724caebcd]
<FromGitter> <sam0x17> he's very motivated since he has terrible internet in his area so this is his only chance at fun lolol
<FromGitter> <sam0x17> @drinkmorewaters ok so you're a frontend developer... did you do HTML markup or strictly photoshop type stuff
<FromGitter> <bew> very cool Sam!!
<FromGitter> <drinkmorewaters> I know HTML, CSS but absolutely no JS i was able to style Shopify stores but not do something like, connect to the graphql api or something more fun.
<FromGitter> <bew> @drinkmorewaters I have no idea, I personally started with C a long time ago so I can't really compare to my experience ^^
<FromGitter> <drinkmorewaters> The reason i chose Crystal is because it's newer i could get in at the start and have a better understanding. Javascript has so much churn. Which made me feel i would constantly be chasing.
<FromGitter> <drinkmorewaters> @bew Lol, i'm not going anywhere near C or C++ haha
<FromGitter> <DanilaFe> The benefit of old languages is that there's a LOT of examples / documentation / tutorials
<FromGitter> <sam0x17> @drinkmorewaters ok so in that case, you definitely should learn js at some point. I recommend learning pure js and then some jquery before you try using any frameworks. For server side it doesn't really matter what you learn and you are saying all the right reasons for wanting crystal so I say stick with crystal
<FromGitter> <DanilaFe> That isn't to say you shouldn't use crystal, it's great
<FromGitter> <drinkmorewaters> @DanilaFe Absolutely, that's definitely something that would help me immensely but i am worried, i spend that time learning that i would have been better off on the one that i kept gravitating towards lol
<FromGitter> <sam0x17> technically speaking, you would get the most mileage out of learning js and doing node.js/express for server side, but I advise against this because npm is so terrible and broken and the js ecosystem is fragmented af and glitchy af and trust me you don't want to deal with that
<FromGitter> <drinkmorewaters> @sam0x17 I know enough Jquery to be dangerous, but not enough to be useful haha. I don't know what i'm doing when i do it.
<FromGitter> <drinkmorewaters> @sam0x17 Yeah, the only reason i didn't go with JS and node is that even the Node creator canned it, people like TJ dropped node for GO and WASM soon, i am gauging that if the pros moved on, then well.
<FromGitter> <sam0x17> @drinkmorewaters at a certain point you will realize no one knows what they are doing, and "conventions" and the things frameworks do are just people being confident and asserting that "this is a good way to do x" -- this is something I often tell the junior developers I train because they come in all wide-eyed thinking they know nothing when really they already know quite a bit they just aren't
<FromGitter> ... arrogant/confident/whatever enough to hack things into working (which is what everyone does)
<FromGitter> <sam0x17> being a developer is mostly about being unafraid to mess around with things until they work, and trying things out that might break, imo, and it takes a certain confidence
<FromGitter> <sam0x17> yeah totally agree on compiled languages / go / wasm / etc .. I am banking on crystal having web assembly support and doing 100% of my work in crystal lolol
<FromGitter> <bew> nice way to put it, I've realized it not too long ago, and was thinking about it lately,so at least I'm not crazy :p
<FromGitter> <sam0x17> yeah, its so a thing
<FromGitter> <sam0x17> lol
<FromGitter> <drinkmorewaters> @sam0x17 I want to hack shit together for fun and have it be portable, maybe leverage wasm via LLVM (Crystal) be portable (Crystal) and be fast as heck (Crystal) So i think i got the right language, just go no idea how to get some fun things together. I've been hacking away with Lucky and Amber, doing pretty useless stuff. But it's the core concepts that i can't translate from Ruby or another langauge
<FromGitter> ... as it just doesn't work that way it seems.
<FromGitter> <sam0x17> @drinkmorewaters there is no better teacher than a project with a deadline, but in lieu of that you should pick some sort of goal/project to create with crystal, could be anything
<FromGitter> <bew> if it's your first compiled (and static typed) language, it's definitely quite different from what you know from other interpreted languages
<FromGitter> <DanilaFe> Try to make something simple, like fizzbuzz, or maybe a pig latin converter
<FromGitter> <sam0x17> or a terminal program that tells you the weather (scrape it from weather.com or whatever) and uses a YAML file to configure your location and other things. (just a suggestion)
<FromGitter> <DanilaFe> No need to scrape, there's always openweathermap
<FromGitter> <DanilaFe> https://openweathermap.org/
<FromGitter> <drinkmorewaters> I'm not struggling to come up with ideas, that parts fine, i'm struggling to find examples, tutorials or explanations to help with the gotchas, the learning and the methods i want to do.
<FromGitter> <sam0x17> lol I'm that guy who still scrapes rather than learning yet another REST API
<FromGitter> <DanilaFe> With crystal's from_json or whatever it's called, most of the API stuff is easy
<FromGitter> <drinkmorewaters> So i am spending double time looking at another language and trying to replicate it, with wild results lol I'm trying to be a translator without knowing either language, it's quite stupid.
<FromGitter> <sam0x17> no that makes sense, at least you have this chat though
<FromGitter> <sam0x17> getting a good idea of what these other languages do will help you gain perspective on how things work in crystal too
<FromGitter> <sam0x17> like I'm probably going to teach my nephew some basic C stuff and make him use malloc and such before he gets the privilege of garbage collection
<FromGitter> <bew> or make him write some Crystal without the stdlib :P
<FromGitter> <sam0x17> the good thing is the stdlib in crystal is very, very good compared to a lot of languages, and at this point the basic building blocks you need for pretty much anything
<FromGitter> <sam0x17> yes actually that is a good idea
<FromGitter> <sam0x17> *are there in the stdlib
alex`` has quit [Ping timeout: 240 seconds]
moei has quit [Quit: Leaving...]
moei has joined #crystal-lang
<FromGitter> <drinkmorewaters> It's very simple, just need more of this https://mordsith.github.io/2017/crystal-tutoial-the-basics---methods/
<FromGitter> <drinkmorewaters> I believe lots of people are planning to do these or have done these, so i am very much looking forward to it!
<FromGitter> <sam0x17> well if you ever get into the whole "serverless" movement I've written a shard that lets you deploy crystal to google cloud functions: https://github.com/sam0x17/gcf.cr the appeal is you can write crystal code for specific endpoints and pay 0.0000000001 cents per invocation instead of paying 10 cents an hour for a web server, and be able to handle enormous traffic spikes etc. So a serverless app is usually a
<FromGitter> ... huge javascript frontend that is stored in S3 / google cloud storage / wasabi / etc and all the end points are lambda / cloud functions, so you have no servers, just a bunch of virtually infinitely scalable things that are dirt cheap
<FromGitter> <j8r> @sam0x17 still, don't begin too hard. I would say start as easy as possible (even Scratch lang) and then if the child likes we can go further 😁
<FromGitter> <sam0x17> yeah, agreed
<FromGitter> <drinkmorewaters> I looked at your shard and have looked at serverless which i'd love to be able to do at some point
<FromGitter> <sam0x17> I might fall back on python + minecraft
<FromGitter> <j8r> That's a good one!
flaviodesousa has joined #crystal-lang
<FromGitter> <sam0x17> @drinkmorewaters thanks! that shard is also very straightforward to pick apart because I tend to code in a very deliberate obvious sort of way with very few includes so feel free to pick through it as an educational exercise it will probably be a lot easier to follow than other shards
<FromGitter> <sam0x17> python is just ruby-like enough that it hurts not being ruby lol
<FromGitter> <j8r> @drinkmorewaters for example, i recommend you to read the files in `spec` folders of projects like Crystal. You can also read the stdlib
<FromGitter> <sam0x17> thats a super good idea
<FromGitter> <sam0x17> specs show you how everything works
<FromGitter> <j8r> @sam0x17 It wouldn't be more Lua for minecraft plugins?
<FromGitter> <sam0x17> there's a python API
<FromGitter> <sam0x17> but generally yes
<FromGitter> <sam0x17> I've never had to take the Lua plunge myself so going to avoid that for now
akaiiro has joined #crystal-lang
akaiiro has quit [Ping timeout: 260 seconds]
<crystal-gh> [crystal] ysbaddaden closed pull request #6452: Compiler: missing `request_value` in `not` call (master...bug/6451-not-missing-request-value) https://git.io/fNuub
alex`` has joined #crystal-lang
Ven`` has joined #crystal-lang
DTZUZO has quit [Ping timeout: 244 seconds]
<FromGitter> <Grabli66> Hi! What do you think about removing libevent from dependencies and rewriting it in crystal?
<FromGitter> <j8r> because time
<FromGitter> <j8r> Big work to do
<FromGitter> <Grabli66> I want to do that, atleast for linux with epoll. But does not understand how. I'am too old for that sh*t :)
ua_ has quit [Ping timeout: 265 seconds]
<dom96> It is indeed a lot of work :)
<FromGitter> <j8r> How about rewriting LLVM in Crystal - lol.
<RX14> building working tooling to seamlessly handle static compilation in an alpine chroot is everyone's best bet for short-term portability
<FromGitter> <j8r> you can already `docker run --rm -it -v $PWD:/app -w /app jrei/crystal-alpine crystal build src/app.cr --static --release --no-debug`
<FromGitter> <j8r> or if you prefer `docker build` the image on your side
<crystal-gh> [crystal] r00ster91 opened pull request #6454: Improve samples (master...fixlinks) https://git.io/fNupf
Ven`` has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
ua has joined #crystal-lang
<FromGitter> <Grabli66> dom96, i saw how it's done in Nim(ioselectors_epoll). I think it's pretty simple to implement it in crystal. :) Joking.
<dom96> Not as simple as simply using Nim ;)
<RX14> i don't think crystal would want to write it's event loop reimplementation in nim, it's too big of a dependency :P
<FromGitter> <Grabli66> dom96, i tried to use nim, several times. But i feel it's not my language.
<crystal-gh> [crystal] j8r opened pull request #6455: Move out Playground from the compiler (master...playground_removal) https://git.io/fNujx
<FromGitter> <Grabli66> RX14, i want to try implement event loop in crystal, not nim. :)
<FromGitter> <j8r> omg there are 1400 open issues on Nim :o
<FromGitter> <delef> Hi everyone! ⏎ Please tell me the ways of solving the problem. ⏎ ⏎ I need only accept a union type in the method argument. ⏎ How can i do this? ... [https://gitter.im/crystal-lang/crystal?at=5b5b05f046235249cd575d36]
<FromGitter> <j8r> why you use `as`?
<FromGitter> <j8r> "classic" overload don't work?
<FromGitter> <Grabli66> Maybe you want something like this? https://play.crystal-lang.org/#/r/4mdu
<FromGitter> <delef> Here's about what I need: ⏎ https://play.crystal-lang.org/#/r/4me7
<FromGitter> <delef> no one knows the answer? 🙁
<FromGitter> <j8r> The general is to avoid big union type because it becomes quickly a mess 😄
<FromGitter> <j8r> It would be better (if possible), do make a struct instead of this big alias
<jokke> hey o/
<jokke> can i somehow restrict a generic type placeholder to be a subtype of something else?
<FromGitter> <delef> I did not mention the big union type :) ⏎ I just need to work in the method only with it. ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5b5b18d6e5fc191d95a3db44]
DTZUZO has joined #crystal-lang
<FromGitter> <delef> I want to make mapping on complex unit types, so I have to accept only them.
<FromGitter> <delef> sorry for my english, but I hope you understand me :)
<z64> jokke: there is no way in generic grammar, but maybe this is good enough https://carc.in/#/r/4mes
<jokke> hmm
<jokke> that's too bad
<jokke> but yeah, that will work
<z64> cool:)
<FromGitter> <delef> Yes, that will work, but I wanted to provide the overload that was in my example
<FromGitter> <delef> https://carc.in/#/r/4meu
<FromGitter> <sroller> @delef Never apologise for your English :-)
<FromGitter> <j8r> sorry for my French, you can :)
<FromGitter> <delef> @sroller why? 😀
<FromGitter> <sroller> @delef I'm a German living in Canada. I did this all the time. People told me what I just wrote. I live close to Toronto where about 50% of the people were not born in Canada! It is said that in the Greater Toronto Area (GTA) people speak 92 mother tongues. All the native english canadians speak one language. The rest is bilingual :-). Also, there are probably >1E+09 people in the world who speak English. Most
<FromGitter> ... of them as a second language. There is no reason to apologise.
<FromGitter> <delef> @sroller I'm understood, thank you 🙂
Raimondi has joined #crystal-lang
renzhi has quit [Quit: WeeChat 2.1]
renzhi has joined #crystal-lang
akaiiro has joined #crystal-lang
duane has joined #crystal-lang
<FromGitter> <fridgerator> Is it not possible to override methods which take a `&block` / `Proc` argument? https://carc.in/#/r/4mfx
<oprypin> well overriding is what you're doing :p
<oprypin> seems not possible to overload
<FromGitter> <fridgerator> yeah overload I meant
<FromGitter> <fridgerator> ok thanks
<FromGitter> <kazzkiq> Does it makes sense to have a "run" option in shards?
<FromGitter> <j8r> please try to avoid using `as` - not a good practise
<FromGitter> <kazzkiq> So one can write repeating project tasks in the shards.yml and invoke it with a `shards run my-command`
<FromGitter> <j8r> I'll bet you're coming from dynamic languages @delef :) ?
<FromGitter> <delef> @j8r yes, I coming from dynamic languages :) ⏎ ⏎ but I created the shard that decodes the MaxMindDB format. ⏎ here is the union type with which you have to work, and this is not the only example ⏎ https://github.com/delef/maxminddb.cr/blob/master/src/maxminddb/types.cr#L2-L3 ... [https://gitter.im/crystal-lang/crystal?at=5b5b3c5fee7b230b447069f1]
<FromGitter> <asterite> Don't use recursive types, you'll have a much easier life
flaviodesousa has quit [Quit: KVIrc 4.2.0 Equilibrium http://www.kvirc.net/]
<FromGitter> <j8r> maxmind database could be huge, right?
<FromGitter> <j8r> Is it wise to parse the all database, or just what we need?
<FromGitter> <j8r> you could do something like https://gist.github.com/j8r/07737bc34cfc4a53e0ddf3051b47f8f4
<FromGitter> <j8r> and create a PullParser for Maxmind
<FromGitter> <delef> MaxMindDB is a binary format, in order to analyze it, you first need to decode it.
<FromGitter> <j8r> hum ok, to decode it to text and then you create hashes,arrays etc?
<FromGitter> <j8r> Hum binary don't change anything
<FromGitter> <j8r> Text or binary, parse what you need
<FromGitter> <delef> @j8r this format has strict mapping rules, you can read about it, but we're not talking about this now :) ⏎ ⏎ very many shards use recursive types, example: ⏎ https://github.com/crystal-community/msgpack-crystal/blob/master/src/message_pack.cr#L5 [https://gitter.im/crystal-lang/crystal?at=5b5b42d3bd17b961590ac969]
<FromGitter> <bew> @sam0x17 I recommend Minecraft with the mod Computercraft where you can program a lot of cool things in Lua
<FromGitter> <delef> without recursive types you can't solve many problems :(
snsei has quit [Read error: No route to host]
<FromGitter> <j8r> Yeah, personally not againt
<FromGitter> <j8r> I underline that `#as(Type` is not good
<FromGitter> <j8r> That's an unsafe hack,
<FromGitter> <j8r> What do you want to achieve? You actual implementation seems to work
<FromGitter> <j8r> Why you dont do `{ SomeType.as_s => SomeType.as_i}`?
<FromGitter> <j8r> Or `SomeType.new("Name")` i guess
wontruefree has joined #crystal-lang
<FromGitter> <sam0x17> @bew thanks ill check it out
<crystal-gh> [crystal] kostya opened pull request #6458: Fix JSON::Serializable with 2 args, and YAML::Serializable with 3 arg… (master...fix_json_with_two_fields) https://git.io/fNzEN
<FromGitter> <delef> The answer to the recursive types was sent to @asterite. ⏎ @j8r I wanted to get `{} of SomeType => SomeType` with content
wontruefree has quit [Quit: bye]
wontruefree has joined #crystal-lang
<crystal-gh> [crystal] chris-huxtable opened pull request #6459: Adds `IO::Memory.truncate()` (master...io-memory-truncate) https://git.io/fNzaA
<FromGitter> <paulcsmith> It seems like this should work, but I can't figure out how :( https://play.crystal-lang.org/#/r/4mig
<FromGitter> <paulcsmith> I think it has something to do with `Array` being generic because if I change it to just accept a `Filter` and not `Array(Filter)` it works fine...hmm 🤔
kosmonaut has quit [Remote host closed the connection]
kosmonaut has joined #crystal-lang
<FromGitter> <paulcsmith> Thank you!
wontruef_ has joined #crystal-lang
wontruefree has quit [Read error: Connection reset by peer]
snsei has joined #crystal-lang
<FromGitter> <asterite> Ivan: yes you can, see JSON::Any in the standard library. It's recursive without using recursive aliases. Recursive aliases are a smell and they will eventually be removed from the language.
rohitpaulk has joined #crystal-lang
akaiiro has quit [Ping timeout: 244 seconds]
DTZUZO has quit [Ping timeout: 268 seconds]
rohitpaulk has quit [Read error: Connection reset by peer]
<FromGitter> <kazzkiq> How can I create a new type/interface? ⏎ ⏎ Example: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5b5b787d12f1be71375e41d5]
<FromGitter> <bew> checkout the pages related to classes in the docs: v
alex`` has quit [Quit: WeeChat 2.1]
wontruef_ has quit [Quit: bye]
wontruefree has joined #crystal-lang
wontruefree has quit [Quit: bye]
wontruefree has joined #crystal-lang
<FromGitter> <Blacksmoke16> crystal doesnt have interfaces in the typescript/php sense of the word i dont think?
<oprypin> how would we know what those do
<oprypin> modules can have abstract methods, it's like an interface
<FromGitter> <Blacksmoke16> yea that would be the crystal equivalent
<FromGitter> <Blacksmoke16> but not explicitly like
<FromGitter> <Blacksmoke16> ```interface User ⏎ name: String ⏎ age: Int32 ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5b5b88ff17c942036b79d369]
<oprypin> wut
<oprypin> also seems like a terrible example of interface
<FromGitter> <Blacksmoke16> was talking about @kazzkiq example
<FromGitter> <Blacksmoke16> that, that sort of setup doesnt exist in crystal, would have to be a class/struct for what he wants
<FromGitter> <Blacksmoke16> or a hash/named tupled alias'd to the keyword `User` like his example
<oprypin> i suppose
duane has quit [Ping timeout: 268 seconds]
wontruefree has quit [Quit: bye]
TCZ has joined #crystal-lang
wontruefree has joined #crystal-lang
DTZUZO has joined #crystal-lang
Philpax has joined #crystal-lang
TCZ has quit [Quit: Leaving]
wontruefree has quit [Quit: bye]
alex`` has joined #crystal-lang
duane has joined #crystal-lang
duane has quit [Ping timeout: 240 seconds]
<FromGitter> <kazzkiq> Guys I tried to work on it using struct, classes and modules. Not sure what I'm doing wrong, but it didn't worked. If you could please provide a micro example with actual code, it would be much appreciated.
<FromGitter> <kazzkiq> I also read the classes docs, but some things are easier to wrap your rlhead about when seeing actual code instead of text, I suppose.
<FromGitter> <Blacksmoke16> @kazzkiq https://play.crystal-lang.org/#/r/4mjp
<FromGitter> <Blacksmoke16> `user : User` makes that method only take a instance of the `User` class
<FromGitter> <Blacksmoke16> while `NamedTuple(name: String, age: Int32)` could take any named tuple that has those properties/data types
<FromGitter> <Blacksmoke16> doesnt *have* to be a user
Philpax has quit [Ping timeout: 240 seconds]
<FromGitter> <kazzkiq> Hmm, got it! My error was trying to pass the NamedTuple directly to the function (that only accepted my class).
<FromGitter> <Blacksmoke16> mhm that would do it
<FromGitter> <kazzkiq> I was thinking that by giving my parameter a type of a class (that returns a NamedTuple) it would simply serve as an alias to that tuple, so by typing it directly would work, too.
<FromGitter> <Blacksmoke16> this would also work
<FromGitter> <kazzkiq> Only because of the below function in your example, right?
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/4mju
<crystal-gh> [crystal] delef opened pull request #6460: Update doc for JSON::Any (master...patch-1) https://git.io/fNzpN
<FromGitter> <kazzkiq> lolol didn't knew about `alias`.
<FromGitter> <kazzkiq> Thanks a lot!
DTZUZO has quit [Ping timeout: 240 seconds]