<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> `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>
<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> 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> `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>
<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> 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>
<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>
<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>
<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> 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> 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 :/
<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>
<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