RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.27.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
<FromGitter> <girng> macros will continue to blow my mind. there is nothing i can do
<FromGitter> <j8r> You can `{{debug}}` your mind, that helps
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
<FromGitter> <girng> πŸ˜†
<FromGitter> <girng> Random.new.rand(-10..20)
<FromGitter> <girng> tested it, yep works wonderfully !
<FromGitter> <girng> Niceeee
Raimondi has quit [Ping timeout: 240 seconds]
<FromGitter> <nrser> Hey everyone, I've been evaluating Crystal for the last day or two and been hitting a lot of "Error: you've found a bug in the Crystal compiler", macro expansion and other type-system errors that I've had mixed success fiddling my way out of... was wondering if anyone with more experience would be willing to help?
Raimondi has joined #crystal-lang
<FromGitter> <nrser> Mostly stuff around splats and generics, where I'm not getting much useful out of the compiler
<FromGitter> <nrser> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c4411f620b78635b65103c9]
<FromGitter> <sam0x17> If I use instances of a struct in a class (like as instance variables), are they heap allocated or stack allocated?
<FromGitter> <sam0x17> @nrser definitely report those as issues on the github, it helps everyone ;)
<FromGitter> <nrser> @sam0x17 yeah I'm trying to bookend it down a little bit between simple examples that I think preserve the fundamentals, but work, and the full use case that breaks
<FromGitter> <sam0x17> gotcha
<FromGitter> <nrser> This seems pretty boiled down for that particular error: https://play.crystal-lang.org/#/r/61vi
<FromGitter> <nrser> Ah never mind, that was all 'cause I left a change in to the `self.print` sig by accident
<FromGitter> <nrser> Still a wonky compiler readout though I guess
<FromGitter> <nrser> This is the other one I've been seeing lately: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c4415deba355012a46936b7]
DTZUZO_ has quit [Ping timeout: 246 seconds]
Raimondi has quit [Ping timeout: 240 seconds]
<oprypin> nrser, when it says "bug in the compiler", it really is a bug in the compiler that should be reported. also why it looks wonky
<FromGitter> <nrser> Is this uncommon for most people? I've hit at 4-5 different ones in the last day
<oprypin> yes it's uncommon
<oprypin> and the most important thing when reporting is a complete code snippet causing it
<oprypin> also when trying to get help.
<oprypin> but i see you're already doing it so congratulations
<oprypin> do you need help with any unresolved error at this time?
<FromGitter> <nrser> What's up w all the "use a more specific type" errors?
<FromGitter> <nrser> Think I've seen it with Object, Reference, Pointer, generics... what are you supposed to use for any type?
<FromGitter> <nrser> Fine w unsafe btw just not sure how to do it
<oprypin> oh, well there's no such thing as "any type"
<FromGitter> <nrser> It's just for output & logging
<oprypin> it's possible to implement probably but not implemented and no immediate plans
<FromGitter> <nrser> What's object then?
<oprypin> fake base class for everything
<FromGitter> <nrser> Oh jeez
<oprypin> what
<FromGitter> <nrser> I
<FromGitter> <nrser> It's a surprising limitation
<oprypin> is it though? i don't know any compiled-to-native-code language that has anything close
<FromGitter> <nrser> For something adopting Ruby's syntax to go from everything's an object to nothing can be
<FromGitter> <nrser> Java?
<FromGitter> <nrser> Don't they have Object?
<FromGitter> <nrser> And, what's in C, like void*?
<FromGitter> <nrser> Yeah prob like Haskell don't have it
<FromGitter> <nrser> I feel like most langs have a way of saying "here's some pointers", even if it's boxing, unsafe, whatever
<oprypin> well knock yourself out with Void* but then you need to restore the type info
<oprypin> really though, wanting to do this is often a bad sign and there are almost always better solutions
<FromGitter> <nrser> I'm just kicking the wheels, seeing what it can and can't do at this point
<oprypin> primarily thinking of generics. and duck-typed methods are always there
<oprypin> just shoot specific examples, always easier to work from there
<FromGitter> <nrser> I managed to put together this thing that seems to hold and string-ify arbitrary Tuples and NamedTuples, but I haven't managed to store it them as instance variables... https://play.crystal-lang.org/#/r/61x9
<FromGitter> <nrser> I keep getting compiler bugs or "use a more specific type" (not sure what more specific type would make any sense here thought)
<FromGitter> <r00ster91> you get this for example here: `array = [] of Array`. Here Crystal is just not satisfied with the type you gave it. You need to say what the `Array` will contain. So this for example will compile: ⏎ `array = [] of Array(String)`
<FromGitter> <r00ster91> You need to give more types
<FromGitter> <nrser> huh?
<FromGitter> <nrser> I'll look again but I don't think I have any arrays
<FromGitter> <nrser> it's all Tuples / NamedTuples
<FromGitter> <r00ster91> it was just an example
<FromGitter> <nrser> Yeah the array and hash stuff is cake, but the Tuple / NamedTuple has been a bit trickier for me
<FromGitter> <r00ster91> for example in the Tuple docs: https://crystal-lang.org/api/0.27.0/Tuple.html ⏎ you can see that it wants a type. This means whenever you write "Tuple", you need to write what type it holds. So e.g. Tuple(String)
<FromGitter> <nrser> It's generic
<FromGitter> <nrser> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c442fae7a0f4d5b19da2f6e]
<FromGitter> <nrser> (in brief)
<FromGitter> <nrser> concrete types come out like `Reason(Tuple(String, String), NamedTuple(three: String))`
<FromGitter> <nrser> for `Reason.new "one", "two", three: "four!"`
<FromGitter> <nrser> so there's some further details, but `Reason` seems to work pretty well, but then I've run into trouble composing it
<oprypin> this is just not a good way to store data
<oprypin> should be Array, Hash
<FromGitter> <nrser> ok, I'll switch them up
<oprypin> the language's main author doesn't like namedtuples being used for storage so much that he wanted to remove them entirely
<FromGitter> <nrser> I tended towards Tuple / NamedTuple since I thought compiler might be able to be a lot more clover w those 'cause immutable
<FromGitter> <nrser> *clever
<FromGitter> <nrser> And you have types at compile time, stack allocated... seemed like one of the nice parts, but, yeah, they didn't turn out to be too nice to work with like this
<oprypin> maybe so, but the size of compiled code will be so ridiculously huge and it's just really inconvenient
<FromGitter> <nrser> yeah that makes sense
<oprypin> nrser, but then you're back to wanting an arbitrary value type in Hash, which won't work
<FromGitter> <nrser> hmrm :/
<oprypin> so *maybe* the approach needs to be rethought
<FromGitter> <nrser> I mean if there's not a reasonable way to cart arbitrary data around then that's fine, these are the sort of things I'm doing this to find out
<oprypin> surely you won't have any useful way to interact with this data, other than, say, string interpolation. maybe it's good to define the exact combinations of input types in a meaningful way
<oprypin> say if this was for error reporting. there's no advantage in storing the data generically because there is no meaningful way of accessing the data in a structured way
<oprypin> then why not just store the interpolated string...
<oprypin> or you might want to have a class hierarchy with well-defined fields and interpolation
<FromGitter> <nrser> The advantage is being able to pipeline the data to different destinations that want to handle it (display / store / whatever) differently
<FromGitter> <nrser> With macros then you just leave the call sites (as macros) in the code and control where they actually get compiled in via compile time settings
<FromGitter> <nrser> did this with custom Babel plugin in JS and it worked really nicely. Doesn't really work as well in Ruby w/o true macros / compiler access, but thought I would give a try here
<FromGitter> <nrser> of course can move a string around, I guess I would just assume every lang can do that reasonably
<oprypin> no matter how you spin this, the destinations won't have a way to usefully handle arbitrary data. it's either doing the same thing to every value or it has pre-defined patterns.
<oprypin> for first one, how are you even gonna store this in a file or database? for 2nd one, why not then define exactly what those patterns are by using meaningful types?
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
<FromGitter> <nrser> Like I said, I'm evaluating it... let's see what it can do, what it can't, what it makes pleasant, what it makes tiresome... I believe you the language can do specific things you ask it just fine :)
<oprypin> yeah then the conclusion is, languages that compile to native code really don't want you to store arbitrary types
laaron has joined #crystal-lang
<FromGitter> <nrser> Yeah, fair enough. Crystal seems primarily focused on performance, and don't want to be boxing and unboxing things all over the place.
<FromGitter> <nrser> Are there particular use cases that the community feels like Crystal excels at?
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
<FromGitter> <vladfaust> @nrser um, everywhere? It allows to write maintainable human-understandable (aka expressive) code just like Ruby, but it has speed of C and zero startup time (as of being compiled), making it perfect for all spheres of development
<FromGitter> <vladfaust> @nrser um, everywhere? It allows to write maintainable human-readable code just like Ruby, but it's compiled into assembly code giving native speeds, thus making it a perfect tool for literally everything
ashirase has quit [Ping timeout: 246 seconds]
ashirase has joined #crystal-lang
<FromGitter> <vladfaust> When we speak about class methods, we use dot (`.foo`), when about instance methods -- (`#foo`). Macros are described with dot as well (`.bar`), but they're different from class methods. Which symbol would you use for macros instead?
bazaar_ has quit [Quit: Reconnecting]
bazaar has joined #crystal-lang
_whitelogger has joined #crystal-lang
<FromGitter> <r00ster91> @vladfaust I think `%foo` would fit well.
<FromGitter> <vladfaust> Yeah, because `%` is used in macros. Smart
<FromGitter> <bararchy> so... "m\xAA".ascii_only? => true ... why?
_whitelogger has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
rohitpaulk has joined #crystal-lang
<FromGitter> <proyb6> Who uses xxHash64 or other hashing shards in your projects? I'm unsure about SipHash in Crystal shards for general purpose, xxHash seems to hash faster on large data sample about 10KB size
rohitpaulk has quit [Ping timeout: 268 seconds]
rohitpaulk has joined #crystal-lang
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
<FromGitter> <vladfaust> @proyb6 there is no native Crystal implementation of xxhash yet
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
<FromGitter> <drum445> Does anyone have a sample project of Kemal and MySQL?
<FromGitter> <proyb6> Yeah, I tried the C binding which someone suggested you earlier, the whole day I spent on reading about xxHash and Spooky on the web that both seem better as I haven’t tested if the SipHash has collision on words or filenames yet.
<FromGitter> <vladfaust> SipHash is slower
<FromGitter> <proyb6> I’m curious how many bytes of sample you was testing?
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 250 seconds]
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
<FromGitter> <proyb6> Oh, forgot about the thread you’ve posted. xxHash128 were discussed but the author have not have the time to work on it until the end of this year.
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
<oprypin> vladfaust, what do you need the hash value for?
<oprypin> bararchy, you made a string that contains malformed UTF-8, so all bets are off
<oprypin> note that there are no guarantees that it won't change with Crystal version. also, of course, you should be aware that same hash does not mean same value -- especially for this simplistic algorithm
Raimondi has joined #crystal-lang
laaron- has joined #crystal-lang
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
<FromGitter> <vladfaust> Thanks, @oprypin, I understand that
Raimondi has quit [Ping timeout: 240 seconds]
pabs has quit [Ping timeout: 246 seconds]
<FromGitter> <vladfaust> They said everything in Crystal is Object, while a module is not
<FromGitter> <vladfaust> `Foo.ancestors # => [] of ::NoReturn`
<FromGitter> <vladfaust> ```code paste, see link``` ⏎ ⏎ If I have `Foo`, I can not anyhow get `Bar`. My best guess was `Object.all_subclasses.select{ |t| t <= Foo }`, but it doesn't work as of `Bar` being not a descendant of `Object` [https://gitter.im/crystal-lang/crystal?at=5c4497db746d4a677ae270ba]
<FromGitter> <vladfaust> https://carc.in/#/r/620g is there a way to get `Bar, Baz` in the output? :thinking:
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c4499647a0f4d5b19dca81b]
<FromGitter> <Blacksmoke16> hrm
<FromGitter> <Blacksmoke16> well managed to get the `X has no type` bug again
<FromGitter> <vladfaust> Lez go boiz https://carc.in/#/r/620h
<FromGitter> <Blacksmoke16> πŸ’―
<FromGitter> <vladfaust> @Blacksmoke16 when I got this bug, I usually end up doing `.as(PossibleTypes)`
<FromGitter> <Blacksmoke16> thats the thing, i have wrapped in a `if qp.is_a?(QueryParam)`
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c449a2f7a0f4d5b19dcae7c]
<FromGitter> <vladfaust> Sorry, to small context for me
<FromGitter> <vladfaust> As Chris would say, find another way ))))00)
<FromGitter> <Blacksmoke16> yea np,i have an idea
<FromGitter> <Blacksmoke16> ill see if ican reproduce it
<FromGitter> <vladfaust> Don't think anyone would need it but https://carc.in/#/r/620u
sevensidedmarble has quit [Ping timeout: 250 seconds]
sevensidedmarble has joined #crystal-lang
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 268 seconds]
Groogy has joined #crystal-lang
rohitpaulk has joined #crystal-lang
<FromGitter> <girng> @nrser game servers!
<FromGitter> <drum445> Is there a clean way to go from mysql result set to JSON in Crystal?
<FromGitter> <drum445> I wrote this to deal with it: https://github.com/drum445/objectify ⏎ But wondering if there is a nice built in way?
<FromGitter> <mavu> evening, I have trouble finding a list of exceptions a http request can raise, could anyone point me in the right directions where I might find such a list?
<FromGitter> <vladfaust> @mavu related to https://github.com/crystal-lang/crystal/issues/7154
Raimondi has joined #crystal-lang
<FromGitter> <mavu> thanks :) ⏎ Coming from ruby (obviously :) ) I learned that you should not do a rescue *all* because You might catch things you did not expect and would want to handle in other places. ⏎ Should I just do a rescue all on http requests?
<FromGitter> <girng> ya rescue ex : Exception
<FromGitter> <girng> can do multiple it's nice
ua has quit [Read error: Connection reset by peer]
ua has joined #crystal-lang
<FromGitter> <mavu> Ok, going with that. thanks.
rohitpaulk has quit [Remote host closed the connection]
<FromGitter> <vlazar> I didn't know about this interesting proc composition operator in Ruby https://drivy.engineering/ruby-lambda-composition/
<FromGitter> <vlazar> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c44b7751cb70a372a0ce623]
<FromGitter> <drum445> Any ideas on mysql to JSOn please guys?
<FromGitter> <Blacksmoke16> hmm
<FromGitter> <drum445> or better still, is there a way to perform a to_h on a resultset?
<FromGitter> <drum445> Similar to how ruby deals with mysql rows
<FromGitter> <Blacksmoke16> not sure, prob would have to add an override to do it
<FromGitter> <drum445> Come up with this so far ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c44bb050721b912a5aefada]
<FromGitter> <drum445> I can't really go through every type and add the relevant to_x though
<FromGitter> <Blacksmoke16> sure you can :p
<FromGitter> <drum445> lol
<FromGitter> <Blacksmoke16> macro it up
<FromGitter> <drum445> How would I go about that matey?
<FromGitter> <Blacksmoke16> have a hash of each type and the method to call then iterate over that in macro land to build out your case statement
<FromGitter> <Blacksmoke16> like
<FromGitter> <Blacksmoke16> ```{% for type, method in TYPES %} ⏎ when {{type}} then obj{{method}} ⏎ {% end %}``` [https://gitter.im/crystal-lang/crystal?at=5c44bb661cb70a372a0cfbde]
<FromGitter> <Blacksmoke16> will have to wrap the whole case statement in a `{% begin %} xxx {% end %}` tho
<FromGitter> <drum445> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c44bc4ccb47ec3000749e10]
<FromGitter> <drum445> when Int8 then obj".to_i8" :(
<FromGitter> <Blacksmoke16> not quite, like
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c44bc7d20b78635b65525a4]
<FromGitter> <Blacksmoke16> try that
<FromGitter> <drum445> Nice one, thanks. Now I've just got to find a way to add that to my hash
<FromGitter> <Blacksmoke16> might be a better way, but im not too familiar with the plain resultsets from db shard
<FromGitter> <j8r> TIL private constants: `private CONST = "val"`
laaron- has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
<FromGitter> <sam0x17> @oprypin thanks, that matches my intuition
<FromGitter> <vladfaust> @j8r also private aliases, classes and structs, right?
<FromGitter> <vladfaust> Haven't I miss anything
Raimondi has quit [Ping timeout: 240 seconds]
<FromGitter> <girng> crystal playground down or just me?
<FromGitter> <theretromaniac> Down for me too
<FromGitter> <girng> the end is nigh
DTZUZO_ has joined #crystal-lang
DTZUZO_ has quit [Ping timeout: 250 seconds]
sevensidedmarble has quit [Ping timeout: 246 seconds]
sevensidedmarble has joined #crystal-lang
sagax has quit [Ping timeout: 246 seconds]
Groogy has quit [Quit: WeeChat 2.3]
<oprypin> jhass:
<FromGitter> <girng> hello oprypin
<oprypin> hi
<FromGitter> <girng> did you see my new github name lol
<oprypin> no
<oprypin> now yes. ok.
<FromGitter> <girng> haha :D
pabs has joined #crystal-lang