<FromGitter>
<Blacksmoke16> https://play.crystal-lang.org/#/r/5dii pp with `JSON::Serializable` and not nilable property `throws invalid memory access` error
johndescs has quit [Ping timeout: 240 seconds]
johndescs has joined #crystal-lang
rohitpaulk has joined #crystal-lang
return0e has quit [Read error: Connection reset by peer]
return0e has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 240 seconds]
<FromGitter>
<girng> what is CON::any? New?
<FromGitter>
<dscottboggs_gitlab> it's a new object representation @j8r is working on, it's supposed to be easier on the eyes and around as efficient as JSON to parse.
rohitpaulk has joined #crystal-lang
<FromGitter>
<girng> Sounds cool
<FromGitter>
<girng> Seems pretty fast too
<FromGitter>
<dscottboggs_gitlab> yeah, I'm not sure how I feel about it but it certainly looks like a fun project
<FromGitter>
<girng> I recommend Derek in the comments a few months to do a tut on Crystal too
<FromGitter>
<girng> Glad its going more exposure
<FromGitter>
<proyb6> I love Crystal as its easier to add C binding for any missing feature l
<FromGitter>
<proyb6> more easier than Swift
<FromGitter>
<dscottboggs_gitlab> that's a nice tutorial but I feel like he covers a lot more than the core of crystal. one of the things that I like so much about crystal is that at its core all you really need to know is that EVERYTHING is an object which returns, and then point to the docs. I mean, there's a lot more to it but I feel like that should be front and center in any introduction.
return0e has quit [Read error: Connection reset by peer]
return0e has joined #crystal-lang
<FromGitter>
<girng> Yeah, he mostly just goes over the syntax
<FromGitter>
<girng> Maybe in future he can make more in-depth tutorials
<FromGitter>
<dscottboggs_gitlab> well, like right after going over data types he goes straight into string methods and like that's useful but I don't see any reason for a demonstration of that it's more of something you look at a reference for until you're familiar with
<FromGitter>
<dscottboggs_gitlab> but tbh I've never seen one of his videos before that might just be how he does things
<FromGitter>
<girng> Yeah he's got a video for every language, just like that
<FromGitter>
<girng> Lol
sp3ncer has joined #crystal-lang
<FromGitter>
<sam0x17> lets say I have an abstract class `Opp`, and I want to make a hash of `Hash(String, T)` where `T` is any class that extends `Opp`. How would I write that?
<FromGitter>
<sam0x17> ` @@opp_to_class = Hash(String, Opp).new` does not work as when I try to assign to it I get `no overload matches 'Set(Nojs::Opp)#add' with type Nojs::PlusOpp.class`
<FromGitter>
<sam0x17> where `PlusOpp` extends `Opp`
<FromGitter>
<sam0x17> basically I need to take string operators and map those to Opp classes, and I don't want to write a giant case statement
<FromGitter>
<Blacksmoke16> whats all this for?
<FromGitter>
<sam0x17> a compiler
<FromGitter>
<Blacksmoke16> gotcha
<FromGitter>
<sam0x17> I'm writing a very simple language that compiles to js called nojs
<FromGitter>
<Blacksmoke16> neat
rohitpaulk has quit [Ping timeout: 240 seconds]
<FromGitter>
<sam0x17> it's basically opionatedly stripped down ruby and in a way that will be performant instead of the Opal way
<FromGitter>
<sam0x17> best part is the CLI gets to call itself "no"
<FromGitter>
<Blacksmoke16> sounds like a plan
<FromGitter>
<sam0x17> originally I was just going to add ruby/crystal-style require statements to js to replace those horrible js modules, but I was like screw it I'll just bring over everything I want. Web assembly is taking too long for shit I want and I know compiler theory enough to make this work
rohitpaulk has joined #crystal-lang
<FromGitter>
<sam0x17> like my biggest gripe is nodejs making you do all this exports bullshit when I'd rather just dumbly import a file at the current scope like php and C and C++ and crystal and Ruby and everything else does
<FromGitter>
<sam0x17> and I want to support real closures (I'm not 100% sure I can though, haven't worked on that part yet)
<FromGitter>
<sam0x17> so ruby/crystal style blocks
<FromGitter>
<sam0x17> map, etc
<FromGitter>
<Blacksmoke16> sounds like you got some work to do :p
<FromGitter>
<sam0x17> yup
<FromGitter>
<sam0x17> tokenizer is 95% done so that's nice
<FromGitter>
<Blacksmoke16> good luck, imma get to bed for the night
<FromGitter>
<Blacksmoke16> #progress
<FromGitter>
<sam0x17> night
_whitelogger has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 246 seconds]
<FromGitter>
<valamorgon> how can I get class property from string like this[myString] in javascript ? like self[myString]
rohitpaulk has joined #crystal-lang
<FromGitter>
<girng> gn
<FromGitter>
<valamorgon> nvm I solved it with macros
<FromGitter>
<kimvex> Hi, i have a question... how export a module since an file and import from other file and use this module importa
<FromGitter>
<kimvex> *imported
<FromGitter>
<kimvex> ?
rohitpaulk has quit [Ping timeout: 252 seconds]
<FromGitter>
<melonlub> can I have optional arguments in macro?
<FromGitter>
<bew> @melonlub yes, just give them a default value
<FromGitter>
<bew> @kimvex you simply require the file, and your module will be available everywhere
rohitpaulk has joined #crystal-lang
<FromGitter>
<kimvex> @bew thanks,
<FromGitter>
<melonlub> thanks @bew
<FromGitter>
<melonlub> can i definie aliases inside macros?
<FromGitter>
<bew> nop, no function in function either
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 240 seconds]
Raimondii is now known as Raimondi
<FromGitter>
<j8r> @melonlub group them in the same module
<FromGitter>
<melonlub> okay, I am using macro to generate class and then adding them to a hash. Is there any way to initialize a Hash without specifying the type of the value?
<FromGitter>
<rishavs> Is there a known issue where `DB.query_one?` returns a DB::Error if there are no rows returned? According to the docs, in case of no rows, it should return nil
<FromGitter>
<melonlub> Is there a method similar to slice in javascript for crystal?
<FromGitter>
<drum445> @rishavs Not sure tbh, although I hope that isn't a plain text password ;)
<FromGitter>
<rishavs> its a bcrypted one
<FromGitter>
<bajro17> @melonlub you can just use array[1..3]
Yxhuvud has quit [Ping timeout: 260 seconds]
thi has quit [Ping timeout: 260 seconds]
FromGitter has quit [Ping timeout: 260 seconds]
FromGitter has joined #crystal-lang
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 244 seconds]
<FromGitter>
<bew> @melonlub but note that it will create a new array
moei has joined #crystal-lang
<FromGitter>
<proyb6> Can we actually include C header file in Crystal without writing it manually in LibC scope?
<FromGitter>
<j8r> So for now, you can compile statically linked binaries for x86-64, arm64 and x86 (compiling on x86-64 with cross compilation and linking in x86)
<FromGitter>
<fenicks> > So for now, you can compile statically linked binaries for x86-64, arm64 and x86 (compiling on x86-64 with cross compilation and linking in x86) ⏎ ⏎ Understood
<FromGitter>
<dscottboggs_gitlab> is there a way to build a spec executable for running with lldb?
<FromGitter>
<proyb6> @bew I see, was reading on Swift programming, I wanted to compare the pros and cons in Crystal and Swift approach. Libvips is not yet bind despite discussed
<FromGitter>
<dscottboggs_gitlab> @j8r holy shit definitely gonna have to give those a try
<FromGitter>
<bew> There's bindgen from Papierkorb (it's used to bind to qt)
<FromGitter>
<dscottboggs_gitlab> I tried `crystal build spec/spec_helper.cr --static`and that didn't actually run any of my specs
<FromGitter>
<j8r> @dscottboggs_gitlab because the helper contains nothing
<FromGitter>
<dscottboggs_gitlab> @bew I saw a comment from Papierkorb that he "doesn't have time for crystal anymore" and I can't get bindgen or qt5.cr to compile so I would consider those projects abandoned unfortunately
<FromGitter>
<dscottboggs_gitlab> oh right the specs require the helper not the other way around
<FromGitter>
<kimvex> @j8r yes, know but does not have something similar to the cluster in nodejs?
<FromGitter>
<proyb6> @kimvex You can used fork keyword on multiple Crystal process with cluster something like Nodejs, find the "cluster" in gist for some examples or Github, it's feasible.
<FromGitter>
<melonlub> How can I cross compile to windows?
akaiiro has quit [Ping timeout: 246 seconds]
<FromGitter>
<fridgerator> @melonlub Crystal does not have windows support yet
<FromGitter>
<bew> Not fully at least
rohitpaulk has joined #crystal-lang
<FromGitter>
<fridgerator> If cross compilation to windows were to work, i'm guessing it would require WINE or something else
<FromGitter>
<melonlub> okay. Is there anything equal to eval in crystal?
<Yxhuvud>
macros are as close as you come, but that is compiletime
<FromGitter>
<dscottboggs_gitlab> you could, of course, imlement an `eval` function somewhere, which accepts a string, writes it to a temp file, builds it, then runs it. But eval() functions are a huge security hole and should never be used IMO. ⏎ ⏎ not to mention, with crystal, you're not "executing" text, you're executing a binary which is optimized. doing an "eval" in crystal will be even slower than just using an
<FromGitter>
... interpreted language anyway because compile-time is longer than it takes to interpret an interpreted language, even without optimizations
<FromGitter>
<melonlub> ah. I was just wondering if it was possible since there are packages for go that allows evaluation of simple expressions.
<FromGitter>
<dscottboggs_gitlab> like I said, it's feasible
<FromGitter>
<dscottboggs_gitlab> it's just highly discouraged
<FromGitter>
<dscottboggs_gitlab> also, compile times for crystal are slower right now than go's compile times
<FromGitter>
<dscottboggs_gitlab> probably always will be
<FromGitter>
<bew> What kind of expressions?
<FromGitter>
<roblally_twitter> I've heard, here, that the crystal team are moving it towards support for true concurrency. Has a concurrency roadmap been published anywhere?
rohitpaulk has quit [Ping timeout: 272 seconds]
akaiiro has joined #crystal-lang
<FromGitter>
<bew> There is no roadmap for concurrency afaik, fwiw @ysbaddaden is working on it, he recently made a few PR to clean the current concurrency code in order to prepare for fibers over real threads
<FromGitter>
<bew> @dscottboggs_gitlab indeed but that's not a roadmap, and devs don't think to update it (maybe it'll come^^)
<FromGitter>
<vladfaust> Hey guys, do you know if I could trigger top-level require in `included` macro? https://carc.in/#/r/5dp1
<FromGitter>
<vladfaust> It says `can't require inside type declarations`
rohitpaulk has joined #crystal-lang
<FromGitter>
<roblally_twitter> @bew Are the sentiments in the links @dscottboggs_gitlab still current? There seemed to be questions about whether a preemptive scheduler would ever be part of the design.
rohitpaulk has quit [Ping timeout: 240 seconds]
<FromGitter>
<bew> No you can't @vladfaust, would be nice though
<FromGitter>
<vladfaust> Yeah, would be...
<FromGitter>
<vladfaust> I'm afraid if I create another feature request issue I'd get banned
<FromGitter>
<bew> Lol
<FromGitter>
<bew> What's you usecase for this behavior?
<FromGitter>
<bew> (the require)
<FromGitter>
<vladfaust> I have `Atom::Model` module for ORM objects. And I have `atom/model/repo` which defines app-level repository while requiring `DB_URL` env. Right now I have to write `require "atom/model"` explicitly in my app when I want to use models. I'd like `atom/model/repo` to be required only if there is at least one `Atom::Model` included.
<FromGitter>
<vladfaust> That looks complicated, but it's really not :)
<RX14>
@vladfaust replied to your issue
<FromGitter>
<vladfaust> Haven't read it yet @RX14, are there any good news for me?
<RX14>
yes
<RX14>
i replicated your desired interface exactly, well typed, without your proposed feature
<RX14>
or macros
<FromGitter>
<vladfaust> Give me a little time
<FromGitter>
<vladfaust> I see now. It looks nice, thanks, @RX14! Gonna use this approach for now :)
<RX14>
well that feature isn't going to get implemented
<FromGitter>
<vladfaust> Ever?
<RX14>
probably not
<FromGitter>
<vladfaust> Could you elaborate on reasons? Just because it's hard to?
<RX14>
mainly that
<RX14>
but I imagine the semantics would be super weird
<FromGitter>
<vladfaust> I'm far from understanding that deeply
<RX14>
basically your proposal is to put the defaults for a named tuple into the type
<RX14>
but types don't really carry values
<RX14>
and the type inference could only ever work when the named tuple was an argument to the method
<RX14>
just like the enum shorthand
<RX14>
and because there's a good alternative to the syntax
<RX14>
there's little motivation to clear up these issues
<FromGitter>
<vladfaust> Still not understanding, honestly, but it's me. I appreciate the effort to explain this and I believe you
<RX14>
adding a NamedTuple#deep_merge would be another strategy
<RX14>
then you'd just take **args and merge some stuff
<RX14>
then you could pass around the named tuple
<RX14>
however - it's not as well-typed as my proposal
<RX14>
and it's nicer to pass around records
<RX14>
if you need type aliases it's kind of a code smell already
<FromGitter>
<vladfaust> I like the errors your example brings, they're self-descriptive enough
rohitpaulk has joined #crystal-lang
<FromGitter>
<vladfaust> Thank you very much.
<RX14>
I do agree with you that crystal needs to maintain ruby's ability to create powerful DSLs
<RX14>
and do so easily
<FromGitter>
<vladfaust> I'm glad you dive into the issue
<FromGitter>
<vladfaust> Yes, it needs a way to create API wrappers easily at least
<FromGitter>
<vladfaust> Because lots of software is built around existing HTTP APIs
<RX14>
other languages would probably reduce the nesting and use a builder API
<FromGitter>
<vladfaust> I don't understand, what building approach you're talking about?
<RX14>
it doesn't matter, it's inferior :)
<FromGitter>
<vladfaust> I believe so
<FromGitter>
<vladfaust> But in the end, do you like the syntax of target examples which are in the issue?
<FromGitter>
<vladfaust> The one of just nested tuples?
<RX14>
the ones which I replicated? yes
<RX14>
I like them as a DSL
<RX14>
or to put it more simply
<RX14>
I like the user-facing API
<RX14>
but transforming that nice user-facing API into records or other classes as soon as possible internally to gain crystal's typing advantage is a must for me
<RX14>
I wouldn't want to pass around named tuples very "far"
<FromGitter>
<vladfaust> Let's split it. Having exclusively tuple arguments is bad?
<RX14>
I don't think so
<FromGitter>
<vladfaust> In your implementation you still use records. Would it be better to use tuples exclusively, giving that we have Stripe API docs?
<RX14>
no, thats what I was talking about
<RX14>
I would always use records internaly
<FromGitter>
<vladfaust> But these are arguments only
<FromGitter>
<vladfaust> What's bad about it? Not-so-good errors?
<RX14>
I use records but the records are not in the API
<RX14>
or - don't have to be
<FromGitter>
<vladfaust> Yes, not in the public one
<RX14>
so I'm not sure what you mean
<FromGitter>
<vladfaust> What's the advantage of your "I'm trying to use records when speaking about complex arguments"?
<RX14>
well passing named tuples around is harder than records
<RX14>
because you cant add methods
<RX14>
and the syntax for named tuple types gets messy
<RX14>
its just not what named tuples are designed to do
<FromGitter>
<vladfaust> And what are they designed to do?
<RX14>
for passing ad-hoc data a small disatnce
<RX14>
maybe inside one class
<RX14>
ideally inside one or maybe two methods
<FromGitter>
<vladfaust> That's exactly the case I'm working on!
<RX14>
but definitely for for a whole project
<RX14>
but it's not so
<RX14>
because these types are global to the API wrapper
<RX14>
they're used in a lot of places
<FromGitter>
<vladfaust> These arguments are used exclusively for one method. The records *can not be shared* due to Stripe API "features"
<RX14>
so record fits better
<RX14>
if the named tuples never leave the method then you could use merge to add defaults
<RX14>
then maybe use .as() to assert that the resulting named tuple was the correct type
<RX14>
but it still wouldn't be quite as nice errors
<RX14>
try it out for yourself
<FromGitter>
<vladfaust> Yeah, I will. Thanks for `merge` idea
<FromGitter>
<vladfaust> You've helped me a lot, @RX14
<RX14>
I was imagining these records would be passed around a lot
<RX14>
but I guess since its an API wrapper it'll just be straight to json
<RX14>
you just wanted defaults and type checking
<FromGitter>
<vladfaust> Exactly (urlformencoded in this case :))
<RX14>
I don't think that you'll get as good errors
<RX14>
but it might be acceptable
<FromGitter>
<vladfaust> No, I don't even want defaults. I need ommit-ability
<RX14>
that is defaults?
<FromGitter>
<vladfaust> To skip some args
<FromGitter>
<vladfaust> NamedTuple isn't capable of omitting args, right? And MY issue is exactly about that
<RX14>
thats what merge is for
<RX14>
thats defaults
<RX14>
to me
<FromGitter>
<vladfaust> Please, how would you implement merge in this case? https://carc.in/#/r/5dq8 I would be even more thankful, because it's not clear for me now
<FromGitter>
<bew> Nice resolution RX14 ;)
<FromGitter>
<vladfaust> https://carc.in/#/r/5dqg how to handle non-nilable exp_month etc. in this case (remember, I want to get rid from records), @RX14?
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 240 seconds]
Raimondii is now known as Raimondi
<FromGitter>
<vladfaust> I think I'm too tired for today
<FromGitter>
<vladfaust> I think there is no way to get rid of records, though
<FromGitter>
<vladfaust> You cannot define a strict list of arguments (with nested) using `merge` approach
akaiiro has quit [Ping timeout: 252 seconds]
akaiiro has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 240 seconds]
ua has quit [Ping timeout: 252 seconds]
ua has joined #crystal-lang
Vexatos has quit [Remote host closed the connection]