ChanServ changed the topic of #crystal-lang to: The Crystal programming language | | Crystal 0.23.1 | Fund Crystal's development: | GH: | Docs: | API: | Gitter:
<Papierkorb> I have it set like that
<Papierkorb> It doesn't even find def's in the same file
<FromGitter> <faustinoaq> > We're above Scala ⏎ >> we're above rust as well ⏎ >>> and above kotlin, seems like a weird thing ⏎ >>>> **<RX14>** please ignore the tiobe stuff ⏎ ... []
<FromGitter> <faustinoaq> > It doesn't even find def's in the same file ⏎ ⏎ Papierkorb, seems that something is going wrong here, let me check, I disabled it by default because I had some issues in past
hightower4 has joined #crystal-lang
hightower3 has quit [Ping timeout: 258 seconds]
<FromGitter> <faustinoaq> Papierkorb, Seems is working fine on latest VSCode
<FromGitter> <faustinoaq> > Got Crystal working on a Raspberry Pi, sort of. ⏎ > Question though, when you compile with the --release option, should the executable really be so big? ⏎ ⏎ @HCLarsen I found some comparison about executable size Crystal vs C here ( []
<Papierkorb> I think you meant 185600B
<Papierkorb> Was wondering how you managed to create a 180meg binary at first
<FromGitter> <faustinoaq> Yeah, I just realize, fixed now 👍
<FromGitter> <faustinoaq> About `Can't find definition for "bar"` seems to be a `crystal tool` issue
<FromGitter> <faustinoaq> Seems Crystal needs an instance method call to find method definition inside a class or module
<Papierkorb> Yep then it works
<Papierkorb> Can't you require all *.cr files in src/ to find dependencies, calls, etc?
<FromGitter> <faustinoaq> These the reason because I also implemented `mainFile` on settings: ⏎ ⏎ ```code paste, see link``` []
<Papierkorb> Yeah I know of that setting, but it's not that useful when you have multiple projects
<Papierkorb> or can I say "src/*.cr" in there?
<FromGitter> <faustinoaq> Yeah, I tried that, Basically I pass mainFile as second argument for `crystal tool implementation -c /full/path/ /full/path/mainfile`, this problem ith `src/*.cr` as main file is that crystal doesn't work as I expected, I tested before and didn't work
snsei has joined #crystal-lang
ephemera_ has quit [Ping timeout: 240 seconds]
ephemera_ has joined #crystal-lang
<Papierkorb> faustinoaq, write a tempfile which simply requires those files, then load that as main file into crystal
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
<FromGitter> <georgeu2000> I have the following params: ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ How can I handle nil params with an instance variable? How can I handle a different params (say `OtherParams` in a `@params` variable? []
mooe_ has joined #crystal-lang
<mooe_> is there any way to get a list of instance variables like in ruby?
<mooe_> nevermind, its possible using macros and @type.instance_vars
_whitelogger has joined #crystal-lang
snsei has quit [Remote host closed the connection]
gokmen has quit [Quit: bye.]
RickHull has quit [Ping timeout: 260 seconds]
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
claudiuinberlin has joined #crystal-lang
mooe_ has quit [Quit: Connection closed for inactivity]
<FromGitter> <Brusalk> Hey All, been following Crystal for a long time, and starting to use it for personal projects. It's been awesome.
<FromGitter> <Brusalk> I have run into something I'm curious about,
<FromGitter> <Brusalk> Is it not possible to accept a block/proc with a method that can have multiple signatures? For example: ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ Am I misunderstanding union types and/or is there a better way to do this sort of thing? []
_whitelogger has joined #crystal-lang
DTZUZO has joined #crystal-lang
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
DTZUZO has quit [Ping timeout: 240 seconds]
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
<crystal-gh> [crystal] firejox opened pull request #5086: Make Tuple#map_with_index return a Tuple. (master...tuple_unified_map_behavior)
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 255 seconds]
DTZUZO has joined #crystal-lang
rohitpaulk has joined #crystal-lang
danielpclark has joined #crystal-lang
<FromGitter> <iambudi> How to capture error code from exception? Using ex.message only gives the error message string.
<FromGitter> <monouser7dig> ```code paste, see link``` ⏎ ⏎ compiles just fine here? []
<FromGitter> <bew> @Brusalk indeed it doesn't work, and it doesn't seems to be possible... (@monouser7dig try to instanciate a formatter, you'll see the error)
<FromGitter> <bew> @iambudi which exception? all exception don't have an error code
<Groogy2> Morning
Groogy has quit [Disconnected by services]
Groogy2 is now known as Groogy
Groogy_ has joined #crystal-lang
<FromGitter> <imonmyown> Yeah morning :)
<Papierkorb> Morning
<Groogy> looks a lot easier to read thx :)
<Groogy> though gonna move out these functions to its own structure probably like the formatter
<Papierkorb> Groogy: Having tons of small helper `struct`s turned out well for me too Basically free in creation, and prevents scope cluttering of including tons of helper modules
<Groogy> yeh also what I think
<Groogy> as long as the structures names and methods describe well what they are doing I think its gonna improve the code base
<FromGitter> <iambudi> > @iambudi which exception? all exceptions don't have an error code ⏎ I want to capture database exception error.
<FromGitter> <bew> and which exception is it?
<FromGitter> <iambudi> For example, using mysql driver to connect to db and do a record insert. When primary key duplicate it will throw error and we can capture the message : Duplicate entry ‘1’ for key ‘PRIMARY’. What i would like to capture is the error code of mysql : 1062. Is this related to db drive or by general crystal does not throw error code?
mrCrystal has joined #crystal-lang
<mrCrystal> hello how can I run 2 loops at the same time? can i create threads?
<FromGitter> <bew> mrCrystal see the documentation at
<RX14> damnit @bew you beat me to it
<FromGitter> <bew> ahah sorry, I have desktop notifications & I was already on my browser (with fast vim keybindings), might help to do things faster ;)
<RX14> i tried vim keybindings on my browser but never really made use of tem
<FromGitter> <bew> in this case I only used `y` to copy the url, combined with firefox's omnibox, I had to write `conc` to access the docs about concurrency
<FromGitter> <bew> and `alt-1` to goto first tab (I always pin gitter in first tab=
<RX14> well i only access that page for linking to other people so...
<RX14> its not in my omnibox
<FromGitter> <bew> I also almost only access this one for linking, maybe I accessed it more often (or more recently)
<FromGitter> <bew> yesterday I learned about frecency (frequency + recency), used by omnibox-like tools
<FromGitter> <bew> @iambudi which mysql shard are you using?
ShalokShalom_ has joined #crystal-lang
<hightower4> Howdy fellows
<mrCrystal> where are all the math things in crystal? sin cos atan atan2 sqrt?
<Papierkorb> In the `Math` module partially, "missing" stuff is directly defined on the `Number` types
<mrCrystal> ah okay!
<mrCrystal> "myint-1.times do" does not work. What can I do?
<mrCrystal> do i really need to define a new variable for this
<Papierkorb> `(foo - 1).times`, or with ranges: ``
<mrCrystal> ooh thanks
<FromGitter> <bararchy> So, stuck on a logical problem. ⏎ I got an `Array(String)` of URLs with parameters (id=1&bar=2&foo=3,etc..) ⏎ for each url I change one parameter, and keep all others, which means I end up with `URLs * params(for each)` kinda calculation which is fine, now to my issue. ⏎ I want to continuesly do this and add stuff to the parameters, but going with the same logic I just add more and more urls instead of
<FromGitter> ... changing the ones I already changed. ⏎ ... []
<oprypin> this is too confusing
<FromGitter> <bararchy> I know :(
<FromGitter> <bararchy> it managed to confuse me, and it's my code :(
<oprypin> just show example
<oprypin> a COMPLETE example with inputs and outputs
<oprypin> dont need code
<FromGitter> <bararchy> sure
<FromGitter> <bararchy> ```code paste, see link``` []
<FromGitter> <bararchy> now, I want to do the same again , add another A, but this will add 4 urls to output, and I want just 2
<oprypin> that makes the example incomplete then
DTZUZO has joined #crystal-lang
<FromGitter> <bararchy> right now it's exactly what it does though
<FromGitter> <bararchy> but not for the 2nd part
<FromGitter> <bararchy> as in, to the "again" part
claudiuinberlin has joined #crystal-lang
<oprypin> you are not explaining this well, so I ask for a complete example. so you give an incomplete example and more confusion
<FromGitter> <bararchy> oprypin Sorry, trying my best to comunicate my issue , i'll try again, in a gist maybe
<FromGitter> <bararchy> oprypin, is this better ? ⏎ ⏎
<oprypin> bararchy, why would you repeat step 2 and not just add AA immediately?
<FromGitter> <bararchy> Because the thing I might add might not be an actual A , its random
<FromGitter> <bararchy> So one becomes A another B ... Etc..
<oprypin> so what you're saying is the example is incomplete
<oprypin> so why not add an A and then "random" in the same step
<FromGitter> <bararchy> oprypin Trying to explain the issue gave me an idea :) thanks for the patiances
thews has quit [Ping timeout: 255 seconds]
<FromGitter> <Rinkana> Can i get the runtime value of an array while not matching like `["foo", "bar"].is_a?(Array(String))`
<FromGitter> <Rinkana> More like `["foo", "bar"].type => String`
<oprypin> Rinkana, that's .class
<Papierkorb> Rinkana, you can only work around it by grabbing any element and asking its #class. Array doesn't come with a `T` returnin method
<FromGitter> <Rinkana> Ah alright. Thanks
<oprypin> Rinkana, oh yeah sorry. the expression is `typeof(a[0])`
<oprypin> it gets the compiletime type of the item, even if the array is empty
<Papierkorb> Yeah that's much better
<FromGitter> <monouser7dig> even if it's a union?
<Papierkorb> Then it'd return that union
<FromGitter> <Rinkana> Awesome @oprypin, it works!
<Papierkorb> The typeof that is
<FromGitter> <Rinkana> Do you happen to know if it was a design choice to not include such method?
<FromGitter> <Rinkana> To return `T` i mean
<FromGitter> <monouser7dig> nice indeed
<oprypin> Rinkana, it's inelegant to have such a method
<oprypin> or is it
<Papierkorb> Why would it be "inelegant"
<oprypin> btw a typeof expression is usable in more places than a method call so there's that
<FromGitter> <Rinkana> I would think it might come in handy sometimes. Even if my current usecase is not going to happen very often.
<FromGitter> <Rinkana> But as long as there is a 'workaround' it's fine by me
<oprypin> `a = [1,2,3]; Deque(typeof(a[0])).new`
<oprypin> cant do that with a method
<oprypin> in fact, i think the method would cover only labout 10% of use cases
<FromGitter> <monouser7dig> how do you compare the result of typeof?
<oprypin> ==
<FromGitter> <Rinkana> It does feel somewhat odd referencing to an array object that might not even exists
<FromGitter> <monouser7dig> == what? cause the result is something like String::Class
<oprypin> typeof(a[0]) == Int32
<FromGitter> <Rinkana> Oh and thanks for referencing `Deque`. I forgot about that one
<oprypin> would be nice if `typeof(a[0]) < Int` also worked
<crystal-gh> [crystal] RX14 pushed 1 new commit to master:
<crystal-gh> crystal/master ebe683c firejox: Make Tuple#map_with_index return a Tuple. (#5086)
<FromGitter> <georgeu2000> How can I define a nested Struct?
<oprypin> georgeu2000, struct A; end; struct B; @a : A; end
<FromGitter> <georgeu2000> For example: ⏎ Hmmm...for example: ⏎ ⏎ ```code paste, see link``` []
<oprypin> wut
<FromGitter> <georgeu2000> I am using Struct instead of a nested hash.
<FromGitter> <georgeu2000> It worked well for HTTP params.
<FromGitter> <georgeu2000> So I have a JSON response that looks like this: ⏎ ⏎ ```{ foo: ⏎ { bar: "items" } ⏎ }``` []
<oprypin> georgeu2000,
<oprypin> lease make your example less obfuscated
<FromGitter> <georgeu2000> OK
<oprypin> "items" that's the most ambiguous json i've ever seen
<FromGitter> <georgeu2000> I was trying to make it easy to understand.
<FromGitter> <georgeu2000> "items" is not the JSON.
<FromGitter> <georgeu2000> The whole "hash" is JSON.
<FromGitter> <georgeu2000> Anyway, haha. I did use JSON.mapping which worked for JSON -> Struct.
<FromGitter> <georgeu2000> But this is a bit different. I am creating the "Struct" for the JSON response.
<oprypin> ok still do the exact same JSON.mapping thing for it
<FromGitter> <georgeu2000> OK, let me see.
<FromGitter> <georgeu2000> BTW, thanks for all your help.
<FromGitter> <georgeu2000> You seem to be here every day answering my questions.
<oprypin> np
<FromGitter> <georgeu2000> That looks like it will work. What is the difference between JSON mapping and a Struct?
<oprypin> georgeu2000, JSON mapping is not a data type. it's a way to generate methods that convert to and from json
<oprypin> u can put it inside a class, as in the example, or (at least I hope) inside a struct just the same way
<oprypin> georgeu2000,
<oprypin> i was trying to find any way at all to print the generated code from the macro, and the extremely funny thing is that just adding `p` did that. because it's a compilation error.
<FromGitter> <georgeu2000> Cool.
<FromGitter> <georgeu2000> It seems like since Crystal is typed JSON works like a hash with arbitrary types...
<oprypin> georgeu2000, yeah that's why people dont like it
<oprypin> json mapping abstracts that away. when it's applicable, anyway
<travis-ci> crystal-lang/crystal#ebe683c (master - Make Tuple#map_with_index return a Tuple. (#5086)): The build passed.
<FromGitter> <georgeu2000> That's why people don't like typed languages?
<oprypin> georgeu2000, who said people dont like them
<oprypin> lately people just love em
<FromGitter> <georgeu2000> > eah that's why people dont like it
<oprypin> georgeu2000, Hash with arbitrary types is terrible to work with that's why people don't like parsing JSON to such a Hash
<Papierkorb> Holy shit is working with Clang sometimes infuriating.
<Papierkorb> At least they don't break every single method in existence just for the lulz anymore it seems.
<FromGitter> <georgeu2000> @oprypin - I haven't had too much trouble working with arbitrary types, but maybe because my use case is JSON API's...
<FromGitter> <georgeu2000> I found 2 benefits from using Structs though...
<FromGitter> <georgeu2000> It's very interesting to use Crystal because it is a different approach...
<FromGitter> <georgeu2000> I am going to write a post about it on the company engineering blog.
<FromGitter> <georgeu2000> Is it possible to combine these into one class? That is to have nested JSON? ⏎ ⏎ ```code paste, see link``` []
<Papierkorb> You can pull the class into the class of course. apart from that, no.
<oprypin> georgeu2000, these are already combined and have nested json. what's the problem?
<FromGitter> <georgeu2000> I was wondering if you have to declare the Location as a separate class. I see we do.
<Papierkorb> You can use a `delegate` to the inner values if you insist. But for the general case, I don't see much point for this
<Groogy> been trying to figure out why some triangles behind others were being painted over the other
<Papierkorb> writing instead of foo.bar_baz or foo.baz isn't much worse, but is so much more structured. Also somewhat prevents god objects.
<oprypin> as Papierkorb suggested, you can move the line `class House` to the very beginning while keeping the reset the same
<Groogy> then I realized that in my shader script I forgot to switch function = Always to function = Less for the depth values
<FromGitter> <georgeu2000> OK thanks.
<FromGitter> <georgeu2000> Are there any examples of writing an API with Crystal?
<Groogy> mine? ^^
<Papierkorb> Groogy: C features got another jump in stability. Missing: 1) Function callbacks 2) vararg arguments 3) complex #define's (Like `1 | 2`). Of those, 3) is by far the most complex to solve.
<Groogy> hmm you feel it got far enough where I should give it a try on opengl?
<oprypin> Papierkorb, it's actually impossible to solve
<Papierkorb> On the upside, for pure C APIs, if you don't use any C++-side conversions, you can now leave out the C++ generator completely, which gets it in line with pure binding generators
<oprypin> complex defines include arbitrary pieces of C code, not even necessarily valid on their own
<Papierkorb> Groogy: Except for the listed points, it seems to work. The tests are promising too.
<Papierkorb> oprypin: Of course
<Papierkorb> Groogy: The biggest obstacle is #define mockery prevalent in many C libs. If those are not used (or wrapped through in a `enum`), then you should be fine.
<Papierkorb> Mh for complex-but-self-contained and constant object-like macros I might have an idea for a reasonably easy solution.
<oprypin> that's nice :)
<Groogy> you mean like the freetype weird macros they did? D:
<Papierkorb> Yeah those fall into that just mentioned category
<Groogy> crap
<Groogy> but I'll do a test on GL tomorrow
<oprypin> no i think "fall into that just mentioned category" is a good thing, right?
<Papierkorb> Ah how boring, that idea might just work. I had a much more fun solution in my mind.
<Papierkorb> May do that anyway when I have a few days for the lulz
<FromGitter> <monouser7dig> looking at array, is there some plan for rotate with boundaries and or partial sort?
<Papierkorb> Views would be nice to have
<Papierkorb> Though ArraySlice may be a more crystaly name
<FromGitter> <monouser7dig> for rotate you mean? thought about slice as well
<FromGitter> <bew> But would it ba safe?
<FromGitter> <bew> be*
<Papierkorb> With Slice? I have to say "no" but ....
<FromGitter> <monouser7dig> and why is there a replace function? what is the difference to just assign it to a different array?
<Papierkorb> What I mean would be a class that'd operate on a specific range of an Array
<FromGitter> <monouser7dig> (I mean if it had a range, but it does not)
<Papierkorb> Which would be perfectly safe
<FromGitter> <monouser7dig> for partial sort that aint work though
thews has joined #crystal-lang
thews has quit [Changing host]
thews has joined #crystal-lang
<FromGitter> <monouser7dig> or a nth_element
<oprypin> monouser7dig, this is not c++. you'd make a copy of the array and do something with it lol
<oprypin> arrays flying left and right here
<oprypin> that said, making a view class is very easy
<FromGitter> <monouser7dig> if you want something else than just web maybe do some algorithms once, properly 😄
<oprypin> no it's fine
<FromGitter> <monouser7dig> hm ⏎ yet sth easy like Levenshtein is included 😄
<oprypin> what a disaster, `rotate!` and `sort!` are defined directly on Array
<FromGitter> <monouser7dig> how is this a disaster
<oprypin> they cant be reused for other data types
<oprypin> this was supposed to work
<FromGitter> <monouser7dig> if any it would be defined on Comparable, not Indexable?
<oprypin> wut
<FromGitter> <monouser7dig> was thinking about sorting still my bad
<FromGitter> <georgeu2000> It seems that Spec does not do mocking. Do you have any suggestions?
<oprypin> don't do mocking
<FromGitter> <georgeu2000> Why not?
<FromGitter> <georgeu2000> I found and looks good...
<FromGitter> <georgeu2000> What is all about?
<oprypin> georgeu2000, it's an advanced alternative to Spec with very complex (and unfortunately slow to compile) implementation
<FromGitter> <monouser7dig> ...why is there a replace function on array? what is the difference to just assign it to a different array?
<FromGitter> <georgeu2000> I see. Thanks.
<oprypin> monouser7dig, `a = [1, 2, 3]; b = a; a[0] = 7; p b`
<FromGitter> <monouser7dig> b = a.clone in this case would be clear instead of a strange replace?
<FromGitter> <sdogruyol> lol
<FromGitter> <sdogruyol> nice one @Papierkorb
<oprypin> monouser7dig, that implies destruction of former value of b
<oprypin> which is a mmory reallocation
<oprypin> and there are special cases like `class A; getter a : Array; end` you can't reassign that value but can .replace
<FromGitter> <faustinoaq> > write a tempfile which simply requires those files, then load that as main file into crystal ⏎ ⏎ Papierkorb, Good Idea 👍
<FromGitter> <monouser7dig> if I have b.replace(a) instead of b = a.clone #all b values are gone in both cases, how can one require more effort than the other? ⏎ ⏎ so you tell me if I only have getter access I can still replace, does not sound doof IMO
<FromGitter> <monouser7dig> sound good*
<FromGitter> <eliasjpr> The new AmberFramework website is now live. The team has recently upgraded the website looks and documentation. It looks beautiful! Take a look
<oprypin> please don't tamper with scrolling, thx
<FromGitter> <faustinoaq> Great work @eliasjpr 👏 👏
<oprypin> that website just triggers me
<Papierkorb> eliasjpr, good job
<FromGitter> <imonmyown> looks damn hot
<FromGitter> <eliasjpr> Thanks guys. 😄 the docs still needs some work which we are currently working on :)
<FromGitter> <bararchy> On mobile the getting started button is a little chopped
<FromGitter> <imonmyown> Oh, there's even heroku support... amazing
<FromGitter> <imonmyown> So, heroku is like running native code?
<FromGitter> <eliasjpr> No, there is a heroku buildpack, is currently running on heroku
<FromGitter> <imonmyown> So how does it work, is it transpiled to ruby or? ... I don't get it
<FromGitter> <faustinoaq> > is it transpiled to ruby or? ⏎ ⏎ What do you mean ? @imonmyown
<Papierkorb> Heroku is simply a managed hoster. They got big with rails hosting, but they don't "run" on ruby
<FromGitter> <imonmyown> So it's a native binary eventually or...?
<Papierkorb> they just run your program, whatever it is. You're basically paying to run a Docker-like container.
<FromGitter> <imonmyown> Ok, got it now
<FromGitter> <eliasjpr> the site gets compiled on the build process and then the process gets spin up
<FromGitter> <eliasjpr> by one of the dynos
<FromGitter> <imonmyown> I used to think they only supported rails
<FromGitter> <monouser7dig> oprypin actually this memory reallocation thing, could you elaborate how an assignment is less efficient?
<FromGitter> <imonmyown> @faustinoaq it's a joiner of "transcribe+compile", some crazy idea crossed my mined that they used this trick to make crystal work like ruby
<oprypin> a.replace(b) -- a has memory allocated for its items. the same memory location gets overwritten with b's items. a = b.clone -- a new memory region gets allocated, b's items written to it, a gets destroyed
<oprypin> i should say `dup` not `clone`
<FromGitter> <faustinoaq> @imonmyown haha, no problem 😄
<FromGitter> <monouser7dig> well replace is like dup or like clone? the doc does not tell me 😟 but the allocation actually makes sense as long as b is smaller than a, otherwise it's probably not a real deal? ⏎ ⏎ still I find this replace command really weird especially after you told me about the getter thing (which makes kind of sense since it is an instance method but still)
<FromGitter> <monouser7dig> another cool option would be to have array#permute visiting everything once, it's easy but a really nice thing to have
<FromGitter> <monouser7dig> I see that is shuffle nvm
<oprypin> monouser7dig, `replace` is indeed weird. you shouldn't really think much of it in regards to getter, because there are a ton more ways to achieve the same effect through a getter anyway. that's how passing objects by reference works
<FromGitter> <monouser7dig> If I'd want to make sure I'd monkey patch it
<oprypin> what
<FromGitter> <monouser7dig> open Array and overwrite replace
<Papierkorb> just why
<FromGitter> <monouser7dig> why would you have it? just mmcopy?
<Papierkorb> you realize that there's a ton of other possibilities to overwrite the array data, right?
<FromGitter> <monouser7dig> sane ways?
<Papierkorb> #[]= ?
<FromGitter> <monouser7dig> if it only has a getter?
<Papierkorb> Dude. Pass by Reference.
<FromGitter> <monouser7dig> what is the deal in respect to access privilege?
<Papierkorb> ... Really, just try it.
<FromGitter> <monouser7dig> sure does not work if I pass an object and try to access an instance that has a getter only
<FromGitter> <monouser7dig> try to set *
<FromGitter> <monouser7dig> is it sensible opening an issue for redefining sort and rotate and maybe others on the classes they actually depend on (comparable etc.)? ( ⏎ Why should the implementation make such restrictions? ⏎ or was there some consideration that led to the decision that is was best to implement them straight into array? ⏎ Or is it just
<Papierkorb> comparable? What the heck?
<FromGitter> <monouser7dig> such that if I write a structure that is Iterable and has objects that are comparable, I can call sort on it
<oprypin> monouser7dig, you do not understand the situation at all, so please do not open an issue
<oprypin> monouser7dig, integers are comparable. do you think it would make sense to call 5.sort ? because that's what it seems like you're suggesting
<oprypin> so, you cannot define sort on comparable
<oprypin> you define sort on array-like types
<FromGitter> <monouser7dig> but ints are not indexable so no
<oprypin> what do you think it means "ints are indexable"?
<FromGitter> <monouser7dig> what?
<FromGitter> <monouser7dig> it means you can call some methods on them, on ints you can't of course
<oprypin> monouser7dig, the ability to sort depends on the type of container, that's what you should be talking about
<FromGitter> <monouser7dig> that is what I mean saying indexable
<oprypin> comparable is just a tiny detail that is not even specified anywhere. sort just uses `<` method and if it's not there it can't compile
<oprypin> so you said "is it sensible opening an issue for redefining sort and rotate and maybe others on the classes they actually depend on (comparable etc.)?"
<oprypin> is it a very unfortunate typo?
<oprypin> it is true that `sort!` and `rotate!` can be implemented on Indexable and that needs to be brought up
<oprypin> Comparable, as I was saying, is an unrelated tiny detail
<FromGitter> <monouser7dig> comparable etc was not meant as if they all depend on comparable but was meant in a way that they should only depend on the "interfaces (java)" they depend on
<FromGitter> <monouser7dig> I should say module, not interface here probably 😄
<oprypin> Also note that these cannot be implemented on `Iterable` or `Enumerable` (c++ equivalent forward iterator)
<FromGitter> <monouser7dig> > **<oprypin>** it is true that `sort!` and `rotate!` can be implemented on Indexable and that needs to be brought up
<oprypin> monouser7dig, sorting depends on `<` method. Comparable is just a convenience thing defining `<`, `<=` and others
<FromGitter> <monouser7dig> > > **<oprypin>** it is true that `sort!` and `rotate!` can be implemented on Indexable and that needs to be brought up ⏎ ⏎ that's it, thanks
<FromGitter> <monouser7dig> does sorting really depend on < like if you have a partial ordering ( you might not even need this every time? you do not have to enforce a strict < relation between every two elements just to establish a valid sort I mean
<oprypin> monouser7dig, it does not depend on any module or any relation. literally `<` method.
<oprypin> actually im not exactly sure what method it depends on but it doesnt matter
<FromGitter> <monouser7dig> yeah that is not the point afterall so I'll leave this with you and at the time you think it is appropriate this might pop up in your mind and the issue tracker?
<oprypin> i have no idea what PartialComparable is doing in stdlib, literally 0 uses of it
<FromGitter> <monouser7dig> I think it is actually a good concept to have and will hopefully be used sooner than later (
<FromGitter> <georgeu2000> I get an error when parsing XML: ⏎ ⏎ ``` ⏎ Is there a way to do it?``` []
<FromGitter> <georgeu2000> ```code paste, see link``` []
<FromGitter> <bew> it means that your xpath is invalid
<FromGitter> <bew> (I think)
<FromGitter> <georgeu2000> Another one worked fine: ` audio_url = parsed.xpath_node("//channel/item/enclosure")`
<oprypin> so it's probably the ":" i dunno, never heard of such symbol in xpath
<oprypin> oh it's part of the tag
<FromGitter> <bew> oprypin it's an XML namespace
<FromGitter> <georgeu2000> I guessed the same...thought maybe there is a way to escape it. But `\:` did not work.
<oprypin> i think it's invalid to use : as part of tag name in xpath
<FromGitter> <bew> says that you need to register a namespace somehow
<FromGitter> <bew> in the xpath call you can provide namespaces in second param
<FromGitter> <bew> not sure how to use it though
<FromGitter> <bew> I've found at that the namespaces arg must have a `#each` method, and each element is a tuple (?) with {prefix, uri}
<FromGitter> <bew> no idea what they are (prefix & uri)
nijotz has left #crystal-lang ["WeeChat 1.8"]
<FromGitter> <georgeu2000> I think `itunes` is the prefix.
<FromGitter> <bew> yes but uri?
<FromGitter> <georgeu2000> Maybe it is used in building XML.
<oprypin> in order to use 'h' prefix anywhere you must define xmlns:h="" where http://... is the uri
<oprypin> writing just xmlns="http://something" means prefixless things mean things from that uri
<oprypin> that's how this thing works
<oprypin> <html xmlns:lol=""><lol:head><lol:title> might be valid XHTML is what i'm trying to say
<FromGitter> <bew> lol x)
<FromGitter> <georgeu2000> I see it's just a reference for a Human...
<oprypin> let's not get humans involved here
<FromGitter> <georgeu2000> This made a lot of sense:
<oprypin> georgeu2000, yeah you need to register the namespace. maybe as part of the xml document, even. if not, i think bew linked a way to register it above
<oprypin> `xmlns:itunes=""` or something
<FromGitter> <georgeu2000> Seems like URI is used for building XML document.
<FromGitter> <georgeu2000> For parsing, I am using
<FromGitter> <georgeu2000> Which takes a param.
<FromGitter> <bew> yeah, use `some_node.xpath("//expr", {"itunes", "some_uri"})` or sth like that
<FromGitter> <bew> (or another xpath method)
<FromGitter> <georgeu2000> I think I need to build the Namespace first.
<FromGitter> <georgeu2000> ```undefined method 'each' for String ⏎ ⏎ namespaces.each do |prefix, uri| ⏎ ``` []
<FromGitter> <bew> you need an array of tuple for the namespace arg
<FromGitter> <georgeu2000> OK, I'll try.
<FromGitter> <bew> so more like `some_node.xpath("//expr", [ {"itunes", "some_uri"} ])`
<FromGitter> <bew> but I would think that the XML document would provide the xmlns:itunes attribute & the uri associated
<oprypin> yeah
<FromGitter> <georgeu2000> OK...
<FromGitter> <georgeu2000> Yes, it does: `<rss xmlns:itunes=""`
<FromGitter> <bew> cool ;)
<FromGitter> <georgeu2000> Yes, that worked. ⏎ ⏎ ```code paste, see link``` []
<FromGitter> <georgeu2000> Thank you.
<oprypin> very strange that libxml does not detect the namespace by itself
<FromGitter> <bew> and according to I think you can give it the name you want in the xpath, as long as it's the same uri as in the original xml document
<Papierkorb> "Hah great, that class has a dump() method. Let's see what it shows" `LValue: <todo>` "Fantastic!"
<FromGitter> <bew> (the prefix you want*)
<FromGitter> <bew> I'm glad it worked @georgeu2000 ;)
<FromGitter> <georgeu2000> > very strange that libxml does not detect the namespace by itself ⏎ ⏎ I didn't have this problem with Nokogiri...
<FromGitter> <georgeu2000> Should I create an issue on Github?
<FromGitter> <bew> I don't think so, oprypin why should it detect the namespace?
<FromGitter> <georgeu2000> Now my code looks like: ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ Is there some shorthand or Crystal idiom? []
<Papierkorb> `Object#try`
<Papierkorb> `duration = node.try(&.text)`
<FromGitter> <georgeu2000> OK, thanks.
<FromGitter> <georgeu2000> I tried that with `[]`...
<FromGitter> <bew> or `duration = node.text if node` ?
<FromGitter> <bew> (not tried but should work I think)
<oprypin> postfix if may not work actually
<FromGitter> <bew> hmm not working.. :/ why?
<FromGitter> <bew> the type is not restricted in that case?
<FromGitter> <georgeu2000> Figured out it try with array:`[1].try(&.[] 0)`
<FromGitter> <bew> ah nvm it actually worked (with a simple test)
<FromGitter> <georgeu2000> Is there any special reason that `HTTP::Headers#new` does not take any args?
<FromGitter> <bew> iirc you can use `HTTP::Headers{"Key" => "Value"}` to initialize it
<FromGitter> <georgeu2000> No, I looked at and source.
<FromGitter> <bew> "no" what?
<FromGitter> <georgeu2000> Oh, I see.
<FromGitter> <georgeu2000> It does not use `#new`.
<FromGitter> <georgeu2000> I thought it was strange...
<FromGitter> <georgeu2000> Thanks!
<FromGitter> <georgeu2000> It works.
<FromGitter> <bew> :)
<FromGitter> <bew> @iambudi you were looking for an error code if I remember correctly? what's the exception type?
<FromGitter> <georgeu2000> How is that defined in the source? ⏎ Does that come from Struct?
<FromGitter> <bew> no it's a special syntax
<FromGitter> <iambudi> Just a simple ⏎ ⏎ ```code paste, see link``` []
<FromGitter> <iambudi> @bew Should i use spesific ex type?
<FromGitter> <bew> I'm confuse, What are you trying to do?
<FromGitter> <georgeu2000> I was never able to get the ex type...
<FromGitter> <iambudi> I need to get the mysql error code in exception. That's all.
<Papierkorb> `rescue error : MySqlExceptionWhateverItsNameIs` and then access the error code through its getter
<Papierkorb> If there is a getter for it. If not, you're out of luck
<FromGitter> <iambudi> Thanks @Papierkorb, i'll try.
<FromGitter> <georgeu2000> How can I suppress the backtrace when running tests?
<oprypin> why tho
<FromGitter> <bew> a backtrace is an error, why would you want to (almost) hide an error?
<FromGitter> <georgeu2000> Because I only want to see the first line.
<FromGitter> <georgeu2000> The rest of the stack trace is not useful.
<FromGitter> <georgeu2000> And, unlike when running outside of the test environment, I want to get errors.
<FromGitter> <Hellfire01> is it possible to choose to passe a variable by reference or value ?
<FromGitter> <Hellfire01> by default, structs are passed by value and classes by reference
<FromGitter> <Hellfire01> but I have Structs with multiple big strings can I pass them by reference ?
<FromGitter> <Hellfire01> or should I rather just use a class and use it like a Struct
<FromGitter> <bew> just use class
<FromGitter> <Hellfire01> it is not possible to choose ?
<FromGitter> <bew> what do you mean "use it like a struct"? there's no difference betxeen the two
<FromGitter> <bew> unless where they are located and how they're transfered (by value or by ref)
<FromGitter> <Hellfire01> ok thanks