jhass changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.7.5 | Fund Crystals development: http://to.ly/TtGw | Paste > 3 lines of text to https://gist.github.com | GH: https://github.com/manastech/crystal - Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/ | Logs: http://irclog.whitequark.org/crystal-lang
dbackeus has quit [Remote host closed the connection]
dbackeus has joined #crystal-lang
<dzv> does anyone have an example of using parallel()?
havenwood has quit [Quit: Textual IRC Client: www.textualapp.com]
<dzv> why don't any of the fibers run? http://carc.in/#/r/afo
ryanworl has joined #crystal-lang
ryanworl has quit [Client Quit]
NeverDie has quit [Read error: Connection reset by peer]
NeverDie has joined #crystal-lang
blue_deref has joined #crystal-lang
dbackeus has quit [Remote host closed the connection]
wonderbreadz has joined #crystal-lang
kulelu88 has joined #crystal-lang
kulelu88 has left #crystal-lang [#crystal-lang]
ylluminate has quit [Ping timeout: 260 seconds]
ylluminate has joined #crystal-lang
lokulin has joined #crystal-lang
lokulin has quit [Changing host]
<dzv> thanks
NeverDie has quit [Quit: I'm off to sleep. ZZZzzz…]
sailorsw_ has joined #crystal-lang
sailorsw_ has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
miah has quit [Ping timeout: 264 seconds]
miah has joined #crystal-lang
havenwood has joined #crystal-lang
havenwood has quit [Remote host closed the connection]
ddfreyne has quit [Ping timeout: 252 seconds]
havenwood has joined #crystal-lang
eam has quit [Ping timeout: 250 seconds]
eam has joined #crystal-lang
elbow has quit [Ping timeout: 272 seconds]
ddfreyne has joined #crystal-lang
elbow has joined #crystal-lang
sailorswift has joined #crystal-lang
havenwood has quit [Ping timeout: 250 seconds]
BlaXpirit has joined #crystal-lang
sailorswift has quit [Read error: Connection reset by peer]
sailorswift has joined #crystal-lang
<strcmp1> you can tell two threads got together to spell that filename
<jhass> dzv: to elaborate on why your example doesn't work: parallel is a macro, as such its parameters are interpreted as code, if you pass a variable you pass code referencing a variable, not what the variable points to. Think of it as a template and the parameter gets literally inserted into it
strcmp1 has quit [Quit: Leaving]
<dzv> is it possible to have a dynamic array of things and pass it to parallel?
kyrylo has joined #crystal-lang
<kyrylo> Hi! Does anyone know if there's crystal-mode for Emacs?
nahtnam has quit [Quit: Connection closed for inactivity]
<jhass> dzv: I don't think so
<kyrylo> jhass, thanks a lot, you're a life saviour!
trapped has joined #crystal-lang
<kyrylo> jhass, shall I add that to the wiki?
<trapped> is it me or the compiler prints wrong line numbers? (perhaps they're the line numbers for the macro-expanded version of the code?)
sfcgeorge has joined #crystal-lang
<jhass> maybe, got an example?
<jhass> kyrylo: no idea, I mean I just put emacs crystal into github search
<jhass> dzv: btw just do a.each do |item| spawn do work_on(item) end end
<jhass> dzv: plus some channel stuff if you need to block for the results
<kyrylo> jhass, what editor do you personally use?
<jhass> sublime
<kyrylo> But it can't brew coffee!
<jhass> I already have an OS, don't need a second one ;P
<kyrylo> Virtualisation, though
<jhass> I tend to use chroots/containers these days (systemd-nspawn <3)
elia has joined #crystal-lang
mrx1 has joined #crystal-lang
elia has quit [Quit: Computer has gone to sleep.]
<trapped> the wrong line numbers thing is quickly getting kinda annoying
<trapped> "Error in ./src/controllers/request.cr:95: undefined method '+' for Nil" but my source file has 89 lines
<jhass> trapped: if you got some minimal example, a bug report would be great
NeverDie has joined #crystal-lang
elia has joined #crystal-lang
<trapped> jhass: i wish i could share the whole source code
blue_deref has quit [Quit: bbn]
<trapped> here's some code and the error it's giving me, jhass https://gist.github.com/trapped/265d1fb0a926f55125a5
<trapped> note the line number
<jhass> yeah okay, it's a bit odd that it has 20+, it should say 83
<jhass> but that's one it can't point out earlier usually
<jhass> there's no for
elia has quit [Quit: Computer has gone to sleep.]
<jhass> data["cells"].each do |q|
<trapped> `for q in data["cells"]` you mean i should've done "data["cells"].each do..."
<trapped> yeah
<trapped> i thought the for v in a thing applied not only to ecr
<trapped> i guess it doesn't
<jhass> $DBPATH sounds like it wants to be constant btw
<trapped> it's declared in another file
<trapped> it's just a file path
<jhass> exactly
<jhass> no need to have it as a global
<jhass> it won't change during runtime
<jhass> Also prefer "string #{interpolation}" over "string" + concatenation, eg. "#{DB_PATH}/#{new_id}"
<jhass> no idea why you do next_id as String
<trapped> it's a relic from the past now
<trapped> since i couldn't determine where the Nil error was i tried to cast everything to string
<jhass> probably want to make a json_mapping for the request
<jhass> res shouldn't be nil after the if, the .try's on it shouldn't be needed
<trapped> i guess that'd help
<trapped> jhass: res won't be nil but the fields are nilable
<jhass> you .try on res though
<jhass> not on the fields
mrx1 has left #crystal-lang ["Leaving"]
<trapped> isn't that the way .try &. is done
<jhass> no
<jhass> try is for when the thing you call it on might be nil
<jhass> >> {"a", nil}.try &.upcase
<DeBot> jhass: in line 4: undefined method 'upcase' for {String, Nil} - http://carc.in/#/r/aic
<jhass> >> {"a", nil}.sample.try &.upcase
<DeBot> jhass: Error in line 4: undefined method 'sample' for {String, Nil} - http://carc.in/#/r/aid
<jhass> meh
<jhass> you get it
<jhass> regarding your error, what's the definition of DBPATH?
<trapped> DBPATH = "#{__DIR__}/requestdb"
<trapped> just a string
<jhass> mmh, are you sure? I don't notice another codepath to Dir.exists? besides I guess Dir.entries
dbackeus has joined #crystal-lang
<trapped> it's in another file, lemme add that
<trapped> updated
<jhass> mmh, actually no, that doesn't even call it
<jhass> aaah
<trapped> the infamous app.cr
<jhass> I should've noticed that the error isn't even in request.cr :P
<jhass> so, && binds stronger than method call, Dir.exists? DBPATH && File.directory? DBPATH -> Dir.exists?(DBPATH && File.directory?(DBPATH))
<trapped> ah
<jhass> so you need to add () to disambiguate, Dir.exists?(DBPATH) && File.directory?(DBPATH)
<trapped> yeah
<trapped> now that that's solved i gotta write the damn json_mapping so that it stops complaining about me calling .empty? on (Int32 -> Void)
<jhass> I think you meant Dir.mkdir or even Dir.mkdir_p instead of Dir.new
<trapped> yeah i completely forgot that libc uses mkdir
jhass changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.7.5 | Fund Crystals development: http://is.gd/X7PRtI | Paste > 3 lines of text to https://gist.github.com | GH: https://github.com/manastech/crystal | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/ | Logs: http://irclog.whitequark.org/crystal-lang
<kyrylo> When I `raise` an exception, is it possible to extract filenames from the exception's backtrace? It looks like Crystal doesn't provide such information
sailorswift has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
<jhass> no, I guess mainly because we don't generate LLVM 3.6 compatible debug info
<kyrylo> Aww
<jhass> asterite: http://carc.in/#/r/aau nobody opened an issue for this, so I will unless I'm missing the stack overflow somewhere?
<kyrylo> consider this frame "main +108 [0]" What does the [0] part mean?
<kyrylo> Also, why is the very first frame anonymous? https://gist.github.com/kyrylo/7de8d7d9d823482db22d#file-gistfile1-txt-L4
<BlaXpirit> lol these tracebacks are honestly some of the worst :(
dbackeus has quit [Remote host closed the connection]
dbackeus has joined #crystal-lang
dbackeus has quit [Client Quit]
<kyrylo> Seriously, that "[0]" thing is appended to every frame :)
leafybasil has quit [Remote host closed the connection]
<kyrylo> Thanks. It looks like it's a pointer address, isn't it? "fname" probably means filename, but it doesn't look like a filename and "offset" is a line number
<jhass> unw_get_proc_name -- get name of current procedure
<jhass> so more function name
<jhass> and I guess IP instruction pointer, pc program counter (which is the same thing)
<kyrylo> "functionName" then I guess
<kyrylo> ah
<kyrylo> right
<kyrylo> :)
NeverDie has quit [Quit: I'm off to sleep. ZZZzzz…]
maxdeviant has joined #crystal-lang
<maxdeviant> Having a bit of trouble getting some JSON data into a usable format. I'm doing `JSON.parse(File.read("../path/to/file"))`, but I'm not sure how to get it into a usable format from there
<maxdeviant> (Trying to do a key lookup, which I expected would be something like `json_data["key"]`, but all I get is `undefined method '[]' for Nil (compile-time type is (Nil | String | Int64 | Float64 | Bool | Hash(String, JSON::Type) | Array(JSON::Type)))`
<BlaXpirit> maxdeviant, json could be anything
<BlaXpirit> for example, the whole json document could consist of just "null"
<BlaXpirit> so the result would be "nil
<jhass> ?json
<DeBot> jhass: Nothing known about json.
<jhass> mmh, didn't I set something?
<nopc0de> jhass I'm still having trouble with https://gist.github.com/nopc0de/e2072de8716b5539a160
<nopc0de> Latest version of crystal insatlled
<jhass> maxdeviant: try json_mapping if your data is somewhat structured
<jhass> nopc0de: is that the debian curl?
<nopc0de> default osx curl
<jhass> ah, so nothing I can try
<jhass> you're sure you use the head compiler? what does command_you_use_to_compile_the_example -v say?
<jhass> ?json_union maxdeviant
<nopc0de> Crystal 0.7.5 [4288b21] (Fri Aug 7 22:11:15 UTC 2015)
* jhass slaps DeBot
<jhass> mmh, weird
<maxdeviant> jhass, trying to figure out how I would use either of those. json_mapping sort of makes sense to me, but I'm unsure how I would use the macro
<jhass> nopc0de: you might want to comment on https://github.com/manastech/crystal/issues/1077
<jhass> ?json_union
<jhass> mmh, whatever
<maxdeviant> jhass: Derp, my GitHub was pointing at an old revision of that file. One without any comments
<maxdeviant> jhass, alright, look's like it's working. Thanks for your help!
<maxdeviant> Next time I'll make sure that I'm on the master branch, cause that probably would have answered my questions :P
<jhass> no worries, yw :
havenwood has joined #crystal-lang
elia has joined #crystal-lang
oal has quit [Remote host closed the connection]
elia has quit [Quit: Computer has gone to sleep.]
elia has joined #crystal-lang
elia has quit [Client Quit]
leafybasil has joined #crystal-lang
<asterite> jhass: about that carc.in example with array :: Array(Int32), that makes array have garbage, a segmentation fault is what will happen in %99.9 of the cases
<jhass> asterite: but I mean it's nowhere used? def get(..., *handlers
<asterite> Ah, let me check
leafybasil has quit [Ping timeout: 250 seconds]
<asterite> seems like a stack overflow, the "next" of the handler points to itself?
<asterite> `handler.next = handler`
<jhass> ah, that makes sense
<asterite> we should definitely make something about stack overflows. I'll add it to the roadmap so it can't go away :-)
<jhass> good
<jhass> I agree that we also should do something about usable backtraces btw
<jhass> but I guess that mandates llvm 3.6 (or 3.7) debug info first
<asterite> Yes
leafybasil has joined #crystal-lang
<jhass> asterite: that's a bit sad about Errno, it means 99% of the proper code catching Errno will look at .errno and reraise and 80% of code catching Errno at all will swallow unexpected cases
<kyrylo> Sorry, seems like the JSON module cannot "generate" JSON, can it?
<jhass> sure it can
<jhass> >> {"foo": "bar"}.to_json
<DeBot> jhass: Error in line 4: undefined method 'to_json' for Hash(String, String) - http://carc.in/#/r/ajv
<jhass> >> require "json"; {"foo": "bar"}.to_json
<DeBot> jhass: # => "{\"foo\":\"bar\"}" - http://carc.in/#/r/ajw
<kyrylo> Oh
<kyrylo> I was expecting JSON.generate
<kyrylo> Thanks
<jhass> to_json / from_json are pretty much the preferred interfaces
<kyrylo> Thanks. Sounds extreme =)
<asterite> jhass: but how frequent is to catch Errno? I must admit that I never (that is, zero times) catched Errno in my life
<jhass> so you do the full suite of existence, permission & type checks before you open a file or directory?
<asterite> Of course I shouldn't decide things for the language based on my experience, but it's not like we are not turing-complete here
<jhass> or think about IO timeouts you want to retry
<asterite> I think we'll find other ways to do that. Maybe Errno will disappear, other languages don't have Errno, they have specific exceptions
<asterite> but not specific exceptions for each of the errno codes
<jhass> that'd be fine by me too
<jhass> though if you'll do it properly you'll likely end up with a comparable amount
<jhass> whether they're now called Errno::Timeout or TimeoutError, who cares
<asterite> I'm not sure. Do you think each errno code maps to just one exception? Do you always need to distinguish between all of them at once?
<jhass> not always, but there are cases where you want to distinguish
<asterite> but for those cases maybe there will be different exceptions. We'll probably have to analyze it in detail
<asterite> but other languages (for example Java and D) do just fine without a massive errno exception hirarchy
<jhass> well yes, let's have a look at the nice list we have in https://github.com/manastech/crystal/blob/master/src/errno.cr
<jhass> which codes would get the same exception?
<asterite> EISDIR needs an exception?
<asterite> ENFILE and EMFILE might be merged
<asterite> Maybe EMLINK too, in the above (I don't even know when those happen)
<jhass> but that's useful information already
<jhass> ENFILE, I probably can't recover, the system is overloaded
<asterite> The thing is, when you have an operation, you don't expect all of Errno error codes, just some. Then you classify those into exceptions you already have (or create), and I bet you'll end up with a smaller hierarchy
<jhass> with EMFILE I can see if I can close some files
<jhass> I mean the kernel devs aren't stupid, they won't introduce new error codes if they don't provide a useful distinction from some other error code
<jhass> in fact I already often wished for even more specific codes
<jhass> for example you get EPERM for all sorts of stuff
<asterite> For example, take a look at java's FileInputStream
<asterite> When you create one, possible exceptions are FileNotFoundException and SystemSecurityException
<jhass> yeah, that throws a generic IOError "something went wrong"
<asterite> Um, SecurityException
<asterite> while libc's open has like 20 different ERRNOs
<asterite> But I know ruby is closer to unix in this sense and allows you to go deeper than java (maybe because java tries to abstract all of that)
<asterite> I really have to discuss this with waj, or we can continue the discussion in #445
<jhass> Whether I couldn't open the file because it's actually a directory or because I can't read it is very useful option
<jhass> *information
<jhass> it allows to generate actually useful error messages to the user
<jhass> instead of a generic "couldn't open it"
<jhass> or relying on the exception message and displaying that to the user (bye nice i18n)
<jhass> or doing all the checks the OS already does for me in advance
<asterite> Yes, but the current Errno exception gives you that information. Creating a specific errno class, always, regardless of whether the user actually wants to know that much, bloating the binary and slowing down the compiler seems like a bad thing to do
<asterite> Another answer for the above could also be: if we can make the compiler faster in this sense, we might consider changing this
<asterite> :-)
<jhass> I guess the compromise could be to have more generic error classes but have methods on them to determine the specific error
<asterite> Yes, that's another alternative
<asterite> Got to go, bye!
<jhass> rescue e : FileAccessError; case e.reason; when :is_directory; when :permission_denied
elia has joined #crystal-lang
NeverDie has joined #crystal-lang
NeverDie has quit [Client Quit]
elia has quit [Quit: Computer has gone to sleep.]
elia has joined #crystal-lang
NeverDie has joined #crystal-lang
<kyrylo> What are the alternatives for RUBY_PLATFORM and RUBY_VERSION in Crystal?
<jhass> what do you need them for?
<kyrylo> To display them =)
<kyrylo> I'm writing an Airbrake client
<jhass> CRYSTAL_VERSION = {{`crystal -v`.stringify}}; CRYSTAL_PLATFORM = {{`uname -m`}} I guess
<jhass> .stringify in the second too
<kyrylo> Ugh :(
<kyrylo> Is it possible to calculate that at compile-time?
<jhass> that's calculating it at compile time
<jhass> the {{ }} is macro code
<kyrylo> Oh
<kyrylo> From my understanding, if I complied my program on Linux and shared it with an OSX user, he would see that crystal_platform is linux?
<jhass> yes
<jhass> he'd also have trouble running it ;)
<jhass> so the actual answer is no, but theoretically yes
<kyrylo> Well, thanks! Your suggestion will do for now
<kyrylo> Does it make sense to do this for constant strings (for speed improvements): {{"blah blah blah"}}
<jhass> no
<jhass> macros restart the parser even
<jhass> it's a bit like calling sed on the source file and feeding the result to the compiler
<jhass> {{`foo`.stringify}} ends up as a StringLiteral in the AST
<jhass> (the result of I mean)
<kyrylo> Hmm, thanks
<kyrylo> Good old constants, then
oal has joined #crystal-lang
<jhass> strings are immutable, so string literals are already embedded as constants into the binary
<kyrylo> Oh
<jhass> whether you assign them to a constant or not
elia has quit [Quit: Computer has gone to sleep.]
<crystal-gh> [crystal] asterite pushed 1 new commit to master: http://git.io/v3fFd
<crystal-gh> crystal/master bc679fa Ary Borenszweig: Avoid mutating Iterator::Cons so it remains a struct. Fixes #1130
eam has quit [Ping timeout: 264 seconds]
blue_deref has joined #crystal-lang
eam has joined #crystal-lang
<travis-ci> manastech/crystal#bc679fa (master - Avoid mutating Iterator::Cons so it remains a struct. Fixes #1130): The build passed. https://travis-ci.org/manastech/crystal/builds/74711058
elia has joined #crystal-lang
dbackeus has joined #crystal-lang
<kyrylo> If anyone uses airbrake, please use =) https://github.com/kyrylo/airbrake-crystal
<kyrylo> It's super simple now
<jhass> kyrylo: you should overload to_json(IO), def to_json(io); @payload.to_json(io); end
<kyrylo> Thanks, I'm not super familiar with it, but I see the problem
<jhass> no worries, it's a common gotcha
<jhass> same for def to_s btw
<kyrylo> It's hard to think in Crystal =)
<kyrylo> Since it's so similar to Ruby
<kyrylo> (visually)
elia has quit [Quit: Computer has gone to sleep.]
<kyrylo> jhass, I was thinking about setting up a global error handler with help of redefine_main, but I couldn't figure out how to that reliable
<kyrylo> When I use it, it messes up Spec
<kyrylo> Since it also redefines it :)
<kyrylo> *how to do that reliably
<jhass> no idea
<kyrylo> jhass, is the crystal google group only for development of the language? Can I share the link there?
<jhass> sure you can, it's for all kind of discussion for now
elia has joined #crystal-lang
strcmp1 has joined #crystal-lang
<elbow> is there yet a way to timeout a Channel.receive?
<jhass> I think not yet
elia has quit [Quit: Computer has gone to sleep.]
<elbow> Yes something similar.\
<elbow> So are these Fiber's in fact multithreaded? or are they simply co-routines?
<jhass> they are coroutines (based on libpcl atm), but there are plans for a multithreaded work stealing scheduler
<elbow> jhass: oh cool. thanks for the help! :)
kyrylo has quit [Ping timeout: 255 seconds]
NeverDie has quit [Quit: I'm off to sleep. ZZZzzz…]
sailorswift has joined #crystal-lang
<elbow> I have officially spent at least an hour trying to align the 3d shape on the crystal-lang webpage so that it is an exact replica of the logo.
<jhass> xD I guess we need a keyboard shortcut :P
<elbow> hacks!
<elbow> that would be quite fun
blue_deref has quit [Quit: bbn]
leafybasil has quit [Remote host closed the connection]
leafybasil has joined #crystal-lang
leafybasil has quit [Ping timeout: 240 seconds]
leafybasil has joined #crystal-lang
blue_deref has joined #crystal-lang
kyrylo has joined #crystal-lang
blue_deref has quit [Quit: bbn]
leafybasil has quit [Read error: Connection reset by peer]
leafybasil has joined #crystal-lang
<dbackeus> kyrylo: thanks for the airbrake package
<dbackeus> did you consider using a client instance instead of class level singleton?
<dbackeus> I feel like the singleton approach is an anti pattern that got way to popular in ruby
<dbackeus> yes - it's often unlikely to need two use two different api accounts in a single app, but it can happen, more for some API's than others, and now might be the time to set good idioms and example for the crystal developers to come :)
<kyrylo> dbackeus, you are welcome! I did :) Luckily, it's not hard to change.
<kyrylo> dbackeus, do you have a realistic scenario for that, though?
<kyrylo> dbackeus, the library doesn't offer many features at the moment, but in the future it will have all the standard stuff like logging, asyncness, etc
<kyrylo> dbackeus, I don't mind the per-instance design, but I'm curious if it's *really* needed :)
<dbackeus> for Airbrake specifically - you might use different airbrake buckets for different part of the app, for example one for the web and one for background jobs
<dbackeus> say we figure out an awesome way to run background jobs in the same Crystal process
<dbackeus> and your library doesn't work any more :(
<dbackeus> I once wrote an API wrapper for my own web app with this style, since it is a lovely API and all... later on I dog fooded it for one of our projects and I needed to use it for multiple accounts and realized I could never have thread safety with the singleton approach
<dbackeus> lessons learned
<kyrylo> Haha, yeah. Thanks for the feedback! I think I'll change that now :)
<dbackeus> AIRBRAKE = Airbrake.new(project_id: "xxx", project_key: "xxx") would be a way to get a system wide instance if wanted
<dbackeus> if you're really fond of the clean api you could possibly support both
<kyrylo> That would be an overkill, I think
<dbackeus> Airbrake.configure would configure the default singleton instance - which in turn would be just an instance of Airbrake.new
<kyrylo> Ah, I see
<kyrylo> That's interesting
<kyrylo> Makes sense
<kyrylo> So you don't have to do anything to have a global isntance
<dbackeus> exactly, but where you wanted instances you could simply do Airbrake.new, and since you would any way use the instance for the singleton you wouldn't have to do any crazy code to make it work
<kyrylo> Yeah, that sounds very cool
<dbackeus> ok, GLHF :)
<dbackeus> good night!
<kyrylo> Thanks :)
<kyrylo> Nighty night
dbackeus has quit []
trapped has quit [Ping timeout: 246 seconds]
elia has joined #crystal-lang
blue_deref has joined #crystal-lang
BlaXpirit has quit [Ping timeout: 246 seconds]
BlaXpirit has joined #crystal-lang
BlaXpirit has quit [Read error: Connection reset by peer]
BlaXpirit has joined #crystal-lang
elia has quit [Read error: Connection reset by peer]
elia_ has joined #crystal-lang
NeverDie has joined #crystal-lang
elia_ has quit [Quit: Computer has gone to sleep.]
kyrylo has quit [Quit: Konversation terminated!]
sfcgeorg_ has joined #crystal-lang
sfcgeorge has quit [Killed (hobana.freenode.net (Nickname regained by services))]
sfcgeorg_ is now known as sfcgeorge
<dzv> is there a way to specify which libgc is used? mine is installed in a nonstandard path
<BlaXpirit> dzv, normal linker is used
<BlaXpirit> u can specify paths in which it will look for libraries
<BlaXpirit> but it's gonna be a pain for you all the way through
<BlaXpirit> because u also need to specify that path when executing your program
<BlaXpirit> on linux i can do LD_LIBRARY_PATH=/path/ crystal blah
<dzv> there is no provision for adding -L/path as part of building crystal itself and all programs with it?
<BlaXpirit> i'm not aware of any