ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.29.0 | Fund Crystal's development: http://is.gd/X7PRtI | GH: https://github.com/crystal-lang/crystal | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/ | Gitter: https://gitter.im/crystal-lang/crystal
<woodruffw> slightly unrelated: does anybody know if the absence of `Number#negative?` is intentional/an oversight? that's one of the convenience methods i find myself using frequently in ruby
<FromGitter> <tenebrousedge> πŸ‘€
<FromGitter> <watzon> @woodruffw idk, you could make an issue about it and see. If would be super easy to add to the standard library. There are a lot of helpful methods that are still missing.
<FromGitter> <watzon> Especially with `URI`
<woodruffw> yeah, i'll probably make a PR for it. just wanted to do a first pass to see if i was potentially retracing someone else's steps
<FromGitter> <watzon> I mean you could search the issues to see if someone has asked before. It would make a good first PR if the maintainers are ok with adding it.
<FromGitter> <tenebrousedge> I think it would be useful
<FromGitter> <Blacksmoke16> positive too
<FromGitter> <watzon> I do too, as well as a `positive?` method to compliment it
<FromGitter> <watzon> Lol
<FromGitter> <watzon> @Blacksmoke16 beat me to it
<FromGitter> <Blacksmoke16> would be an easy implementation based on `#sign`
<FromGitter> <Blacksmoke16> ```def positive? ⏎ sign == 1 ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5d0ec46b207f6e6963e74726]
<FromGitter> <Blacksmoke16> ```def negative? ⏎ sign == -1 ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5d0ec47941654c559ee346b4]
<FromGitter> <tenebrousedge> `0.sign == 0`
<FromGitter> <Blacksmoke16> right
<FromGitter> <watzon> That would probably be cheaper than doing a comparison check huh? `self < 0`
<FromGitter> <Blacksmoke16> `#sign` already does that
<FromGitter> <watzon> Oh does it?
<woodruffw> IIRC ruby provides `#positive?`, `#negative?` and `#zero?`, so i'll make the PR with all three
<FromGitter> <Blacksmoke16> zero already exists
<woodruffw> whoops
<FromGitter> <watzon> Yep
<woodruffw> alrighty, just the two then
<FromGitter> <Blacksmoke16> that was quick
<FromGitter> <Blacksmoke16> needs specs
<woodruffw> yep, adding them now
<FromGitter> <Blacksmoke16> πŸ‘
<FromGitter> <Blacksmoke16> `Returns `false` if `self` is less than zero.`
<FromGitter> <Blacksmoke16> since the comparison is happening on self not a passed in value
<woodruffw> hmm, i copied that from the `zero?` comments. looks like the docs use "the value" and "this number" inconsistently. i'll change it to `self` here.
<FromGitter> <Blacksmoke16> `self` makes the most sense
<woodruffw> yep
<FromGitter> <Blacksmoke16> πŸ‘
<woodruffw> okay, specs added
<FromGitter> <Blacksmoke16> protip, you can do `.should be_true` and `.should be_false`
<FromGitter> <Blacksmoke16> but either way, does the same thing
<FromGitter> <Blacksmoke16> good stuff
<woodruffw> ah, more copy paste hell. i can do it for the whole spec in another PR, since i've done a few test refactoring PRs before
<FromGitter> <Blacksmoke16> :P
<FromGitter> <Blacksmoke16> all good
<FromGitter> <cpunion> In Ruby: ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ Ah, I think it’s better for HTTP::Client likes Ruby. [https://gitter.im/crystal-lang/crystal?at=5d0ecb0d007cff7a82ffa277]
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d0ecb4d007cff7a82ffa511]
<FromGitter> <Blacksmoke16> setters return the value that was set, not self
<FromGitter> <Blacksmoke16> so the return value from your block is returning `3` which `client` is being set to
<FromGitter> <Blacksmoke16> is there an easy way to see if an IO is empty? `STDIN` for example?
<FromGitter> <tenebrousedge> `peek` ?
<FromGitter> <Blacksmoke16> seems peek blocks?
<FromGitter> <j8r> Why positive or negative, if we can just `> 0`
<FromGitter> <tenebrousedge> should it be possible to check if the IO is empty without blocking?
<FromGitter> <tenebrousedge> @j8r you could do e.g. `arr.select(&.positive?)` Which is a little more awkward with `0.>`
<FromGitter> <Blacksmoke16> also zero exists, so my as well just complete the set
<FromGitter> <j8r> No @tenebrousedge `arr.select(&.> 0)
<FromGitter> <j8r> And duplicate of https://github.com/crystal-lang/crystal/pull/6552
<FromGitter> <j8r> This is confusing, because are they strictly positive/negative, or not?
<FromGitter> <cpunion> @Blacksmoke16 Thanks.
<FromGitter> <tenebrousedge> @j8r that code doesn't work
<woodruffw> i don't think that's a confusion i've ever run into, do people actually use a definition of "positive" that includes 0?
<woodruffw> i agree with tenebrousedge that `&.positive?` is more pleasant to read
<FromGitter> <Blacksmoke16> using sign makes it so 0 is neither positive or negative
<FromGitter> <Blacksmoke16> which is correct
<FromGitter> <tenebrousedge> it would be `arr.select(&.<(0))`
<FromGitter> <j8r> Or `are.select &.< 0`
<FromGitter> <tenebrousedge> just as bad
<FromGitter> <tenebrousedge> semantic method names are preferable to direct comparisons to zero
<FromGitter> <j8r> Not in this case
<FromGitter> <tenebrousedge> why?
<FromGitter> <j8r> This is very explicit, `positive?` don't tell if it's strictly or not
<FromGitter> <tenebrousedge> I don't see that that's a necessary disambiguation, or if so, the documentation could make that clear
<woodruffw> i don't know of any definition of real numbers that it's trichotomous
<woodruffw> i.e., all numbers are either positive, negative, or zero
<FromGitter> <Blacksmoke16> the docs do make it clear
<woodruffw> under that definition "strict" positive and positive are exactly the same thing
<FromGitter> <Blacksmoke16> `0` is false for both
<woodruffw> s/it's/isn't/
<FromGitter> <j8r> there is already `sign` we can use, too
<woodruffw> i think there's a real argument to be made for "strict" in the case of primes, e.g. `1.prime?`; but not here
<FromGitter> <Blacksmoke16> thats why this is built upon that, just more readable
<FromGitter> <Blacksmoke16> vs `145.sign == 1`
<FromGitter> <Blacksmoke16> same argument could be made with `"what does 1 mean"
<FromGitter> <Blacksmoke16> vs `145.positive?`
<woodruffw> more generally: crystal brands itself as inspired by ruby, which includes "say what you mean" semantics instead of "say how it works" semantics
<FromGitter> <j8r> Yes, comparing to zero is better
<woodruffw> `sign` exists and `zero?` exists, `positive?` and `negative?` follow from existing considerations
<FromGitter> <Blacksmoke16> id rather do `num.positive?` than `num > 0` but i dont have strong feelings either way
<FromGitter> <tenebrousedge> I don't think that being explicit for the sake of being explicit is a remotely good argument
<FromGitter> <j8r> I don't see how it relates woodruffw. That's an opinion, I don't like having multiple "dummy" methods for such simple operations.
<FromGitter> <Blacksmoke16> then why does zero exist?
<FromGitter> <tenebrousedge> ^
<FromGitter> <Blacksmoke16> that way of thinking you could remove prob a good amount of methods
<FromGitter> <j8r> Good question
<FromGitter> <j8r> Lol
<FromGitter> <Blacksmoke16> why have `sign` if you could just do `num == 0`
<woodruffw> yeah, my opinion is that "dummy" methods are reasonable when they allow us to (1) be more semantic, and (2) align with popular methods in ruby
<FromGitter> <Blacksmoke16> has to be a balance imo
<FromGitter> <Blacksmoke16> id like to have like `Array#second`
<FromGitter> <Blacksmoke16> etc, but meh
<woodruffw> but i think the actual number theory has been long settled here: for numbers in R, all numbers are `sgn | {-1, 0, 1}`
<woodruffw> "positive" is `{1}`. "negative" is `{-1}`. "nonpositive" is `{-1, 0}`, and so forth
<FromGitter> <Blacksmoke16> pretty sure `0` is neither positive or negative, according to quick google search :P
<FromGitter> <Blacksmoke16> not to say i have a PHd in math :S
<woodruffw> i specialized in formal logic, but i didn't do much number theory :p
<FromGitter> <j8r> We could have `loosely_positive?` instead of `>= 0`... :3
<woodruffw> i mean, i'd be okay with `nonpositive?` and `nonnegative?`, since those are the terms the literature uses. but i think at that point we might as well just use `!1.positive` ;)
<FromGitter> <Blacksmoke16> on another note, does this make sense
<woodruffw> j8r: FWIW i think you'd be 100% right if `Complex` inherited from `Number`, since (AFAIK) the literature isn't as settled on `sgn` for complex numbers. but `Number` seems to only represent `R` in crystal, so i think the definition of "positive" and "negative" in the PR is 100% sound
<FromGitter> <Blacksmoke16> `[1,2,3].to_xml` # =>
<FromGitter> <Blacksmoke16> ``` <0>1</0> ⏎ <1>2</1> ⏎ <2>3</2> ⏎ <3>foo</3> ⏎ ``` [https://gitter.im/crystal-lang/crystal?at=5d0ed31bd4535e477a853816]
<FromGitter> <Blacksmoke16> not sure what other options id have...
<FromGitter> <tenebrousedge> does `hash` implement `to_xml` ?
<FromGitter> <Blacksmoke16> not directly
<FromGitter> <Blacksmoke16> shh, WIP :P
<FromGitter> <Blacksmoke16> was thinking i could do something with the type of the value, but that would tricky
<FromGitter> <Blacksmoke16> have to deal with unions and stuff
<FromGitter> <Blacksmoke16> this is prob fine id say?
<FromGitter> <tenebrousedge> I mean, I'm not sure what exactly I would expect from a `to_xml` method. Probably a well-formed document
meltingwax has joined #crystal-lang
<woodruffw> @j8r: btw, is your native tongue french? i did some searching and apparently this is a common point of confusion, since french uses "positif" to refer to `>= 0`
<FromGitter> <Blacksmoke16> @tenebrousedge that was just a snippet of the actual xml version of the array
<FromGitter> <Blacksmoke16> The full output has the xml Dec and root element
<FromGitter> <tenebrousedge> well. In that case, probably something like `<numbers type="array"><value>0</value><value>1</value><value>2</value></numbers>`
<FromGitter> <Blacksmoke16> That's an option
<FromGitter> <Blacksmoke16> The tricky thing is more so the tag of each value
<FromGitter> <tenebrousedge> why?
<FromGitter> <Blacksmoke16> Either use index or something generic like value or item
<FromGitter> <Blacksmoke16> Because you don't have anything telling it what it should be
<rkeene> Usually XML lists end up looking like this: <items><item>0</item><item>1</item></items>
<FromGitter> <Blacksmoke16> Vs like {"key":[1,2,3]}
<FromGitter> <tenebrousedge> I don't think `<0>` is technically valid xml
<FromGitter> <tenebrousedge> has to start with `[a-zA-Z_]`
<FromGitter> <Blacksmoke16> Probably not, I like "item" better
<FromGitter> <Blacksmoke16> As a fallback
<rkeene> It's even worse for related lists check out Apple's plist format for terribleness
<FromGitter> <watzon> Check out Apple's anything for terribleness
<rkeene> I've mirrored many of my projects onto GitHub now for everyone to enjoy.
<FromGitter> <Blacksmoke16> `[1,2,3,"foo"].to_xml`
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d0edcf44291ad76a5b035d2]
<FromGitter> <Blacksmoke16> or can do `to_xml xml_root: "items"` if you wanted to change `root`
<FromGitter> <Blacksmoke16> id say that would work
<FromGitter> <tenebrousedge> πŸ‘
<FromGitter> <Blacksmoke16> anyone remember who had this gist for statically compiling using docker?
<FromGitter> <Blacksmoke16> https://github.com/j8r/dockerfiles/tree/master/crystal-alpine found it for the record
alex`` has quit [Ping timeout: 245 seconds]
<FromGitter> <Blacksmoke16> ```code paste, see link``` ⏎ ⏎ :( [https://gitter.im/crystal-lang/crystal?at=5d0ee9ec5bc3210bb7813444]
<FromGitter> <Blacksmoke16> adding `alpine-sdk` to the Dockerfile seemed to fix it
<FromGitter> <Blacksmoke16> @j8r
<FromGitter> <Blacksmoke16> but you prob know more about it than i do
<FromGitter> <Blacksmoke16> just needed `g++`
<FromGitter> <Blacksmoke16> anyone mess with the snap stuff yet?
<FromGitter> <watzon> Not I
<FromGitter> <watzon> What is the syntax for symbols? Can they have any non-whitespace character?
<FromGitter> <Blacksmoke16> `A double-quoted identifier can contain any unicode character including white spaces and accepts the same escape sequences as a string literal, yet no interpolation.`\
<FromGitter> <watzon> That's right, they can contain whitespace, but only with double quotes
<FromGitter> <watzon> That makes writing regex for it interesting
<FromGitter> <watzon> Ehh, I guess I can just duplicate that definition
<FromGitter> <watzon> Something like ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d0ef85441654c559ee4d276]
_whitelogger has joined #crystal-lang
<FromGitter> <Blacksmoke16> ` {4, 5, {6, 7, 8}}.to_xml b, "key"` yea this can get gross
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d0f0007d35d4162a88502c1]
<FromGitter> <tenebrousedge> @watzon should `*` be `+` ?
<FromGitter> <watzon> True enough
<FromGitter> <Blacksmoke16> esp if you go more than two, but hm
<FromGitter> <Blacksmoke16> dunno what else you could do
<FromGitter> <tenebrousedge> does HAML work for xml?
<FromGitter> <Blacksmoke16> no idea
<FromGitter> <Blacksmoke16> i could pass the key down to each sub tuple/array
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d0f009dd4535e477a86889f]
<FromGitter> <Blacksmoke16> i guess thats stil valid?
<FromGitter> <tenebrousedge> using a `Hash` seems simpler
<FromGitter> <Blacksmoke16> well sure, but im currently working on supporting to_xml on the primitive types
<FromGitter> <Blacksmoke16> like
<FromGitter> <watzon> Ahh that's cool
<FromGitter> <watzon> An arduous task
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/73w9
<FromGitter> <Blacksmoke16> but since yaml nor json requires keys for this kinda stuff its a bit diff setup
<FromGitter> <Blacksmoke16> https://www.xml.com/pub/a/2006/05/31/converting-between-xml-and-json.html basing my journey off those 7 examples :P
<FromGitter> <Blacksmoke16> seems to cover mostly everything common at least
<FromGitter> <watzon> What is your current thought process for primitive types like `Int32`?
<FromGitter> <tenebrousedge> I mean, I get that, but doing that for `Array` just seems like a poor fit. XML is kinda inherently key => value
<FromGitter> <Blacksmoke16> yea ofc, but i cant just *not* implement it
<FromGitter> <Blacksmoke16> @watzon
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d0f01e84b0b7b477b45d88c]
<FromGitter> <Blacksmoke16> `{"name": "Jim", "age": {"@unit": "years", "#text": 12}}.to_xml`
<FromGitter> <Blacksmoke16> currently generates
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d0f023c1e35ef14b6a204b9]
<FromGitter> <Blacksmoke16> just stringifying everything, since its all just text
<FromGitter> <mistergibson> @Blacksmoke16 : how do you intend upon handling array elements? Just curious.
<FromGitter> <watzon> Why the different prefixes for `@unit` and `#text`?
<FromGitter> <tenebrousedge> does `to_xml` take a block argument?
<FromGitter> <Blacksmoke16> @watzon so you can add an attribute to that key, plus its text value
<FromGitter> <Blacksmoke16> `<age unit="years">12</age>`
<FromGitter> <Blacksmoke16> @mistergibson `[1,2,3].to_xml` atm is
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d0f02c55bc3210bb7820589]
<FromGitter> <mistergibson> ah ok - thanks
<FromGitter> <Blacksmoke16> OR if the array has a key
<FromGitter> <Blacksmoke16> like a hash with an arrray value
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d0f02ef4b0b7b477b45e0cb]
<FromGitter> <Blacksmoke16> `{arr: [1, 2, 3]}`
<FromGitter> <Blacksmoke16> @tenebrousedge no, but it takes a string that would change the root element name
<FromGitter> <Blacksmoke16> what would the block do?
<FromGitter> <mistergibson> @Blacksmoke16 : would it be of any value to add a 'type' attribute to the array item tag?
<FromGitter> <Blacksmoke16> i dont know
<FromGitter> <watzon> @Blacksmoke16 ahh ok that makes sense
<FromGitter> <mistergibson> I'm just thinking of the reverse process
<FromGitter> <watzon> What is the output of `3.to_xml`
<FromGitter> <Blacksmoke16> ```<?xml version="1.0" encoding="UTF-8"?> ⏎ <root>3</root>``` [https://gitter.im/crystal-lang/crystal?at=5d0f0354207f6e6963e9329b]
<FromGitter> <Blacksmoke16> yea, i didnt get to `from_xml` yet :P
<FromGitter> <mistergibson> I made a inline-type json export/import method set and found it pretty handy
<FromGitter> <Blacksmoke16> im imaging its going to be a PITA
<FromGitter> <watzon> I guess that makes sense
<FromGitter> <Blacksmoke16> yea, xml is weird. I cant imagine you can solve every case
<FromGitter> <mistergibson> yeah, xml is a PITA --> I use a lot of JSON consequently.
<FromGitter> <Blacksmoke16> like even if i added `type="array"` attribute would still need to be able to parse xml *not* generated by it
<FromGitter> <mistergibson> right
<FromGitter> <mistergibson> that's the rub I suppose
<FromGitter> <Blacksmoke16> prob going to be like `if child has more than 1 element of same name then assume array`
<FromGitter> <tenebrousedge> that seems like a thing
<FromGitter> <Blacksmoke16> yea, is how did it in pattern 6 on that site
<FromGitter> <Blacksmoke16> http://badgerfish.ning.com/ looks like another convention
<FromGitter> <Blacksmoke16> either way its going to involve JSON objects that contain implementation key/values for building out the json
<FromGitter> <Blacksmoke16> which isnt terrible
<FromGitter> <Blacksmoke16> esp for my use case
<FromGitter> <Blacksmoke16> ever use jq?
wmoxam has joined #crystal-lang
thodoris has quit []
<oprypin> woodruffw: @Blacksmoke16: never ever say that a method is "missing" even it happens to exist in Ruby. that stopped being an argument many years ago. and Ruby is frankly bloated.
<oprypin> * "when", not "even"
<FromGitter> <tenebrousedge> "bloated" == "contains methods that I don't like"
pvn has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
pvn has quit [Quit: Leaving.]
thodoris has joined #crystal-lang
<FromGitter> <girng> I've been a code crystal warrior for the past 24 hours
<FromGitter> <girng> I'm on fire baby
<FromGitter> <girng> who is here is still using xml lol
<FromGitter> <vladfaust> I'm currently binding libpq. In https://www.postgresql.org/docs/8.1/libpq-exec.html got `const int *paramLengths`. How can I bind unknown-size array of ints?
<FromGitter> <bew> It's simply a pointer then
<FromGitter> <vladfaust> So it would be `fun foo(param_lengths : LibC::Int)` and `foo([1, 2].to_unsafe)`?
<FromGitter> <bew> I think so yes
<FromGitter> <vladfaust> And how to deal with `const char * const *paramValues`, @bew?
<FromGitter> <vladfaust> > paramValues[] specifies the actual values of the parameters. A null pointer in this array means the corresponding parameter is null; otherwise the pointer points to a zero-terminated text string (for text format) or binary data in the format expected by the server (for binary format).
<FromGitter> <vladfaust> Oops πŸ˜…
<FromGitter> <vladfaust> Thanks, @bew, you've helped me!
<FromGitter> <bew> ;)
<FromGitter> <bew> About the `const`, they are not important when writing the actual bindings, they basically indicate that the value passed won't be changed by the function, but it's only semantic
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
<FromGitter> <r00ster91> How can I spawn two fibers (or more) with an infinite loop in it (but I'll break out of the loop after some time) and make them all start running at the same time? `spawn { ... }; spawn { ... }; Fiber.yield` only runs the first fiber and then *after* that the second fiber, also tried other stuff with `Fiber.yield`
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
<FromGitter> <j8r> @Blacksmoke16 I've removed g++, because it's not needed on all projects
<FromGitter> <vladfaust> @r00ster91 "start running at the same time" looks like multi-threading, which not the case yet
laaron has quit [Remote host closed the connection]
<FromGitter> <vladfaust> Infinite loop blocks the runtime, there can be only one inf loop per thread
<FromGitter> <j8r> Only needed if there is C++, like in the Crystal compiler. Most Crystal projects don't use this language
<FromGitter> <r00ster91> wait, really? that is not possible? oh well that's another reason then for multi-threading. I thought the only reason is because then all of the computer's threads can be used
<FromGitter> <vladfaust> But you can put `Fiber.yield` *inside* loops, so there will be reschedules. Note, however, that it (switching between fibers) would be slow in this case. I suggest you you to call `sleep 0.1` instead
laaron has joined #crystal-lang
<FromGitter> <r00ster91> ah, inside the loop. thats a good idea
<FromGitter> <j8r> IIRC there is someone here using GitLab CI – who he was?
<FromGitter> <r00ster91> I think it was jokke: https://gitter.im/crystal-lang/crystal?at=5c53243293fe7d5ac01fb162
<FromGitter> <j8r> Thanks @r00ster91 , that's because there is an issue I can't answer on my dockerfiles repo: https://github.com/j8r/dockerfiles/issues/3
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
laaron has quit [Client Quit]
laaron has joined #crystal-lang
<FromGitter> <bestwebua> Hello! Is there a way to use instance variables in modules, like in ruby:
<FromGitter> <bajro17> Is it possible for example to find shard who has in there dependency Kemal
<FromGitter> <r00ster91> @bestwebua no, that is not possible right now. maybe in the future but I don't know
<FromGitter> <bestwebua> Thank you, @r00ster
<FromGitter> <bajro17> @r00ster91 I think I was find this before on shards.info/ or crystalshards.xyz but I dont remember where :(
<FromGitter> <r00ster91> If you really don't find it then I'd just create my own shard which has Kemal as the dependency
<FromGitter> <j8r> Variables in modules?
<FromGitter> <j8r> You can use class vars, `@@cvar`
<FromGitter> <j8r> @bestwebua
<FromGitter> <bestwebua> @j8r Yup, like in this case: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d0f7379bc834f76a4cc99a4]
yxhuvud has joined #crystal-lang
<FromGitter> <j8r> woodruffw I speak french yes. Perhaps `positif` means `>= 0`, not sure. We have always been told to write `strictement positif`
<FromGitter> <j8r> @bestwebua I don't know, what do you want to achieve?
<FromGitter> <j8r> there is no instance of a module, but you can have define `class_property` inside a module
<FromGitter> <j8r> like this https://play.crystal-lang.org/#/r/73yo
alex`` has joined #crystal-lang
devil_tux has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
devil_tux has quit [Ping timeout: 246 seconds]
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
DTZUZO has quit [Ping timeout: 245 seconds]
alex`` has quit [Ping timeout: 272 seconds]
sz0 has joined #crystal-lang
alex`` has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
devil_tux has joined #crystal-lang
<FromGitter> <vladfaust> Looks like a bug for me https://play.crystal-lang.org/#/r/73zi
<FromGitter> <Blacksmoke16> might be conflicting with https://crystal-lang.org/api/master/Class.html#cast(other):self-instance-method?
<FromGitter> <vladfaust> How to convert `Bytes` to `Char`?
<oprypin> vladfaust, please define how the conversion should work
<FromGitter> <vladfaust> I'm parsing from PostgreSQL `char` type. It's a number of bytes, I guess
<FromGitter> <vladfaust> @Blacksmoke16 nope https://play.crystal-lang.org/#/r/73zu
<oprypin> that doesnt help much
<FromGitter> <vladfaust> Okay
<FromGitter> <Blacksmoke16> id just throw it in `String.new bytes`?
<FromGitter> <vladfaust> `String.new(bytes).chars.first`
<FromGitter> <vladfaust> I wonder if there is more efficient way
<FromGitter> <r00ster91> I would look at String.new's internals
<FromGitter> <r00ster91> uuh can'
<FromGitter> <Blacksmoke16> i have idea
<oprypin> i mean, providing an inefficient implementation is a great way of defining it
<FromGitter> <vladfaust> @r00ster91 a char can consist of multiple bytes
<FromGitter> <r00ster91> oh
<oprypin> `IO::Memory.new(that).read_char` is also not that great but probably still better
<FromGitter> <vladfaust> Well, UTF-8 is always 4 bytes IIRC
<oprypin> no
<oprypin> 8 stands for 1 byte, anyway
<FromGitter> <vladfaust> > UTF-8 is a variable width character encoding capable of encoding all 1,112,064 valid code points in Unicode using one to four 8-bit bytes.
<FromGitter> <vladfaust> Indeed
<oprypin> utf-8 can store a codepoint between 1 and 6 bytes, but 4 is covers all of unicode so more is impossible
<oprypin> i mean "never happens" rather than impossible
<FromGitter> <vladfaust> I see
<woodruffw> oprypin: i think there's a world of difference between `positive?` and `negative?`, which i consider "missing", and most of the junk in ruby's stdlib ;)
alex`` has quit [Ping timeout: 245 seconds]
alex`` has joined #crystal-lang
<oprypin> well i think it's exactly part of the junk
<oprypin> mainly because if u ask someone what "positive" means,
<oprypin> 70% ppl will say "obviously > 0" and 20% will say "obviously >= 0"
<FromGitter> <tenebrousedge> the 20% are wrong, and the documentation can make that clea
<oprypin> or u can just write "> 0"
<FromGitter> <tenebrousedge> or you can use semantic methods and avoid embedding primitive values in your program
<woodruffw> yeah, i think the mathematical community is settled on what "positive" means. it's only one specific human language that has this problem, and the API isn't written in that language
<oprypin> this is not semantics, it's just a made up name for what literally is `> 0`
<woodruffw> i'm going to go out on a limb and guess that there are other words in the crystal stdlib that mean other things in not-english, and that they cause confusion when people run into them
<oprypin> yep there sure are
<oprypin> most often because they were copied from Ruby
<oprypin> u know what, that last sentence is unsubstantiated
<woodruffw> and ruby copied them from somewhere else for the most part. that's part of the cost of building a language that people can get right into
<woodruffw> (and it's one of the reasons i really like programming in crystal)
<woodruffw> hey, i don't have any evidence either, let's not go injecting truth into this ;)
<FromGitter> <j8r> Being in Ruby, or similar methods exists isn't a strong enough argument.
<FromGitter> <j8r> I'm curious of your use case?
<woodruffw> mostly what @tenebrousedge mentioned above, i think it makes block and conditional comprehension much cleaner
<woodruffw> it's definitely not the end of the world to have it
<woodruffw> to not have it*
<FromGitter> <tenebrousedge> it's also a trivial addition
<woodruffw> right, and it aligns with "developer happiness" as a PL philosophy. but that's also a ruby thing, and i'll need to reevaluate future PRs to crystal if that's not a design goal here as well
<FromGitter> <tenebrousedge> that something exists in Ruby is not necessarily an argument *against* its inclusion, but it's not *sufficient*
<FromGitter> <j8r> exactly
<FromGitter> <tenebrousedge> and some things are either not possible or not a remotely good idea (`send`)
<FromGitter> <j8r> that's partially possible https://github.com/j8r/crystal-object-send
<FromGitter> <tenebrousedge> yes, as a macro, but not possible at runtime, right?
<FromGitter> <j8r> not with the bare stdlib
<FromGitter> <j8r> this library use macros to generate an basic interpreter, a huge `case/when`
<FromGitter> <j8r> that will evaluate the expression at runtime
<FromGitter> <bajro17> Can someone tell me why I get epoch dont exist
<FromGitter> <bajro17> when I use it for time
<FromGitter> <bajro17> Time.now.epoch.to_i
<FromGitter> <bajro17> undefined method 'epoch' for Time
<FromGitter> <Blacksmoke16> It's to_unix now
<FromGitter> <r00ster91> do you want `Time::UNIX_EPOCH` maybe?
<FromGitter> <Blacksmoke16> Time.now is deprecated as well
<FromGitter> <Blacksmoke16> Use local or utc
<FromGitter> <j8r> Use `Time#unix`
<FromGitter> <Blacksmoke16> Or better yet yea
<FromGitter> <bajro17> what to use for secure_random?
<FromGitter> <bajro17> also not find
<FromGitter> <bajro17> its one of all packages I try compile
<FromGitter> <bajro17> old*
<FromGitter> <j8r> @bajro17 I suggest you to search in the api docs
<FromGitter> <bajro17> I try cant find secure_random
<FromGitter> <Blacksmoke16> Random::Secure
<FromGitter> <Blacksmoke16> I don't think that's a thing anymore
<FromGitter> <Blacksmoke16> You just use the random module methods on
<FromGitter> <Blacksmoke16> Random::Secure
<FromGitter> <j8r> search keywords @bajro17
<FromGitter> <j8r> if you don't find it, it means it has changed
<FromGitter> <j8r> also look at the changelog https://github.com/crystal-lang/crystal/blob/master/CHANGELOG.md
DTZUZO has joined #crystal-lang
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
<FromGitter> <jgaskins> I'm trying to define a method that type-casts values returned from Neo4j into given classes and takes a block to process each result row (to stream it to the application) https://gist.github.com/jgaskins/c1e92a57f3ac8a9953851d1e151b3125
<FromGitter> <jgaskins> And I'm running into the issue where I need to tell the compiler that I need instances of those classes rather than the classes themselves in the block. :-\
<FromGitter> <jgaskins> no overload matches 'Array(Tuple(Array(Int32)))#<<' with type Tuple(Array(Int32).class)
<FromGitter> <jgaskins> Any ideas?
<FromGitter> <Blacksmoke16> looks like you're trying to push an `Array(Int32).class` into your array
<FromGitter> <Blacksmoke16> notice the `.class`,
<FromGitter> <jgaskins> Yes, my question is how do I tell the compiler that the value will actually be `Array(Int32)` and not `Array(Int32).class`.
<FromGitter> <Blacksmoke16> are you sure it is?
<FromGitter> <Blacksmoke16> hard to say without the full code
<FromGitter> <jgaskins> Did you check the gist I linked?
<FromGitter> <Blacksmoke16> yes but that doesnt include where the << actually happens
<FromGitter> <Blacksmoke16> or is that behind the scenes or something?
<FromGitter> <jgaskins> Oh, I see what you mean. I updated the gist to show what that error is from.
<FromGitter> <jgaskins> It's not the exact code, but the `<<` call was inside the block.
<FromGitter> <Blacksmoke16> from what i can tell `results` is like `[{[1,2]}]` but you're trying to push a `{[Int32, Int32}]`
<FromGitter> <Blacksmoke16> but i dont know enough about what is going to say where/why that is happening
<FromGitter> <jgaskins> I have the code working without the block, I just want to be able to customize what happens with each row. Since I set type of the block to be `Tuple(*TYPES) -> Nil`, the compiler thinks the row will literally be `{ User, Group }` instead of `{ a_user, a_group }`.
<FromGitter> <Blacksmoke16> ah ok
<FromGitter> <jgaskins> I don't want it to *always* just be an array of results in case it's a huge array. Using the block to stream the results as they come back from the DB.
<FromGitter> <Blacksmoke16> i dont suppose you could just do like `.as(xx)`?
<FromGitter> <Blacksmoke16> or just not type the block?
<FromGitter> <jgaskins> Not typing the block doesn't let you pass args to it, from what I can tell.
<FromGitter> <Blacksmoke16> really?
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/740m seems to be fine
<FromGitter> <Blacksmoke16> dont even really need the `&block`
<FromGitter> <Blacksmoke16> is mainly for making it easier to see it takes a block
<FromGitter> <jgaskins> Ugh, I kept getting an arg mismatch. One sec, lemme reproduce it.
<FromGitter> <jgaskins> lol I'm gonna be pissed at myself if I've gone down this rabbit hole for this long and I could've avoided it by just not typing the block πŸ˜‚
<FromGitter> <Blacksmoke16> :p
sz0 has quit [Quit: Connection closed for inactivity]
<FromGitter> <jgaskins> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d0fce637456db0bb842ceea]
<FromGitter> <jgaskins> This is the reason I thought you needed to specify the block arg types.
<FromGitter> <Blacksmoke16> what if you remove the `()` around the block arg?
<FromGitter> <jgaskins> I run into it all the time, and it usually goes away if I specify the types.
<FromGitter> <jgaskins> Same error
<FromGitter> <Blacksmoke16> and what does `exec_cast` look like?
<FromGitter> <jgaskins> Updated the gist with this definition of `exec_cast` https://gist.github.com/jgaskins/c1e92a57f3ac8a9953851d1e151b3125
<FromGitter> <Blacksmoke16> hm
<FromGitter> <jgaskins> It has a few different implementations for convenience β€”Β `NamedTuple` vs `Neo4j::Map` and block vs no-block. No-block is the one that worked before, I'm just trying to reimplement it in terms of the new one that takes a block.
<FromGitter> <jgaskins> Specifically, if you don't pass a block, it'll return the array of all the results. If you do pass the block, it'll call the block each time it receives a result from the DB.
<FromGitter> <Blacksmoke16> dunno, dont have any idea :/
sagax has joined #crystal-lang
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
jokke has quit [Ping timeout: 245 seconds]
jokke has joined #crystal-lang
<FromGitter> <sirbroadwell> Hi! Hi! ⏎ I would like to know what you think about the use of Crystal in the pro world, if you have any examples of companies using it
<FromGitter> <Blacksmoke16> to name a few
<FromGitter> <jgaskins> GrapheneDB and CloudAMQP also use it for some internal services.
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
<FromGitter> <asterite> Generic type arguments can be types or integer literals, because they are needed for StaticArray (and mainly for C interop). I wouldn't mind having any kind of literal there, like String, Symbol, or even array literals. I think for example Haskell has compile-time values like those. The thing is, we would need a really good use case for all of that to introduce it in the language.
<FromGitter> <Blacksmoke16> has anyone tried to build a snap yet?
<FromGitter> <Blacksmoke16> i installed edge and i can see `crystal` in `snapcraft list-plugins`
<FromGitter> <tenebrousedge> it already sounds better than building a deb
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d100688d4535e477a8f1dc4]
<FromGitter> <Blacksmoke16> but is what im getting
<FromGitter> <Blacksmoke16> i figured it out
<FromGitter> <Blacksmoke16> its at least doing something now
<FromGitter> <Blacksmoke16> neat it worked
<FromGitter> <Blacksmoke16> is pretty slick
<FromGitter> <Blacksmoke16> can also include other snap packages in your snap, if it depends on some other lib
<FromGitter> <Blacksmoke16> check this out
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d100b3341654c559eedb29b]
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d100baad35d4162a88dc459]
<FromGitter> <Blacksmoke16> converts input to JSON, pipes to `jq`, converts resulting json to desired format
<FromGitter> <tenebrousedge> huh
<FromGitter> <Blacksmoke16> `{"names": [.[] | .name]}` is the filter file
<FromGitter> <Blacksmoke16> currently accepts json/yaml and can output json/yaml/xml
<FromGitter> <mistergibson> sweet --> good one @Blacksmoke16
<FromGitter> <Blacksmoke16> back to a question i asked a while ago, is there a way to see if STDIN is empty/nil?
<FromGitter> <Blacksmoke16> i tried `STDIN.peek` but seems it blocks
<rkeene> Blacksmoke16, I maintain an AppFS repository with Crystal in it
<FromGitter> <dscottboggs_gitlab> I think you have to do a timeout on reading from STDIN
<FromGitter> <dscottboggs_gitlab> There's also ARGF, if you weren't aware
<rkeene> Blacksmoke, To see if there's pending data you can do a select() with a really low timeout, not sure what the Crystal interface to that is
<FromGitter> <Blacksmoke16> im using ARGV for the args that come after the binary
<FromGitter> <Blacksmoke16> but data that gets piped in from the echo im assuming is going to STDIN?
<FromGitter> <dscottboggs_gitlab> yeah
<FromGitter> <dscottboggs_gitlab> Idk tbh I'm kinda confused about the difference between ARGF and STDIN myself
<FromGitter> <dscottboggs_gitlab> oh wow, I just looked it up and I don't get that at all, what is happening there
<FromGitter> <dscottboggs_gitlab> Yeah I think your only option is using `spawn` to timeout on listening to `STDIN`
<FromGitter> <Blacksmoke16> hrm
<FromGitter> <Blacksmoke16> that seems less than ideal
<FromGitter> <dscottboggs_gitlab> ``````
<FromGitter> <dscottboggs_gitlab> pretty sure that's how it works with most languagues that allow asynchronous reads from STDIN
<FromGitter> <Blacksmoke16> do you know what that spawn would look like
<FromGitter> <dscottboggs_gitlab> yeah just a sec
<FromGitter> <Blacksmoke16> <3
<rkeene> For example in POSIX you could just select() with a low timeout (1 ms or so) to determine if there's pending data
<FromGitter> <dscottboggs_gitlab> ```code paste, see link``` ⏎ ⏎ something like that? [https://gitter.im/crystal-lang/crystal?at=5d101025007cff7a820a287d]
<rkeene> Not sure what the Crystal interface to select looks like
<FromGitter> <dscottboggs_gitlab> it might be `select do` but I think it's just `select`
<FromGitter> <Blacksmoke16> TIL thats a thing?
<FromGitter> <Blacksmoke16> :P
<FromGitter> <dscottboggs_gitlab> oh actually I think my example is wrong
<FromGitter> <dscottboggs_gitlab> oh, yeah, hang on
<FromGitter> <dscottboggs_gitlab> https://carc.in/#/r/7424