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
BlaXpirit has quit [Quit: Konversation]
dzv has quit [Quit: WeeChat 1.2]
strcmp1 has quit [Ping timeout: 250 seconds]
strcmp1 has joined #crystal-lang
dzv has joined #crystal-lang
dzv has quit [Client Quit]
dzv has joined #crystal-lang
sfcgeorge has quit [Quit: Textual IRC Client: www.textualapp.com]
sailorswift has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
havenwood has quit [Ping timeout: 264 seconds]
blue_deref has quit [Quit: bbn]
wonderbread_ has joined #crystal-lang
wonderbreadz has quit [Ping timeout: 244 seconds]
wonderbread_ is now known as wonderbreadz
NeverDie has quit [Quit: I'm off to sleep. ZZZzzz…]
sailorswift has joined #crystal-lang
BlaXpirit has joined #crystal-lang
elia has joined #crystal-lang
trapped has joined #crystal-lang
sailorswift has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
sailorswift has joined #crystal-lang
elia has quit [Quit: Computer has gone to sleep.]
<jhass> dzv: there's --link-flags to crystal build itself, but no configuration or environment variable
elia has joined #crystal-lang
elia has quit [Quit: Computer has gone to sleep.]
sailorswift has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
sailorswift has joined #crystal-lang
sailorswift has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
<crystal-gh> [crystal] technorama opened pull request #1134: Add support for concurrency safe file operations. (master...f/openat) http://git.io/v3Tp5
kyrylo has joined #crystal-lang
sailorswift has joined #crystal-lang
havenwood has joined #crystal-lang
mcgain has joined #crystal-lang
mcgain has quit [Client Quit]
mcgain has joined #crystal-lang
sailorswift has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
elia has joined #crystal-lang
elia has quit [Client Quit]
sailorswift has joined #crystal-lang
sailorswift has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
sfcgeorge has joined #crystal-lang
sleeper has joined #crystal-lang
dbackeus has joined #crystal-lang
dbackeus has quit [Remote host closed the connection]
sailorswift has joined #crystal-lang
sailorswift has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
sailorswift has joined #crystal-lang
dbackeus has joined #crystal-lang
sailorswift has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
sailorswift has joined #crystal-lang
sailorswift has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
sailorswift has joined #crystal-lang
sailorswift has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
elia has joined #crystal-lang
elia has quit [Quit: Computer has gone to sleep.]
elia has joined #crystal-lang
<nopc0de> /msg jhass
<nopc0de> owk
<nopc0de> /msg jhass thx for helping me on github
<nopc0de> wat
<jhass> nopc0de: oh, so it#s still that?
<nopc0de> Yea I didn't change it
<nopc0de> wget works fine btw
<jhass> weird
<nopc0de> yea
<nopc0de> I have no problem installing a new curl
<nopc0de> but compatibility with default osx curl would be nice
<jhass> you mean it's working with a newer curl?
<jhass> yeah
<jhass> what's the curl -v output now?
<nopc0de> curl 7.37.1 (x86_64-apple-darwin14.0)
<nopc0de> I'll download a new one with brew
<jhass> that's curl -V :P
<jhass> curl -v http://localhost:8080
<nopc0de> ⊨ curl -v localhost:8080 /V/s/P/c/frank
<nopc0de> * Rebuilt URL to: localhost:8080/
<nopc0de> * Hostname was NOT found in DNS cache
<nopc0de> * Trying 127.0.0.1...
<nopc0de> * Connected to localhost (127.0.0.1) port 8080 (#0)
<nopc0de> > GET / HTTP/1.1
<nopc0de> > User-Agent: curl/7.37.1
<nopc0de> > Host: localhost:8080
<nopc0de> > Accept: */*
<nopc0de> > Referer:
<jhass> :(((
<nopc0de> >
<nopc0de> * Empty reply from server
<nopc0de> * Connection #0 to host localhost left intact
<nopc0de> curl: (52) Empty reply from server
<nopc0de> sorry
<nopc0de> this new irc client...
<jhass> gist / pastebin !!!
<nopc0de> yeah my other client did that automatically
<jhass> commented with the working version, there's no difference
<jhass> oh
<jhass> except for the empty referrer
<jhass> I wonder if that's it
mcgain has quit [Quit: Textual IRC Client: www.textualapp.com]
mcgain has joined #crystal-lang
<jhass> yeah, curl -e "" seems to reproduce
<nopc0de> yeah thats it
<nopc0de> omg
<nopc0de> my curlrc made it give an empty referrer
<nopc0de> soooo
<nopc0de> its my own fault jhass
<nopc0de> *dies in shame*
<jhass> haha, no worries
<jhass> it's valid, it should work
<trapped> so here i am again with another issue, jhass: https://gist.github.com/trapped/265d1fb0a926f55125a5
<nopc0de> curlrc: referer = ";auto"
<trapped> this time it's something about the json mapping or something
<trapped> sorry if i keep asking but i'm clueless as there's no docs about the json module
<jhass> trapped: String? is shortcut notation for String|Nil, so you're passing a potential nil to the parser, which doesn't like that
<jhass> trapped: data = Request.from_json request.body.not_nil! try that
blue_deref has joined #crystal-lang
<jhass> (note it'll probably crash if someone sends you some request without a body, so better handle the nil case if that fixes it
<jhass> )
<trapped> the compiler error is longer than my console max lines
<nopc0de> HTTP request body.to_s
<nopc0de> never nils
<nopc0de> i think
<nopc0de> I'm using request.body.to_s
<trapped> updated
<jhass> nopc0de: that'll just cause the exception to be a json parse error for an empty body then ;)
<trapped> same thousand-line error with to_s
<crystal-gh> [crystal] PragTob opened pull request #1136: Improve documentation of struct in regards when to use it (gh-pages...when-to-use-struct) http://git.io/v3Icd
<nopc0de> jhass Right, I only tested form data
<jhass> trapped: you'll need to provide a specific Hash, Hash(String, String) or whatever
<trapped> that makes sense
ssvb has quit [Ping timeout: 252 seconds]
<nopc0de> jhass `curl --data` works but `curl --form` doesn't
<jhass> "works" and "doesn't work" is useless, observe, state observations and derivations from the expectations
<nopc0de> ok
<BlaXpirit> so I need to find out what types a tuple contains. anything i need to know before i give up and do this by parsing .class.name?
<jhass> well, the obvious question is why? :P
<crystal-gh> [crystal] PragTob opened pull request #1137: Improve contribution documentation (gitbook-cli package etc.) (master...improve-docs-contribution-docs) http://git.io/v3I4a
<BlaXpirit> jhass, to send DBUS variant type which may contain DBUS struct type
<BlaXpirit> i mean, this doesn't have to be tuple, but i don't think there is a way to make a generic that accepts an arbitrary number of types
<jhass> maybe you could be a tad more specific, like some explanation that doesn't require an hour of reading docs and guessing what kind of solution came to your mind? ;)
<BlaXpirit> jhass, how i'm gonna try to explain depends on whether you know DBus
<jhass> I know what it is for, I didn't work with the protocol directly
<jhass> libnotify is about as deep as I got really
<BlaXpirit> jhass, well you can call some "methods" and send various data types to them
<BlaXpirit> if I send a string, i can check is_a? String, then send the corresponding enum member and pointer to string
<BlaXpirit> if I send an Array(String), i can check is_a? Array and (by adding a method to Array) get the type of the array
<BlaXpirit> of the array's member, that is
<jhass> typeof(a[0]) works too
<BlaXpirit> problem is, i can't do much with this type object. i can't check what it is
<crystal-gh> [crystal] PragTob opened pull request #1138: Use an up to date ruby version for gh-pages (gh-pages...update-ruby-version) http://git.io/v3IRd
<BlaXpirit> jhass, that's compiletime
<jhass> so you have huge ass unions?
<BlaXpirit> uh pretty much
<BlaXpirit> because there is this type Variant
<BlaXpirit> which means any type can be sent
<jhass> but I mean the interface is sort of defined, no?
<BlaXpirit> jhass, everything is free to define its own methods based on dbus api
<jhass> iirc introspectable
<BlaXpirit> introspectable, but variant is just variant
<jhass> yeah, but I mean for concrete APIs you're going to call
<BlaXpirit> i was almost done with my introspecting solution, then the goddamn variant ruined everything
<jhass> are there really methods that take "whatever"?
<BlaXpirit> for example, (to translate to crystal's terms) there is a method that (among other things) accepts Array(Hash(String, Variant)))
<jhass> my first intuition would be to ponder another code generation approach, generate specific classes with casts, type restrictions and whatever for specific APIs
<BlaXpirit> and Variant could be anything, even another damn Array(Hash(String, Variant))
<jhass> that sucks
<jhass> how is a Variant serialized?
<BlaXpirit> jhass, i can't go with specific apis, because the possibilities are endless, anyone can define another method and it's immediately not supported by my lib
<jhass> well, the support would "here, run this generator for your API"
kyrylo_ has joined #crystal-lang
NeverDie has joined #crystal-lang
<jhass> so Variant is C union I guess?
<BlaXpirit> jhass, there is this whole protocol that i dont know how to use. but to send a variant you say "starting to send a variant", then you give a string signature like "a{si}" which is Array(Hash(String, Int32)), then, because it's an array, you say "i'mstarting to send an array" then you send first item "i'm staring to send a hash of these things" BLAH BLAH RECURSIVITY i'm finishing an array i'm finishing a hash
<BlaXpirit> u dont need to know the protocol, u just use the lib
kyrylo has quit [Ping timeout: 246 seconds]
<trapped> another question: how am i supposed to use if/each-do/etc blocks in ECR files?
<jhass> trapped: do you know ERB?
<trapped> a bit, yes
<jhass> like that
<jhass> <% crystal code %> template template <%= crystal code which's value will be inserted %>
<trapped> it complains if i do `<% if something %> something <% end %>
<trapped> `
<BlaXpirit> so since the types are limited to basically Type = Bool | Int16 | UInt16 | Int32 | UInt32 | Int64 | UInt64 | Float64 | String | Array(Type) | Hash(Type, Type) | Tuple(Type x N) (yeah, that final part is invalid), i think string parsing will work
<jhass> did you try turning it off and on again?
<jhass> (= default response to "didn't work" type of problem descriptions)
<jhass> BlaXpirit: meh
<trapped> it complains a bit less if i do `<% if something { %> something <% } end %>
<jhass> BlaXpirit: I guess a big case when dispatching to handler methods for each type and some recursivity could work
<trapped> but it still complains if i do <% ary.each do { |e| %> <%= e %> <% } end %>
<jhass> BlaXpirit: well, or relying on type restrictions even
<BlaXpirit> jhass, i've spent so many days trying so many things, but there is just no way
<willl> trapped: if you use do..end you dont need { }
<willl> one or the other
<trapped> `expecting token '=>', not 'NEWLINE'`
<trapped> uhh
<BlaXpirit> jhass, relying on type restrictions stops working as soon as an empty array is encountered
<BlaXpirit> and : T.class restrictions just do not work except for trivial types
<jhass> BlaXpirit: http://paste.mrzyx.de/pp7hdaqsf something like that
<BlaXpirit> jhass, do consider empty array
<jhass> what about it?
<jhass> you send the start marker and then the end marker, no?
<BlaXpirit> jhass, I need to know what type an array contains
<jhass> so only uniform arrays are allowed?
<BlaXpirit> yes, unless its an array of variants :po
<jhass> so add a bunch of def send(data : Array(String)); def send(data : Array(Int32)) ...
<BlaXpirit> jhass, array of arrays?
<BlaXpirit> ...of hashes of strings and arrays?
<jhass> do you really need to know the full type prior the first item? :/
<BlaXpirit> yes
<BlaXpirit> introspection does indeed work for everything until variants are involved :(
<jhass> http://paste.mrzyx.de/pzrdkc1bm something into this direction?
<BlaXpirit> jhass, i think this fails on empty arrays
<jhass> mmh
<BlaXpirit> i've been there
<jhass> well, I see no way beyond having it explicit then, send(type : String, data : Variant)
<jhass> and a generator using introspection that wraps that into classes for specific APIs
<BlaXpirit> jhass, i'd rather parse type string, it works for sure :p
<jhass> meh
<BlaXpirit> jhass, and won't be needed if variants are not used, and perhaps i could specialcase if a trivial type is sent into a variant
<BlaXpirit> (you seem to have misunderstood me here, because "type" and "variant" are different things. variant is a type that means "any type can be put in here")
<BlaXpirit> thanks
<nopc0de> Is there support for multipart/form-data in crystal?
<crystal-gh> [crystal] jhass opened pull request #1140: Parse empty HTTP header (master...empty_header) http://git.io/v3IKT
<nopc0de> hoora!
dbackeus has quit [Remote host closed the connection]
trapped_ has joined #crystal-lang
trapped has quit [Read error: Connection reset by peer]
leafybasil has quit [Remote host closed the connection]
leafybasil has joined #crystal-lang
ssvb has joined #crystal-lang
<BlaXpirit> >> {[5], {6=>{"a", 9}}}.class.name.gsub { |c| c.alphanumeric? ? c : " #{c} "}.split # "parsing" :(
<DeBot> BlaXpirit: # => ["{", "Array", "(", "Int32", ")", ",", "Hash", "(", "Int32", ",", "{", "String", ",", "Int32", "}", ")", "}"] - http://carc.in/#/r/amk
<BlaXpirit> actually is tokenizing
elia has quit [Quit: Computer has gone to sleep.]
strcmp1 has quit [Quit: Leaving]
sailorswift has joined #crystal-lang
kyrylo_ is now known as kyrylo
kyrylo_ has joined #crystal-lang
kyrylo has quit [Ping timeout: 240 seconds]
kyrylo_ has quit [Ping timeout: 244 seconds]
dbackeus has joined #crystal-lang
dbackeus has quit [Read error: Connection reset by peer]
dbackeus has joined #crystal-lang
ssvb has quit [Quit: Leaving]
<BlaXpirit> I have some Python code, and I would love to be able to write something like this in Crystal. I can't free myself from Python's paradigms. the main problem I have is with the "yield" ing. in Python the function that yields just spits out values one by one, and the actual control is given to the function that uses it.
<BlaXpirit> in Crystal, however, the function that yields is basically the dominating thing, and it manages the calling of the block given to it. i just can't make myself think this way
<BlaXpirit> i tried my best to explain the Python code https://bpaste.net/show/b77218d67499
<BlaXpirit> i would be forever in debt if someone explained me how to do something similar in Crystal
<jamie_ca> BlaXpirit: I have no idea if this description is relevant to Crystal, but in Ruby...
<jamie_ca> a method has an implicit block (I know, Python is all about preferring explicit)
<jamie_ca> so in ruby, I'd write def tokens_generator(&block)
<jamie_ca> if I wanted to use it
<jamie_ca> and then explicitly using it, inside the method instead of yield "{", I would instead block.call("{")
<jamie_ca> as though it were a coroutine
<BlaXpirit> jamie_ca, do you know Python or understand what i'm doing with next()
<BlaXpirit> this is not normal iteration
<jamie_ca> BlaXpirit: you're taking your generator function, and converting it to an iterator, which uses next to grab the next yielded value?
<BlaXpirit> jamie_ca, that sounds right
<jamie_ca> actually, I could probably do that generator -> iterator conversion in ruby, but I'm probably better off not guessing about the crystal internals to do so
<BlaXpirit> well i could start with ruby then
<BlaXpirit> Enumerator looks like exactly what i want, but there is no such thing in Crystal
<BlaXpirit> it is obvious that this is not meant to be done in these languages, i need a change of paradigms, but i dont understand
<jamie_ca> yeah, some voodoo with Enumerator in ruby, for sure
<jamie_ca> BlaXpirit: ok, I think I see what you're doing...
<jamie_ca> tokens_to_signature, in Ruby, I would assemble a string to return rather than yielding each output character, and that gets rid of some of the indirection
<BlaXpirit> jamie_ca, not a problem in this case, but sometimes i would want lazy computation. but it's ok if we skip this for now
<jamie_ca> BlaXpirit: I need to leave shortly for the afternoon (it's just past 12 here) - will you be around this evening?
<BlaXpirit> jamie_ca, it's 22 here
<jamie_ca> ahh
<jamie_ca> (like, in 8h)
<BlaXpirit> will be here 3 more hours max, so no, sorry
<BlaXpirit> but then i will be available all the time 12 hours from now
<jamie_ca> I can totally chat you up tomorrow this time though
<BlaXpirit> great, thanks a lot. i will remind you (unless i already have the solution)
<jamie_ca> sure
<BlaXpirit> can't define def inside def :S
<jhass> BlaXpirit: yield in Crystal/Ruby is not for generators, that's what Enumerator in Ruby and Iterator in Crystal is for
<BlaXpirit> jhass, sure, now tell me how I would implement tokens_generator using Iterator
<jhass> Ruby allows to easily generate Enumerator's from a method that yields multiple times, but Ary found it to be too slow
<BlaXpirit> literally this function - how i would implement it
<BlaXpirit> i mean,... obviously this could be put in a @array and incrementing @index
<BlaXpirit> so nevermind, jhass, this example is easy to game
<BlaXpirit> jhass, i dont want to manage state, i want to deal with normal control flow
<jhass> note that Enumerable also has a bunch of methods that build up on an each method that yields multiple times
<jhass> >> class Foo; include Enumerable(String); def each; yield "a"; yield "b"; end; end; Foo.new.to_a
<DeBot> jhass: # => ["a", "b"] - http://carc.in/#/r/an5
<BlaXpirit> well i specifically dont want an array
<jhass> >> class Foo; include Enumerable(String); def each; yield "a"; yield "b"; end; end; Foo.new.join(" ")
<DeBot> jhass: # => "a b" - http://carc.in/#/r/an6
dbackeus has quit [Read error: Connection reset by peer]
<BlaXpirit> instead of performing the same action on each item, i want to use these elements sequentially however i want
dbackeus has joined #crystal-lang
<jhass> yeah, that's what you need an iterator for
<jhass> or maybe I still have my Enumerator PoC laying around
<BlaXpirit> jhass, i understand how to implement iterators, and i also understand that it's extremely tedious
<BlaXpirit> well actually not as tedious as i thinught
<BlaXpirit> just gotta treat the next as loop do
<BlaXpirit> thought*
<jhass> as said beware, it's a bit slow, compared to an Iterator at least
<jhass> uhm, ignore the my_def macro, no idea why that's there :P
<BlaXpirit> ok this is great stuff, thanks
<BlaXpirit> jhass, can i use next on an array?
<BlaXpirit> i mean, i clearly see that there is no such method. does array have an iterator?
<jhass> yes, a couple in fact
<jhass> >> [1, 2, 3].each
<DeBot> jhass: # => #<Array(T)::ItemIterator(Int32):0x89ddfc0 @array=[1, 2, 3], @index=0> - http://carc.in/#/r/ana
<BlaXpirit> i was unable to find them
<jhass> >> i = [1, 2, 3].each {i.next, i.next}
<DeBot> jhass: Syntax error in eval:4: unexpected token: } - http://carc.in/#/r/anb
<jhass> bleh
<BlaXpirit> so... all of these each_ things that i can pass blocks to can be used as iterators
<jhass> >> i = [1, 2, 3].each; {i.next, i.next}
<DeBot> jhass: # => {1, 2} - http://carc.in/#/r/anc
<BlaXpirit> that's great. thanks
<jhass> not by default, no. But most in stdlib have overloads now
<BlaXpirit> so how does it work that something that just has the method next can be used with a block
<jhass> it can't?
<BlaXpirit> array has def each; ItemIterator.new(self)
<BlaXpirit> ah the point is it must have include Iterator(T) and def next
<jhass> yes, and def each; yadayada loop; yield value
<jhass> the block counts into the method signature, you can have overloads that take one and not
<BlaXpirit> ok then how does Iterator(T) ensure that i can do array.each if each only returns an ItemIterator?
<jhass> that's the overload that doesn't take a block
<jhass> this one is called if you do pass a block
<BlaXpirit> oh so it doesn't work like that and you must implement both a function that takes a block and one that returns an iterator :(
<jhass> yes
<BlaXpirit> python is way superior in this department
<BlaXpirit> you pretty much just get an iterator for free
strcmp1 has joined #crystal-lang
<BlaXpirit> (yes, it's slow)
<jhass> because you don't get a block
<BlaXpirit> yes
<jhass> we could do the same as Ruby, where you actually get both for free with just one loc, as my PoC shows, but as said it's not fast enough
<BlaXpirit> not fast enough for stdlib
<jhass> I tried to persuade Ary to include (something like) Enumerator into stdlib and so you can default to it and write optimized Iterator's when you have a bottle neck
<jhass> but he didn't like it
<BlaXpirit> but crystal is fast enough that many people would not care for a small slowdown in one area for huge convenience
<jhass> I guess we can make enumerator just a library though
<BlaXpirit> i can only wonder whether compiler support could make it better
<BlaXpirit> it could make it look better, that's one thing
<jhass> you'll need coroutines and that's why it's slow
<jhass> same in Ruby, it's done with fibers there too
<jhass> and I can't imagine Python does it differently
<jhass> after all you need to jump between stack frames
<BlaXpirit> python uses coroutines, yes, and i love it for the convenience with coroutines
<BlaXpirit> yes, thats' what happens
<BlaXpirit> i pretty much just want coroutines in crystal and i'm set for life
<jhass> uhm
<jhass> spawn is coroutines
<sfcgeorge> Well optimized std lib sounds best to me, but I like jhass idea of Enumerator class for convenience in client code.
<BlaXpirit> no mention about spawn in docs
<jhass> I guess they keep it undocumented for now in case they need to introduce syntax to make it work with a multi threaded scheduler
<jhass> look at the chanenl examples in samples/
<jhass> *channel
<BlaXpirit> but of course, no lazy computation involved here
<jhass> I guess the raw coroutine solution without the Enumerator abstraction would be something like http://paste.mrzyx.de/psdafdwsj
<BlaXpirit> you're the best, jhass
<jhass> but I expect it to be slower than just allocating a small array
<BlaXpirit> sure, i will settle on the solution i posted
kyrylo_ has joined #crystal-lang
<BlaXpirit> but it's very important knowledge for me in the future
<jhass> another pattern to perhaps consider could be a pull parser https://github.com/manastech/crystal/blob/master/src/array.cr#L496-L500
<jhass> er, wrong link :/
blue_deref has quit [Quit: bbn]
<jhass> FF tricked me
<BlaXpirit> of course, jhass, that's always an option
<jhass> that is you have a class where you maintain some sort of state over an input and advance that state on external request
<BlaXpirit> i'm too attracted to interrupting functions which have uninterrupted control flow
<BlaXpirit> jhass, what you're saying is just like iterators, i understand the concept
<jhass> well yeah, pretty much
ssvb has joined #crystal-lang
kyrylo_ is now known as kyrylo
<BlaXpirit> are there asserts that work only in release?
<BlaXpirit> only in debug* D:
mcgain_ has joined #crystal-lang
mcgain_ has joined #crystal-lang
mcgain has quit [Ping timeout: 255 seconds]
mcgain_ is now known as mcgain
<jhass> not inbuilt afaik
<jhass> you can do something like def debug_assert(cond); ifdef debug; raise ... unless cond; end; end; and compile with -Ddebug
<BlaXpirit> jhass, doing just that
<jhass> or ifdef ebug; and -Debug if you feel fancy .P
<BlaXpirit> :D
<BlaXpirit> i thought debug and release would be defined :(
<BlaXpirit> jhass, release is defined on --release
<BlaXpirit> so im doing... ifdef release;else
<jhass> ah
<jhass> mmh
<jhass> >> ifdef !windows; puts "hey"; end
<DeBot> jhass: hey - more at http://carc.in/#/r/anf
<BlaXpirit> ifdef is so out of place :D
<jhass> but dunno, the $WARN, $SAFE and $VERBOSITY never really took off in Ruby
<jhass> the community tends to build stuff that just runs the same in prod and dev
<BlaXpirit> how do do this without fearing a clash of "" here "Assertion error: {{ cond }}"
<jhass> the "fail fast and hard" paradigm is fairly strong in the community
<BlaXpirit> cond could be "1" == "2"
<jhass> "foo #{{{ cond }}}"
<jhass> wrap the macro invocation inside #{}
<BlaXpirit> ooooooooooooooooooooooohhhh
<jhass> >> "#{""}"
<DeBot> jhass: # => "" - http://carc.in/#/r/ang
<BlaXpirit> actually, jhass, that turns "1"=="2" into just false
<jhass> well, yes
<jhass> mmh, I guess "".id will just vanish
<jhass> >> {% if true %} "{{"".id}}" {% end %}
<DeBot> jhass: # => "" - http://carc.in/#/r/anh
<jhass> >> {% if true %} "{{"1" == "2".id}}" {% end %}
<DeBot> jhass: # => "false" - http://carc.in/#/r/ani
<jhass> >> {% if true %} "{{("1" == "2").id}}" {% end %}
<DeBot> jhass: # => "false" - http://carc.in/#/r/anj
<jhass> mmh
<BlaXpirit> that's just different
<jhass> >> {% if true %} "{{("1" == "2").stringify.id}}" {% end %}
<DeBot> jhass: # => "false" - http://carc.in/#/r/ank
<jhass> I guess it's evaluated in the macro
<jhass> >> macro test(cond); "{{cond.id}}" end; test("1" == "2")
<DeBot> jhass: Syntax error in expanded macro: test:1: unexpected token: 1 - http://carc.in/#/r/anl
<jhass> wat
<BlaXpirit> yes, now you reached the real conditions
<jhass> okay i give up
<BlaXpirit> expands to ""1" == "2""
<BlaXpirit> unexpected token 1
<jhass> yeah
<jhass> >> macro test(cond); "#{{{cond.stringify}}}" end; test("1" == "2")
<DeBot> jhass: # => "\"1\" == \"2\"" - http://carc.in/#/r/anm
<jhass> that's better
<jhass> >> macro test(cond); "#{{{cond.stringify}}}" end; test("")
<DeBot> jhass: # => "\"\"" - http://carc.in/#/r/ann
<BlaXpirit> i'm sure i tried that! how did i fail
<BlaXpirit> works for sure, thanks
<BlaXpirit> actually it didnt work! i have no idea what i was doing that it seemed to work
<BlaXpirit> anyway, final solution: "Assertion error: #{{{ cond.stringify }}}"
<BlaXpirit> oh, that's exactly what you did, then i failed to copy -___-
<jhass> just realized we also could've just looked at pp
blue_deref has joined #crystal-lang
<BlaXpirit> :D
<BlaXpirit> hey, if i have this expr "a"+"b" == "ab", can i check if it's some kind of OperatorNode with name '==' or '!=' then split it into parts
<BlaXpirit> would be a pretty awesome assert macro then
<jhass> mmh, should be a Call I think
<jhass> >> macro test(cond); {{cond.class_name.stringify}}; end; test("1" == "2")
<DeBot> jhass: # => "\"Call\"" - http://carc.in/#/r/anq
<jhass> >> macro test(cond); {{cond.name}}; end; test("1" == "2")
<DeBot> jhass: Syntax error in expanded macro: test:1: unexpected token: == - http://carc.in/#/r/anr
<jhass> >> macro test(cond); {{cond.name.stringify}}; end; test("1" == "2")
<DeBot> jhass: # => "==" - http://carc.in/#/r/ans
<BlaXpirit> where are methods of this Call described again?
<BlaXpirit> seems like some new things appeared there
<BlaXpirit> thanks
<jhass> >> macro test(cond); {{cond.name.stringify}}; end; test("1" + "2" == "3")
<DeBot> jhass: # => "==" - http://carc.in/#/r/ant
<jhass> ah nice
<BlaXpirit> sure is very nice :) i'm happy as heck
<jhass> was worried for a bit it could go to the + call first in that kind of expression
<jhass> >> macro test(cond); {{cond.receiver.name.stringify}}; end; test("1" + "2" == "3")
<DeBot> jhass: # => "+" - http://carc.in/#/r/anu
<BlaXpirit> these macros are actually much more convenient than Nim's, and in fact this way to do macros is what i suggested to the language's creator
<jhass> I'm a bit jealous of Julia's generated functions though
<BlaXpirit> i just had no idea that Crystal's macros have this power (it's still less than Nim's but not by much)
NeverDie has quit [Quit: I'm off to sleep. ZZZzzz…]
nahtnam has joined #crystal-lang
mcgain has quit [Quit: mcgain]
mcgain has joined #crystal-lang
<BlaXpirit> jhass, this is what i ended up with http://blaxpirit.com/blog/17/detailed-assert-macro-for-crystal.html
<BlaXpirit> crummy syntax highlight T_T
<BlaXpirit> should just post this on gist/github and not be a hipster
<jhass> nice!
<jhass> does it print the value of a variable in things like assert foo.nil?
<BlaXpirit> jhass, no
<BlaXpirit> it's not difficult to add, but i think all these different cases need to be taken into account
<BlaXpirit> by writing code for each case, that is
dbackeus has quit [Remote host closed the connection]
strcmp1 has quit [Ping timeout: 246 seconds]
trapped_ has quit [Ping timeout: 260 seconds]
BlaXpirit has quit [Quit: Konversation]
trapped has joined #crystal-lang
strcmp1 has joined #crystal-lang
sfcgeorge has quit [Quit: Textual IRC Client: www.textualapp.com]
<crystal-gh> [crystal] asterite closed pull request #1140: Parse empty HTTP header (master...empty_header) http://git.io/v3IKT
<travis-ci> manastech/crystal#081a0d8 (master - Merge pull request #1140 from jhass/empty_header): The build passed. https://travis-ci.org/manastech/crystal/builds/74844454
<crystal-gh> [crystal] asterite pushed 2 new commits to master: http://git.io/v3tKm
<crystal-gh> crystal/master b9ba092 Tobias Pfeiffer: Improve contribution documentation (gitbook-cli package etc.)...
<crystal-gh> crystal/master c99bf25 Ary Borenszweig: Merge pull request #1137 from PragTob/improve-docs-contribution-docs...