RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.20.4 | Fund Crystal's development: http://is.gd/X7PRtI | Paste > 3 lines of text to https://gist.github.com | GH: https://github.com/crystal-lang/crystal | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/ | Logs: http://irclog.whitequark.org/crystal-lang
LastWhisper____ has joined #crystal-lang
glenab has joined #crystal-lang
soveran has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Changing host]
soveran has quit [Ping timeout: 245 seconds]
LastWhisper____ has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
splitty_ has quit [*.net *.split]
grindhold has quit [*.net *.split]
daekano has quit [*.net *.split]
aurelien has quit [*.net *.split]
greenbigfrog has quit [*.net *.split]
Kilo`byte has quit [*.net *.split]
Kilo`byte has joined #crystal-lang
splitty_ has joined #crystal-lang
daekano_ has joined #crystal-lang
grindhold has joined #crystal-lang
greenbigfrog has joined #crystal-lang
glenab has quit [Remote host closed the connection]
kiliankoe has quit [*.net *.split]
fedruantine has quit [*.net *.split]
bjmllr has quit [*.net *.split]
Liothen has quit [*.net *.split]
FromGitter has quit [*.net *.split]
z64 has quit [*.net *.split]
pabs has quit [*.net *.split]
jsaak has quit [*.net *.split]
buggs has quit [*.net *.split]
rkeene has quit [*.net *.split]
Papierkorb has quit [*.net *.split]
aemadrid has quit [*.net *.split]
Hates_ has quit [*.net *.split]
jfontan has quit [*.net *.split]
rkeene has joined #crystal-lang
jsaak has joined #crystal-lang
pabs has joined #crystal-lang
bjmllr has joined #crystal-lang
Papierko- has joined #crystal-lang
z64 has joined #crystal-lang
buggs has joined #crystal-lang
FromGitter has joined #crystal-lang
Liothen has joined #crystal-lang
fedruantine has joined #crystal-lang
aemadrid has joined #crystal-lang
kiliankoe has joined #crystal-lang
Hates_ has joined #crystal-lang
Liothen has quit [Changing host]
Liothen has joined #crystal-lang
jfontan has joined #crystal-lang
hmans has quit [Read error: Connection reset by peer]
jeromegn has quit [Read error: Connection reset by peer]
jeromegn has joined #crystal-lang
Majost has quit [Read error: Connection reset by peer]
avdi has quit [Read error: Network is unreachable]
jhass has quit [Ping timeout: 258 seconds]
Majost has joined #crystal-lang
hmans has joined #crystal-lang
M-mva1985 has quit [Ping timeout: 258 seconds]
acheron[m] has quit [Ping timeout: 258 seconds]
kodotest[m] has quit [Ping timeout: 258 seconds]
jhass has joined #crystal-lang
hako has quit [Ping timeout: 242 seconds]
hako has joined #crystal-lang
acheron[m] has joined #crystal-lang
M-mva1985 has joined #crystal-lang
kodotest[m] has joined #crystal-lang
avdi has joined #crystal-lang
aarongodin has quit [Ping timeout: 240 seconds]
aarongodin has joined #crystal-lang
hmans has quit [Ping timeout: 245 seconds]
hmans has joined #crystal-lang
kiliankoe has quit [Ping timeout: 245 seconds]
kiliankoe has joined #crystal-lang
<bmcginty_> Anyone know of any really complicated c bindings that have unknown types being passed from a library back into crystal? I'm working on a bridge from javascriptcore (webkit's javascript engine, full es6 support) to crystal, like duktape.cr. Types come back encapsulated, and I'm going to have to decode them and turn into native crystal types and back again.
LastWhisper____ has joined #crystal-lang
LastWhisper____ has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
LastWhisper____ has joined #crystal-lang
matp has quit [Remote host closed the connection]
matp has joined #crystal-lang
<wmoxam> pointer
<wmoxam> whoops
unshadow has quit [Ping timeout: 240 seconds]
buggs has quit [Ping timeout: 240 seconds]
buggs has joined #crystal-lang
LastWhisper____ has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
unshadow has joined #crystal-lang
unshadow has quit [Ping timeout: 240 seconds]
soveran has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Changing host]
soveran has quit [Ping timeout: 256 seconds]
unshadow has joined #crystal-lang
bjz has joined #crystal-lang
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
bjz has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Changing host]
soveran has joined #crystal-lang
Kug3lis has joined #crystal-lang
Kug3lis has quit [Client Quit]
Kug3lis has joined #crystal-lang
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
bjz has joined #crystal-lang
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<manveru> bmcginty_: not very complicated, but the tcl lib does that a lot
bjz has joined #crystal-lang
Kug3lis_ has joined #crystal-lang
Kug3lis has quit [Ping timeout: 240 seconds]
holyheels has joined #crystal-lang
glenab has joined #crystal-lang
glenab has quit [Ping timeout: 240 seconds]
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
Philpax has joined #crystal-lang
Philpax_ has quit [Ping timeout: 246 seconds]
akwiatkowski has joined #crystal-lang
mark_66 has joined #crystal-lang
Yxhuvud has quit [Read error: Connection reset by peer]
Kug3lis_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Yxhuvud has joined #crystal-lang
Kug3lis has joined #crystal-lang
<Kug3lis> Is there any way like to have shutdown handler, or class initialize opposite deconstruct of something similar?
akwiatkowski has quit [Read error: Connection reset by peer]
Kug3lis has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
soveran has quit [Remote host closed the connection]
gloscombe has joined #crystal-lang
Kug3lis has joined #crystal-lang
<manveru> Kug3lis: i think you can do something like Signal::INT.trap{ your stuff }
<Kug3lis> manveru I though about it but then if it quits with some different signal...
<manveru> yeah... not ideal :(
bjz has joined #crystal-lang
bjz has quit [Client Quit]
<Kug3lis> Also maybe someone has ideas how to count results from crystal-db query? I cant seem to see any method in ResultSet API
<manveru> just looked and saw that that's how the spec lib does it
<manveru> maybe TERM
Raimondi has quit [Read error: Connection reset by peer]
Raimondi has joined #crystal-lang
soveran has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Changing host]
soveran has quit [Remote host closed the connection]
bjz has joined #crystal-lang
<manveru> so many PRs, so little merge :(
<txdv> manveru: are you interested in chipping in?
<manveru> I can help a bit, sure
<manveru> Not sure what the policy is yet though
<txdv> changing a single bit wont be that helpful, multiple bytes of change are expected
<Yxhuvud> IME uncontroversial PRs get merged pretty fast.
<manveru> Lol
<manveru> well, it's your choice, i'm not that experienced with crystal yet, even though it's so similar to ruby, but if it's just making sure that the PR is small and well-tested and uncontroversial, that i can do :)
<manveru> right now i'm porting my programming language from neko to crystal and having fun doing that
<Yxhuvud> hey, I'm not in charge. Just a very lowly contributor. The people in charge would be asterite and the other people at Manas.
<Yxhuvud> argentineans, so they should start coming online soon.
<manveru> heh, and elixir is from brazil
<manveru> go south america!
Kug3lis has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
akwiatkowski has joined #crystal-lang
Kug3lis has joined #crystal-lang
<bmcginty_> manveru: thanks. will look.
soveran has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Changing host]
soveran has quit [Ping timeout: 240 seconds]
<bmcginty_> Kug3lis: def finalize on a class gets called when an instance is GC'd, i fthat's what you were referring t earlier today.
<manveru> finalize doesn't run when the process exists though
<manveru> *exits
<manveru> fun fact: `crystal eval 'class X; def finalize; p :bye; end; end; 1335.times{ X.new }'` doesn't output anything, but with 1336 it does :)
<manveru> might also depend on the machine
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<bmcginty_> manveru: my bad. and it's odd. even given five or ten seconds of sleeping when finished, the gc never kicks in...
<manveru> well, GC only should run when there's too many objects
<manveru> but either way, you cannot rely on GC to call finalizers on program exit, at leat in no language i know of
<manveru> so having some callbacks like BEGIN/END would be cool in crystal :)
<manveru> oh, there is actually AtExitHandlers
<manveru> Kug3lis: ^-
<manveru> for some reason i can't compile a program using that on my machine...
<Kug3lis> manveru oh thanks man :)
<manveru> and fixed it :)
glenab has joined #crystal-lang
<Kug3lis> heh database stuff for crystal are so scarce...
bjz has joined #crystal-lang
glenab has quit [Ping timeout: 248 seconds]
gloscombe has quit [Quit: Lost terminal]
<FromGitter> <raydf> @Kug3lis, you can call a count aggregate funtion sql query with the same variables than the resultset call. https://crystal-lang.org/docs/database/index.html max_age = db.scalar "select count(*) from contacts"
<Kug3lis> raydf thanks :)
<FromGitter> <raydf> ```rows_returned = db.scalar "select count(*) from contacts"``` [https://gitter.im/crystal-lang/crystal?at=587381cf873d96e16d45693a]
<FromGitter> <raydf> this is very useful for paging situations
<FromGitter> <raydf> because you can count first and then use LIMIT clause for selecting a subset of data.
gloscombe has joined #crystal-lang
Kug3lis has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
FromGitter has quit [Ping timeout: 240 seconds]
Kug3lis has joined #crystal-lang
FromGitter has joined #crystal-lang
soveran has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Changing host]
holyheels has quit [Read error: Connection reset by peer]
holyheels has joined #crystal-lang
<manveru> so for shards there's no central repo?
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
Kug3lis has quit [Read error: Network is unreachable]
Kug3lis has joined #crystal-lang
<manveru> btw having Hash#[] be Hash#fetch is so much nicer, in ruby i usually had a refinement for that because it's so annoying
<Yxhuvud> You also have []? for when you want the other behaviour.
<manveru> aye, quite neat :)
<manveru> hmm, i'm trying to load a yaml file, add a key/value, and save it again
<manveru> `undefined method '[]=' for YAML::Any`
<manveru> guess i need to assert the type somehow?
<manveru> hm, solved that i think
Kug3lis has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Kug3lis has joined #crystal-lang
<manveru> so... converting YAML::Any#to_h may result in a bunch of types
<manveru> `undefined method 'find' for String (compile-time type is (Array(YAML::Type) | Hash(YAML::Type, YAML::Type) | String | Nil))`
* manveru has flashbacks to Go
<manveru> so i need a case statement there to assert it's an Hash
<FromGitter> <cschlack> Hi all!
<FromGitter> <cschlack> Is there a way to use a HTTP::Client with streaming (for HTTP::Request as well as HTTP::Response) without using the block syntax?
<FromGitter> <cschlack> I would like to open a HTTP::Client, stream the request body, then stream the response body, then close the connection.
<FromGitter> <cschlack> I can't use a block, because writing and reading the body is going to happen in callbacks (from a C library).
<FromGitter> <cschlack> I need something like mentioned in https://github.com/crystal-lang/crystal/pull/3406: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=58739d5a6c1635643c05df0a]
go|dfish has quit [Ping timeout: 264 seconds]
Kug3lis has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<manveru> hm, yeah, something is definitely strange about using case with tuples from yaml
<manveru> how can `case x; when {String, Hash}; p typeof(x); end` print `(Tuple(Array(YAML::Type) | Hash(YAML::Type, YAML::Type) | String | Nil, Array(YAML::Type) | Hash(YAML::Type, YAML::Type) | String | Nil) | Nil)`
<manveru> do i need to assign to another var in there?
<manveru> even then it won't work
<manveru> how can a {String, Hash} ever be nil?
Kug3lis has joined #crystal-lang
<manveru> it works when i add an additional nil check...
LastWhisper____ has joined #crystal-lang
LastWhisper____ has quit [Client Quit]
<manveru> this could be a tiny bit prettier i suspect... but no idea how
<manveru> it's pretty similar to Go in this respect, type assertions everywhere when handling yaml/json
<FromGitter> <sdogruyol> because dynamic data vs compiled languages
<manveru> still not sure how a tuple can be nil
<TheGillies> The elusive NilTuple
<FromGitter> <mverzilli> @manveru run this gist: https://gist.github.com/mverzilli/3112e642f5c2f9eb2d171cfeb75f09e3
<FromGitter> <mverzilli> I think it'll help you understand what's happening
<manveru> ah, so i don't understand that type syntax right yet
<manveru> thanks :)
soveran has quit [Remote host closed the connection]
unshadow has quit [Quit: leaving]
soveran has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Changing host]
LastWhisper____ has joined #crystal-lang
unshadow has joined #crystal-lang
<manveru> another question, since i'm thinking of changing the crystal package for NixOS, should libyaml be a dependency of crystal or should each user be responsible for providing one?
<Papierko-> manveru: How does ruby do it?
<Papierko-> Not guaranteed to be the correct way, but maybe a pointer (note that I have no idea about Nix)
Papierko- is now known as Papierkorb
<manveru> for the ruby package, yaml is optional, but on by default
cyjimmy264 has joined #crystal-lang
<manveru> i think that'd be a good compromise, since most people want things to work out of the box :)
Kug3lis has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
LastWhisper____ has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
LastWhisper____ has joined #crystal-lang
mark_66 has quit [Remote host closed the connection]
daekano_ is now known as daekano
soveran has quit [Remote host closed the connection]
kodotest[m] has quit [Remote host closed the connection]
M-mva1985 has quit [Remote host closed the connection]
acheron[m] has quit [Write error: Broken pipe]
braidn[m] has quit [Write error: Connection reset by peer]
TheGillies has quit [Read error: Connection reset by peer]
<unshadow> So, I got this project: https://github.com/bararchy/fiber_pool, trying to create a multi-threaded fiber pool. but, it seems it crashes even on specs with invalid mem address, and other mem allocation issues, can someone help me figuring this out ?
<RX14> unshadow, threads don't work
<RX14> is the long and short of it
<Papierkorb> Threading in Crystal 101: Don't
<RX14> IO and GC and fibers don't work in threads
<RX14> so just don't
<RX14> Thread.new == segfault
<RX14> basically
<unshadow> That makes sense I guess hahaha
<unshadow> Hm.... so fiber_pool without multi-threading is kinda useless :\
<unshadow> guess I'll delete the project
<Papierkorb> Also, fibers are almost free compared with threads, I don't know any benefit of using a pool for them
<unshadow> If threads are not supposed to be touched, why not have them as "private" inside the STDlib or raise "dont do this!!" if Thread is called
<Papierkorb> The only thing I added was automatic naming them for debugging purposes
<unshadow> Papierkorb: the benefit was having multiple threads each having x fibers doing some work. if threads aren't usable, then I guess you are right
<Papierkorb> That's what I expect the final Crystal-internal implementation to do by default
pduncan has joined #crystal-lang
braidn[m] has joined #crystal-lang
LastWhisper____ has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
LastWhisper____ has joined #crystal-lang
DeBot has quit [Remote host closed the connection]
DeBot has joined #crystal-lang
soveran has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Changing host]
TheGillies has joined #crystal-lang
M-mva1985 has joined #crystal-lang
acheron[m] has joined #crystal-lang
kodotest[m] has joined #crystal-lang
soveran has quit [Ping timeout: 240 seconds]
Guest18334 is now known as Cyrus
Cyrus has quit [Changing host]
Cyrus has joined #crystal-lang
cyjimmy264 has quit [Ping timeout: 256 seconds]
<FromGitter> <exts> Will crystal ever have something like this in the language? http://php.net/manual/en/reflectionmethod.invoke.php If not that's fine, i'll either stick w/ single action classes or use case expressions to solve something similar.
<FromGitter> <sdogruyol> @spalladino nice labeling
<RX14> @exts no it will not
<RX14> you can sort of use macros to do what you want
<RX14> what exactly do you need this for?
Raimondi has quit [Quit: WeeChat 1.6-dev]
LastWhisper____ has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
sirus has left #crystal-lang [#crystal-lang]
LastWhisper____ has joined #crystal-lang
<FromGitter> <martinium> @RX14 I am looking to create a web interface that pipes inputs to a command line app running on a server. What would be the recommended way to go about this?
<FromGitter> <exts> i'll show you in about 30 minutes when i upload it to github, i'm from the php world so I haven't really adapted to the ruby way of things so I approach mvc a little differently. ⏎ ⏎ With that said I do have a question, is there a way to do one liner initialize methods for classes that don't have a body?
LastWhisper____ has quit [Client Quit]
<FromGitter> <exts> i worded that weirdly, i meant to say: is there a way to do one liner initialize methods for those without a body
<RX14> @martinium well use Process to create a Process which uses the IO from the HTTP request
<RX14> Process will accept an IO as stdin
<RX14> you can also use context.response as stdout if you want
<FromGitter> <martinium> So Process can send input to command line app and use context.response for the output
<RX14> yes
LastWhisper____ has joined #crystal-lang
<RX14> you might want to filter the process's output though
<BlaXpirit> unshadow, didn't i tell you about all this right away?
<RX14> the most expensive part of creating fibers is allocating memory
<RX14> and the crystal scheduler keeps a pool of stacks around
<RX14> so allocating fibers is essentially free
<BlaXpirit> told that as well
akwiatkowski has quit [Ping timeout: 264 seconds]
Raimondi has joined #crystal-lang
<RX14> @spalladino are there any docs on the new tags?
<FromGitter> <bcardiff> @RX14 Coming soon
<RX14> thanks
<FromGitter> <bcardiff> we are tagging and discussing new tags over some open issues and later spalladino will drop some guidance on using them.
LastWhisper____ has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
LastWhisper____ has joined #crystal-lang
A124 has quit [Quit: '']
LastWhisper____ has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
A124 has joined #crystal-lang
LastWhisper____ has joined #crystal-lang
<FromGitter> <andrewhamon> Hey guys! I've been working on a HTTP router implemented as a normal HTTP::Handler/middleware
<FromGitter> <sdogruyol> @andrewhamon that's cool
<FromGitter> <andrewhamon> And I'm really not sure the best way to add additional context to the context object in a way that is friendly to other middleware that might want to do the same
<FromGitter> <andrewhamon> In, i.e. Rack, its easy since its just a Hash that you can stick anything in
<FromGitter> <andrewhamon> But in Crystal thats not an option. The available options are: ⏎ ⏎ 1) Monkey patch `HTTP::Server::Context` ⏎ 2) Subclass `HTTP::Server::Context` ⏎ 3) Wrap `HTTP::Server::Context` [https://gitter.im/crystal-lang/crystal?at=5873e0de873d96e16d47c455]
<FromGitter> <sdogruyol> @andrewhamon 1 is the way to go
<unshadow> BlaXpirit: Yes, you did tell me making a fiber pool is meangless, that's why I wanted to add multi-threading to it, which loops around back to what RX14 and I was talking about.
<FromGitter> <andrewhamon> @sdogruyol so just monkey patch and hope I don't clobber anything?
<FromGitter> <sdogruyol> @andrewhamon clobber? why?
<FromGitter> <sdogruyol> i use that way in Kemal take a look at https://github.com/kemalcr/kemal/blob/master/src/kemal/context.cr
<FromGitter> <andrewhamon> Well, for example, Kemal defines a params method on context
<FromGitter> <andrewhamon> It seems *extremely likely* that some other lib or middleware might also want to do that as well
<FromGitter> <sdogruyol> how come?
<FromGitter> <sdogruyol> i mean if you dont mix two frameworks that's not likely possible
<RX14> but what if you do want to mix frameworks
<FromGitter> <andrewhamon> ^ yeah
<RX14> for example if you wan tto migrate to another framework
<FromGitter> <sdogruyol> that's another problem though :D
<FromGitter> <andrewhamon> Or if you have to not-quite-frameworks with a bit of overlapping functionality
<RX14> monkey-patching stuff in to the Context isn't really a good idea
<FromGitter> <bcardiff> Since neither the RequestProcessor does not allow to build other context https://github.com/crystal-lang/crystal/blob/master/src/http/server/request_processor.cr#L36 nor the Http::Server allows other processors https://github.com/crystal-lang/crystal/blob/master/src/http/server.cr#L121 you are stuck with monkey patching
<FromGitter> <sdogruyol> yeah
<RX14> yes but that could change
<FromGitter> <andrewhamon> I guess its no more of a problem that it is with Rack
<FromGitter> <bcardiff> the design could be improved
<FromGitter> <bcardiff> totally
<RX14> you could make HTTP::Server generic for example
<Papierkorb> I agree RX14, sdogruyol, have you considered creating a generic extension mechanism for this use-case one could put into the stdlib?
<FromGitter> <sdogruyol> not really
<FromGitter> <sdogruyol> open for suggestions :P
<unshadow> What's crystal's "attribute_accesor" synatx ?
<FromGitter> <bcardiff> changing HttpServer to generic might have other limits. extensions might not me composed even if there concerns are orthogonal to each others.
<RX14> you would make HTTP::Server generic and take a Context type which must extend from the original type, extensions then provide a module which you could mix in to the new Context type you create.
<FromGitter> <sdogruyol> @unshadow :property ?
<RX14> Frameworks would provide their own ready-made types
<Papierkorb> Something like Hash(Class, Object) <- that won't work right now sadly, but something like that could work. It's a bit iffy to work with, but it'd work with anything and clashes are pretty much impossible
<FromGitter> <sdogruyol> property
<RX14> with the modules pre-included
<FromGitter> <andrewhamon> RX14 in that case how would two libs, each with their own Context types, share a HTTP server?
<RX14> i said they provide mixins
<RX14> you just mix in both if you want 2 libs
<Papierkorb> Then Kemal could add an instance of Kemal::MyContext, and another one would add Theirs::MyContext, and nothing clashes
<FromGitter> <sdogruyol> yeah
<FromGitter> <andrewhamon> I see, and it would be namespaced be the class in the theoretical Hash(Class, Object)?
<RX14> Kemal::ContextMixin and then just `class Kemal::Context < HTTP::Context; include ContextMixin; end;`
<Papierkorb> andrewhamon, in that pseudo-code, yes. Use the Class itself as key. I think I saw this in other languages.
<FromGitter> <andrewhamon> I see, that would be pretty neat
<Papierkorb> Though say `@params : Array(Param)`, with the object mapping to itself, and everyone just sub-classes the Param. And then a method which finds an object by its class. More hacky, but that could work with current Crystal
<Papierkorb> though I guess you could also do Hash(String, Param) then, you "just have to be careful" that you choose unique names *hides*
<FromGitter> <andrewhamon> A much less technical solution would be to just get everyone to namespace their monkey patched attentions
<FromGitter> <andrewhamon> like `kemal_params` instead of `params`
<FromGitter> <andrewhamon> ;)
<RX14> context.kemal_params?
<RX14> no thanks
<FromGitter> <sdogruyol> hahahaha
<FromGitter> <andrewhamon> Well, I need `params` for *my* lib, but I can't in good conscience use it
<FromGitter> <sdogruyol> i laughed hard :D
<FromGitter> <andrewhamon> Heres what I'm working on btw
<FromGitter> <andrewhamon> https://github.com/andrewhamon/crux
<Papierkorb> macro method_missing(name); params[{{ name.stringify }}]; end #yolo
<FromGitter> <andrewhamon> So I'll probably monkey patch and add `crux_params`
<bmcginty_> Is there a way to get Lib.func(out param) to have param initialized ot zero before running?
<bmcginty_> Sorry, that was kind of goofy sounding. I've got a c library that has me pass a pointer to some initialized memory. I need this memory zeroed out, though, as it's (in the deep dark recesses of c) a pointer to a pointer already...and I need to check that the pointer is null when teh library function finishes.
<Papierkorb> bmcginty_: I don't think so
<RX14> @andrewhamon why not call it params for now, while you float the idea for extensibility on the github issue tracker
<bmcginty_> Papierkorb: erg. okay. Thanks. think I'll go look for how the out stuff is implimented.
<FromGitter> <andrewhamon> @RX14 Sounds good to me!
<FromGitter> <bcardiff> @bmcginty_ if you want out with an initial value you might just want a pointer.
unshadow_ has joined #crystal-lang
<FromGitter> <bcardiff> `p = 0; Lib.func(pointerof(p)); ....`
pduncan has quit [Ping timeout: 240 seconds]
unshadow has quit [Ping timeout: 240 seconds]
triangles2 has joined #crystal-lang
triangles has quit [Ping timeout: 258 seconds]
soveran has joined #crystal-lang
bjz has joined #crystal-lang
soveran has quit [Ping timeout: 248 seconds]
soveran has joined #crystal-lang
soveran has quit [Changing host]
soveran has joined #crystal-lang
akwiatkowski has joined #crystal-lang
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
gloscombe has quit [Quit: Lost terminal]
triangles2 has quit [Quit: Leaving]
pduncan has joined #crystal-lang
<manveru> i want to make a list of classes that inherited my class, i tried like this: `class X; @@x = [] of X; macro inherited; @@x << self; end; end`
<manveru> but then i get `no overload matches 'Array(X)#<<' with type Hello:Class` for `class Hello < X; end`
<manveru> i assume because at that point it's not inherited yet... but i can't make a `[] of Class` because crystal says that's too generic?
<manveru> so... how would i do that instead?
<FromGitter> <MaxLap> Since you are putting types in that array, i think you need `[] of X.class`? Pretty new to the language
<FromGitter> <MaxLap> note that the code won't work like that for what you are doing. the @@x is duped between each subclasses. You would need your macro to do something directly on X
<manveru> well, i plan to enumerate the methods on each subclass and print them first :)
<manveru> your suggestion is already a good point
<FromGitter> <MaxLap> class X; @@x = [] of X.class; macro inherited; class ::X; @@x << {{@type.name}}; end; end; end
<FromGitter> <MaxLap> I think this is what you would want
<FromGitter> <MaxLap> `class X; @@x = [] of X.class; macro inherited; class ::X; @@x << {{@type.name}}; end; end; end`
<manveru> pretty close, but @@x seems to be empty on every invocation, so i think inherited is called on the child?
<manveru> it works with a constant instead
soveran has quit []
<FromGitter> <MaxLap> Yes, it's copied for every class, and type is the child, that's why my suggestion was adding them specifically to the class ::X. Yeah, the constant is probably easier
<manveru> sorry, i missed the ::X
<manveru> that makes a lot more sense :)
<manveru> thanks
<manveru> it's a bit hard for me getting used to this kind of compile-time-only metaprogramming... it's like a mix of what i saw in elixir and go
<manveru> but i'm way more familiar with ruby ^^;
<FromGitter> <MaxLap> Yeah, i understand. And the error messages aren't always as helpful as they could be
<RX14> you can use .subclasses in macros
<RX14> for example
<RX14> {{Foo::Bar.subclasses}}
<RX14> and thats all your subclasses
<manveru> !
<RX14> SUBCLASSES = {{Foo::Bar.subclasses}} might work
<manveru> indeed
<RX14> actually that wont work right away
<manveru> well, it works here
<RX14> it won't work like this though: https://carc.in/#/r/1jtn
<manveru> gives me `[{Hello, ["hi"]}, {There, ["there"]}]`
<RX14> huh
<manveru> true that
<manveru> but i don't know how to handle this empty array stuff in macros yet
<RX14> well
<RX14> it shouldn't be an epty array
<RX14> thats the problem
<RX14> the macro is running too early
<RX14> oh
<RX14> oops
<manveru> if there was no method on any of these classes, it'd be empty
<RX14> my bad
<RX14> typoed
<manveru> sorry, my code is wrong for that statement
<RX14> it does work
<RX14> I did Foo instead of Base
<manveru> X.subclasses.map{|c| c.methods.map(&.name.stringify) }
<RX14> i was expecting it to fail because of macro ordering
<RX14> but
<manveru> that'd fail if there were no methods, right?
<RX14> no
<RX14> because methods would be []
<RX14> map works on that fine
<manveru> `Syntax error in expanded macro: macro_4498912240:1: for empty arrays use '[] of ElementType'`
<manveru> if the macro evaluates to [], then there's nothing i can do
<RX14> ytou would get that error with no subclasses
<RX14> if the array is part of a macro method change it's never going to get pasted
<RX14> chain*
<RX14> an empty array by itself isn't an error
<RX14> macros run in their own programming language
<RX14> which is dynamically-typed
<RX14> it's only when you do {{}} on an empty array
<RX14> it gets pasted as [] into crystal code
<RX14> which is a compile error
akwiatkowski has quit [Quit: Konversation terminated!]
<manveru> exactly
<FromGitter> <MaxLap> Well, you could always annotate the type of the array
<manveru> so... i'd have to return an empty string or something?
<RX14> no
<RX14> if X.subclasses is empty you get a compile error
<RX14> if c.methods is empty you shouldn't
<RX14> wait hmm
<RX14> oh yes you would i guess never mind
<manveru> that's what i get :P
<Yxhuvud> can't you do [{{..}}] of Foo
<RX14> you can
<RX14> i was just thinking thats not required
<manveru> even if it's nested?
<Yxhuvud> or of self, perhaps?
<BlaXpirit> manveru, even if nested it's ok
<Yxhuvud> (it'd be self.class)
<manveru> i'm not sure i understand
<manveru> when my macro returns [[], []], how do i get `[[] of self.class, [] of self.class] of self.class` in the code?
<BlaXpirit> oh..
<RX14> you can do the of on the root
<RX14> and hope it propagates?
<BlaXpirit> but the inner ones are still a syntax error
<RX14> well it shouldn't be
<manveru> i tried like `CHILDS : Array(Array(self.class))`
<RX14> [[]] of Array(Foo) should work tbh
<RX14> manveru, you need to use of
<RX14> it still probably wont work though
<RX14> its worth a go though
<manveru> that's an unexpected token as well
<BlaXpirit> RX14, i mean the compiler might add this workaround for convenience but strictly speaking it makes no sense
<RX14> oh yes it would
<RX14> darn macros
<manveru> hm, it should actually be Array(Array(String))
<manveru> but that doesn't change the compile error
<manveru> the `of` is an unexpected token
<manveru> and i guess constants can't have type declarations
<RX14> yes thats because macros need to be lexable by themselves
<BlaXpirit> well this turned hopeless pretty quickly
<RX14> so you need to surround the thing with {% begin %} {% end%}
<RX14> so the whole array declaration
<BlaXpirit> you can wrap it in {%begin%}{%end%} i guess but that won't save you from the inner syntax errors
<RX14> including the of is inside the {%begin%} block
<RX14> macro ArrayLiterals should have a type
<FromGitter> <MaxLap> I suggest `{{ Project.subclasses.id + " of X.class"}}`
<RX14> that would work I guess
<FromGitter> <MaxLap> but i may not understand exactly what is desired
<FromGitter> <MaxLap> wops, replace project with X
<FromGitter> <MaxLap> testing with classes i have in my code
<manveru> the {%begin%}{%end%} seems to work for one level at least
<manveru> returning an array of arrays of strings where some of the arrays may be empty seems still hard
<manveru> CHILDS = {{ "[" + X.subclasses.map{|c| "[" + c.methods.map(&.name.stringify).join(", ") + "] of Array(String)" }.join(", ") + "] of Array(Array(String))" }}
<RX14> macros are "fun"
<manveru> that simply returns a string :P
<RX14> call .id on it
<RX14> the whole thing
<manveru> oh!
<manveru> magic
<RX14> can you paste your macro code?
<RX14> i might be able to clean it up for you
<RX14> oh its right there
<RX14> nvm
<manveru> you just saw it, apart from the id :)
<manveru> it's horrible
<manveru> but i think i can get rid of the join and "[" stuff
<manveru> let me try first
<manveru> CHILDS = {{ X.subclasses.map{|c| c.methods.map(&.name.stringify).id + " of Array(String)" }.id + " of Array(Array(String))" }}
<manveru> not pretty, but i think i understand it a bit more
<RX14> are you sure it's not an Array(Array(String))?
<manveru> the outer one?
<RX14> instead of an Array(Array(Array(String)))
<RX14> manveru, yes
<RX14> [] of String == Array(String)
<manveru> you know, i haven't tried it with any methods yet...
ruby has joined #crystal-lang
<manveru> CHILDS = {{ X.subclasses.map{|c| c.methods.map(&.name.stringify).id + " of String" }.id + " of Array(String)" }}
ruby is now known as Guest84482
<manveru> you're right
<manveru> anyway, i gotta get some sleep, thanks a lot guys
<RX14> wait a sec
<RX14> manveru, something like https://carc.in/#/r/1juj could be made to work
<RX14> and it's not as ugly
<manveru> hmm
<RX14> manveru, progress? https://carc.in/#/r/1juq
<RX14> manveru, YAY!
<manveru> :D
<RX14> ok
<RX14> gald that's sorted
<manveru> yeah, that might be a bit better :)
<RX14> easier to read
<manveru> so... this stuff is like string interpolation
<RX14> macros have some subtle rules on when they're executed
<manveru> just a bit fancier
<RX14> manveru, yup
<RX14> it's string interpolation
<manveru> i hope this doesn't reach C++ levels
<RX14> well it seems to be working out so far
<RX14> if macros get ugly we'll rethink them
<Yxhuvud> well, with generics and other stuff, shouldn't be neede, hopefully.
<manveru> well, my particular wish can't be fullfilled otherwise i fear
<RX14> manveru, which wish?
<manveru> since i don't see anywhere in the language a way to get the methods of a class otherwise
<RX14> yeah well it's a compiled language so
<RX14> you generally don't want that info
<manveru> had to look through the specs to find that you can call methods in a macro
<RX14> macros are a complex topic
<manveru> searching the api docs for methods was not successful
LastWhisper____ has quit [Ping timeout: 260 seconds]
<RX14> so the docs are there just not very well oriented for beginers
<manveru> i understand
<manveru> i'm moving a bit fast, just wanted to make a proof of concept
<Yxhuvud> I doubt most people move into macros on their second day or whatever it is :)
<manveru> it is ^^;
<RX14> manveru, what do you need this data for anyway?
<manveru> well, i'm trying to build a router like i did in innate
<RX14> so you want to be able to call these methods?
<manveru> well, if a request matching the method name was made
<RX14> well luckilly enough you can access constants from macros
<manveru> so if you go to /hello/there i want to call Hello#there
<manveru> yeah
<RX14> you'd have to generate the routes from the methods
<manveru> exactly
<manveru> they are static during runtime
<RX14> instead of recieving a request and calling stuff dynamically
<RX14> but it probably can be done
<RX14> I just implemented a router like
<RX14> route "GET", "/foo", FooController.index
<RX14> which creates a new FooController and calls index on
<RX14> having a route listing like that is easier
<RX14> but it can probably be done without
<manveru> yeah
<manveru> i don't like writing routes ^^;
<RX14> well i wish you luck
<manveru> anw, it's a fun project
<RX14> it's boilerplate but it can be really reduced
<RX14> and there's a plus to haveing all your routes in 1 place
<RX14> so I prefer just a draw_routes method
<manveru> well, i got used to having implicit routes with nitro
<manveru> anw, we'll see how it goes, i think it's a nice way to learn crystal
<Yxhuvud> manveru: how about a macro inside the class, like macro defroute or so that generates a method definition as well as register it as a route?
<manveru> that's possible too, but will make it harder to treat it like a normal class?
<manveru> not sure about that, do doc generation and the like ignore macros?
<RX14> no
<RX14> docs expand macros
<RX14> and then document the generated tree
<RX14> so if you expand to a def
<RX14> you'll get docs just fine
<manveru> Then I shall try that too
<manveru> But tomorrow :)
<manveru> gn8
<RX14> night