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
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<FromGitter> <aisrael> speaking of macros, am trying to write a simple macro that will initialize a bunch of local variables but I'm getting `If the variable was declared in a macro it's not visible outside it`. I thought that's why we had "fresh variables": because you *should* be able to declare or manipulate vars "outside" the macro?
Creatornator has joined #crystal-lang
<FromGitter> <bew> a fresh variable is a variable with a generated variable name, you can't know its name "outside" the macro
<FromGitter> <paulcsmith> How crazy would it be to make fresh variables the default? It seems that is the safest option and using `%` could generate an unfresh (stale?) variable
<FromGitter> <paulcsmith> Would maybe break some libs, but might be worth it
<FromGitter> <paulcsmith> Elixir goes that route and it works quite well. I think they use different terminology, but I can't remember what it's called
moei has quit [Ping timeout: 244 seconds]
<FromGitter> <aisrael> @bew I'm confused. So, what're "fresh variables" for if variables in macro scope aren't "visible" outside? Does that mean our macros have to define methods all the time to be useful?
<FromGitter> <aisrael> +1 to @paulcsmith's suggestion
<FromGitter> <bew> as the doc says https://crystal-lang.org/docs/syntax_and_semantics/macros/fresh_variables.html a fresh variable allows you to have a named variable in your macro, that can't conflict with an existing variable where the macro is expanded. I'm sure there are many places in the stdlib where you can see how it can be used, and why
<FromGitter> <aisrael> @bew Ok but what I still don't get is even *if* I *don't* use a fresh variable, e.g. `{{var_name}} = nil` when I try use the value of `var_name` later on I get the "it's not visible outside it" or "undefined local variable or method"
a__b__m has quit [Ping timeout: 240 seconds]
<FromGitter> <bew> I don't get it either ^^ can you give an example?
<FromGitter> <aisrael> Here's a minimal example ⏎ https://play.crystal-lang.org/#/r/4pdg
<FromGitter> <bew> I believe that's how the compiler currently work (no idea if it'll change), local variables should be declared explicitly in the current scope and cannot come from a macro => meaning that the macro expander can't create local variables for the scope where the macro is expanded or something like that
<FromGitter> <bew> i.e: is you declare the var before it works: https://play.crystal-lang.org/#/r/4pdk
<FromGitter> <aisrael> @bew Yeah, ok. So I *really* can't use macros to e.g. initialize local variables.
<FromGitter> <bew> (and its type is correct)
<FromGitter> <bew> what's your use-case here?
<FromGitter> <aisrael> I'm trying to create an XML mapping macro similar to `JSON.mapping`. But I'm also partial to using `struct`s over `class`es, so I need to fully construct the `struct`. Which means I need a) local variables to hold the initial values, then pass them into the `initialize`
<FromGitter> <aisrael> I was trying to do it incrementally, starting with a macro "inside" the existing (working) method to slowly build the pieces together
<FromGitter> <bew> did you read how JSON.mapping works w.r.t this?
<FromGitter> <aisrael> Looks like I have to (painfully) try to do *everything* at the class level, defining the methods as I go along
<FromGitter> <aisrael> Yes. `JSON.mapping` generates an `initialize` that takes a `PullParser`. So in my next attempt I'll try to generate an `initialize(node : XML::Node)` instead
<FromGitter> <aisrael> But that also means I can't do ⏎ ⏎ ```record Foo, id: String do ⏎ XML.mapping(id : String) ⏎ end``` ⏎ ⏎ Anymore [https://gitter.im/crystal-lang/crystal?at=5b6cea69988005174eba410a]
<FromGitter> <bew> also checkout `JSON::Serializable`, which will most probably be the successor to JSON.mapping
<FromGitter> <aisrael> Thanks will study that, too
<FromGitter> <bew> why not do that anymore?
<FromGitter> <aisrael> Not sure if it'll conflict with the default initializer generated by `record`. What I did as a PoC was just declare a `self.from_xml_node(node)` that extracts the node contents and then calls `Foo.new id: _id`
<FromGitter> <aisrael> (Ok, so a second `def initialize(node)` works even within `record`)
<FromGitter> <bew> did you read how `record` is implemented?
<FromGitter> <bew> it's pretty simple
<FromGitter> <bew> it's just a struct pre-filled with some methods and default initializer
<FromGitter> <aisrael> Yeah... it was more of... I had to refactor the existing method to make sure the default code path could be seen by the compiler and that it'd initialize all ivars.
<FromGitter> <icyleaf> Julia is so simlar to Crystal but for technical computing, i like its document. https://docs.julialang.org/en/stable/
<FromGitter> <aisrael> *sigh* Sorry, maybe it's just me, but I'm just not warming up to macros.
<FromGitter> <asterite> You probably don't need macros :-)
<FromGitter> <bew> @asterite do you have any idea why `SomeEnum.each ...` is implemented for enum flags but not regular enums?
<FromGitter> <bew> Huh no, it's the other way, it's implemented for regular enums only
<FromGitter> <bew> Nvm, forget what I said, I mis-read the code
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 244 seconds]
Raimondii is now known as Raimondi
<FromGitter> <svs> @straight-shoota Thanks for that. Guess this is either coming very soon or not at all ;-)
<FromGitter> <aisrael> @asterite Am trying to avoid boilerplate and tedium unmarshalling XML to Crystal objects. Without the equivalent of Java’s run-time reflection, or Ruby’s metaprogramming... it’s... challenging
<FromGitter> <aisrael> I foresee a similar stumbling block with GraphQL. Even if I can write a GraphQL parser, there’s really no easy way to go from a dynamic tree of objects to a Crystal `struct` or `class` without macros
<FromGitter> <aisrael> (Even *with* macros, it’s not... easy :( )
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Creatornator has joined #crystal-lang
Creatornator has quit [Client Quit]
<FromGitter> <codenoid> hi people
<FromGitter> <codenoid> don't forget to go when you leave
<FromGitter> <codenoid> lol
<FromGitter> <codenoid> non nullable-field was null
DTZUZO has quit [Ping timeout: 260 seconds]
DTZUZO has joined #crystal-lang
alex`` has joined #crystal-lang
<FromGitter> <j8r> @bararchy do you know why @ysbaddaden wrotte his event loop and immix in C instead of Crystal? Because of the GC need?
<FromGitter> <bararchy> @j8r because Crystal needs a GC , so writing a GC in Crystal is a little recursive ;)
<FromGitter> <j8r> So Crystal can't be entirely self-hosted :(
<FromGitter> <j8r> ...unless there is a reference counting mode?
<FromGitter> <j8r> or something else that doesn't need a GC?
<FromGitter> <bew> the GC could be written in Crystal
<FromGitter> <bew> maybe it was easier to write it in C instead
<FromGitter> <j8r> I see that the Immix GC was in Crystal in the past
<FromGitter> <j8r> I guess unsafe blocks like in rust could help
<FromGitter> <bew> @bararchy the stdlib is witten to be used with a GC, the language itself could have another stdlib that doesn't, that's just a lot of work anyone did yet
<FromGitter> <bew> no-one* (not anyone)
DTZUZO has quit [Remote host closed the connection]
DTZUZO has joined #crystal-lang
abm has joined #crystal-lang
<RX14> it's possible to write a GC in crystal its just harder than in C
<RX14> and the event loop can probably be in crystal
<RX14> it was probably just easier to prototype in C
alex`` has quit [Ping timeout: 256 seconds]
raz has quit [Changing host]
raz has joined #crystal-lang
alex`` has joined #crystal-lang
<dom96> Easier to prototype in C? what
francisl has joined #crystal-lang
<FromGitter> <j8r> when we don't use a GC, what C is designed for, in contrary of Crystal
francisl has quit [Ping timeout: 240 seconds]
francisl has joined #crystal-lang
alex`` has quit [Ping timeout: 244 seconds]
<RX14> dom96, it takes a variable outside of the equation
<RX14> this is a multithreaded event loop, very low-level stuff. That means there's existing libraries for low-level stuff in C that would be a lot harder to use in Crystal (atomic/lock-free stuff tends to use inlines a lot)
<RX14> at least I assume thats most of the reason
alex`` has joined #crystal-lang
<FromGitter> <asterite> The reason is probably that a GC written in Crystal would have to be compiled every time in your program. Another reason could be that he would have to use the empty prelude and basically write C with Crystal syntax, avoiding anything that could allocate, so in the end it's simpler and more portable to write it in C
<FromGitter> <asterite> Alistar: we should have XML mapping in the standard library, very similar to JSON mapping. If it can be done for JSON with macros it should be possible to do it for XML
abm has quit [Ping timeout: 240 seconds]
<FromGitter> <straight-shoota> @asterite A library written in Crystal could expose a C API and just be used as a compiled library. When it is essentially just C code written in Crystal, this should work.
<FromGitter> <straight-shoota> Not that it makes too much sense, though...
<Yxhuvud> asterite: assuming there is some idea of how much the gc can allocate, couldn't the gc use a preallocated arena for whatever needs it has? Not saying it wouldn't be simpler to do it in C, but there would be ways around it without writing most of the code in c-like crystal
<FromGitter> <PlayLights_twitter> I have a question about Crystal
<FromGitter> <PlayLights_twitter> I have a class with a macro
<FromGitter> <PlayLights_twitter> The macro define some methods and so on
<FromGitter> <PlayLights_twitter> How can i drop those things created by that macro and rerun it
<FromGitter> <PlayLights_twitter> its pretty advance for me
<FromGitter> <PlayLights_twitter> anybody knows? Thanks
<Yxhuvud> hmm. no, that would only make sense if the gc stops the world - not from concurrent gc
<FromGitter> <fridgerator> @PlayLights_twitter comment out the macro 😀
<FromGitter> <PlayLights_twitter> My problem is that the macro runs with a param and want to rerun it with different param
<FromGitter> <PlayLights_twitter> Maybe generate a different class is the way
<FromGitter> <Timbus> Ohhhhh, thanks @asterite . Wow I'm tired
<FromGitter> <Timbus> `git add -u` is usually my friend :<
akaiiro has joined #crystal-lang
moei has joined #crystal-lang
<FromGitter> <asterite> I always forget to add new files in many PRs :-P
<FromGitter> <fridgerator> @PlayLights_twitter Do you need a method overload to accept both parameters?
<FromGitter> <PlayLights_twitter> not really, i need to overwrite the class definition, which looks like complicated
<FromGitter> <Timbus> How the heck did I break yaml tests by changing how interactive IO works. -_-
Raimondii has joined #crystal-lang
flaviodesousa has quit [Quit: KVIrc 4.2.0 Equilibrium http://www.kvirc.net/]
Raimondi has quit [Ping timeout: 256 seconds]
Raimondii is now known as Raimondi
akaiiro has quit [Remote host closed the connection]
<FromGitter> <asterite> It's an unrelated issue. It's solved in master, it's strange that it happens. Maybe you didn't rebase against master?
alex`` has quit [Quit: WeeChat 2.2]
<FromGitter> <j8r> But if we write C, we'll need Clang.
<RX14> no?
<RX14> every crystal program already contains some parts in C
<RX14> it's just compiled by any C compiler into a static library
<RX14> and then linked in statically
<RX14> well, not a static library
<RX14> thats wrong
<RX14> its compiled into an object file then linked with the rest of the object files the compiler produces
francisl has quit [Ping timeout: 255 seconds]
francisl has joined #crystal-lang
<FromGitter> <yorci> possible to pass type directly to method as argument? to create a {} of string, customtype in method, i get error :(
<FromGitter> <j8r> So Crystal will always need a C compiler?
<FromGitter> <asterite> Right now, yes, because of sigfault.c and llvm_ext.cc
Creatornator has joined #crystal-lang
marius has quit [Ping timeout: 245 seconds]
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
marius has joined #crystal-lang
akaiiro has joined #crystal-lang
marius has quit [Ping timeout: 256 seconds]
marius has joined #crystal-lang
marius has quit [Ping timeout: 256 seconds]
marius has joined #crystal-lang
marius has quit [Ping timeout: 256 seconds]
akaiiro has quit [Ping timeout: 248 seconds]
<FromGitter> <bew> anyone knows what is happening to travis? (e.g: https://travis-ci.org/crystal-lang/crystal/jobs/414609263)
marius has joined #crystal-lang
abm has joined #crystal-lang
<FromGitter> <anishkny> Hi folks, could someone/few of you review https://github.com/vladfaust/crystalworld this is a backend implementation of RealWorld backend API using Crystal developed by @vladfaust . RealWorld (http://reaslworld.io/) is a reference medium.com clone in various languages for backend and frontend.
francisl has quit [Quit: francisl]
Creatornator has joined #crystal-lang
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Creatornator has joined #crystal-lang
<FromGitter> <Zenohate> Hey everyone
<FromGitter> <Zenohate> I have a bit of a struggle figuring how can I pull digest made with OpenSSL::Digest ut in a more binray form than hex or base64
<FromGitter> <asterite> I think there was a refactor regarding diest and OpenSSL::Digest became unusable
<FromGitter> <asterite> please open a bug report (or, at least I can't figure it out, and there are no docs about it)
<FromGitter> <asterite> Actually...
<FromGitter> <asterite> Here you go: https://play.crystal-lang.org/#/r/4pls
alex`` has joined #crystal-lang
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
alex`` has quit [Ping timeout: 244 seconds]
DTZUZO has quit [Ping timeout: 240 seconds]
ashirase has joined #crystal-lang