RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.27.1 | 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
<FromGitter> <Sija> same as in ruby btw
<mps> understand, but anyway ask, what about `contain({ "key" == "value" })`
<mps> seems more natural to my eyes
<FromGitter> <Sija> well, it seems that your eyes ain't trained for ruby/crystal since thing like that would create a `Tuple(Bool)` (`{false}`)
<FromGitter> <Sija> such construct is simply unnatural in ruby/crystal
<FromGitter> <dscottboggs_gitlab> haha
<mps> agreed, especially ruby
<FromGitter> <Sija> so I'm not sure what's with changing the standard language semantics ;)
<mps> I just asked, nothing more
<FromGitter> <Sija> sure, np :)
<mps> I'm new to crystal and don't used ruby, this question was from my perl experience
<FromGitter> <Sija> right, ruby background gives you pretty compatible experience, perl is a different beast, that's for sure
<mps> yes, yes, trying to adapt to new syntax and idioms
<FromGitter> <j8r> contain does includes under the ground
<FromGitter> <Sija> in terms of syntax I'd definitely recommend checking out ruby first, since that's the main inspiration for it
<mps> Sija: I bought "Programming Crystal" and think it enough, although I read some public ruby books and guides few months ago to understand crystal
<FromGitter> <j8r> I would suggest to rename the contain macro to includes?
<mps> now I have to work with java/kotlin and I'm angry because don't have enough time for crystal
<FromGitter> <j8r> or rename includes? to contain... lol not going to happen
<FromGitter> <Sija> @j8r IMO that's splitting hairs
<FromGitter> <Sija> you're talking about synonyms, IMO it would be better to extend the impl
<FromGitter> <j8r> it's would be more consistent to name it includes at least, no?
<FromGitter> <j8r> extend what?
<FromGitter> <Sija> impl = implementation
<FromGitter> <j8r> i know, but which one?
<FromGitter> <j8r> what to you mean by extending
<FromGitter> <Sija> #7498
hightower2 has quit [Ping timeout: 240 seconds]
<FromGitter> <Sija> that's what I mean by extending :)
<FromGitter> <Sija> @mps sorry to hear java being mentioned… I hope you'll find moar time for Crystal :)
<mps> Sija: eh, must get money for living, that's a life. :)
<FromGitter> <Sija> yup, *man gotta do what man gotta do*… ;)
<FromGitter> <j8r> I don't get it: the hash doesn't contain a hash @Sija ?
<FromGitter> <j8r> This should be a Tuple
<FromGitter> <Sija> @j8r ...
<FromGitter> <Sija> yup, you don't get it, let's walk over it line by line then
<FromGitter> <j8r> This is
<FromGitter> <Sija> so… here you have a line in which I explicitly check if both, the *expected* and *actual* value are *both* of type `Hash`
<FromGitter> <Sija> `if expected_value.is_a?(Hash) && actual_value.is_a?(Hash)`
<FromGitter> <Sija> in this way calling `hash.should contain({"key", "value"})` still works
<FromGitter> <Sija> since *expected*value_ is a `Tuple`
<FromGitter> <j8r> If i want to check a contain for `Hash(String, Hash(String, String))`
<FromGitter> <j8r> This becomes messy, even more if there are unions
<FromGitter> <Sija> then you'd do `hash.should contain({"key", hash2})` or...
<FromGitter> <Sija> `hash.should contain({"key" => hash2})`
lucasb has quit [Quit: Connection closed for inactivity]
<FromGitter> <Sija> both cases obviously wouldn't work recursively (checking just for a subset in *hash2*)
<FromGitter> <j8r> Still, the hash doesn't contain hashes in your first example... this doesn't make sense
<FromGitter> <dscottboggs_gitlab> you're...both...right?
<FromGitter> <dscottboggs_gitlab> lol
<FromGitter> <Sija> *hash2* is a hash?
<FromGitter> <Sija> @j8r `hash.should contain({"key", {"foo" = "bar"}})` makes it more readable for you
<FromGitter> <j8r> Yes @Sija , with Tuples I understand
<FromGitter> <Sija> and that was a 1st example, so now I'm confused about which example you're talking about...
<FromGitter> <j8r> The above link, however, is for me not clear
<FromGitter> <Sija> what exactly is not clear for you?
<FromGitter> <j8r> That's `Hash(String, Int32)` contain `Hash(String, Int32`
<FromGitter> <j8r> It doesn't.
<FromGitter> <Sija> why not?
<FromGitter> <j8r> Because to be consisten with includes, it should contain `Tuple(String, Int32)`, not `Hash`
<FromGitter> <Sija> `if expected_value.is_a?(Hash) && actual_value.is_a?(Hash)`
<FromGitter> <Sija> that's the line which makes it work for this specific case
<FromGitter> <Sija> did I managed to clear it up for you?
<FromGitter> <j8r> Sure. So, `includes?` can be modified to avoid this hack? I don't know
<FromGitter> <Sija> perhaps it would be even better off as another method
<FromGitter> <Sija> using it in `#includes?` would solve the issue with `contain` without any need of modification
<FromGitter> <Sija> I'd say that's a good starting point for discussion
<FromGitter> <Sija> personally I'd even prefer to have it baked in into the `Hash` itself since it's pretty useful outside of spec scenario
<FromGitter> <j8r> The main issue to fix was essentially a naming one
<FromGitter> <Sija> that was an issue you've brought, not the *main* one
<FromGitter> <Sija> > This issue came up for me when I was doing crystal spec with `contains`. Is there an equivalent for `has_key?`? Not sure why `includes?` doesn't have the same behavior...
<FromGitter> <j8r> Citing @arnavb : > This issue came up for me when I was doing crystal spec with contains. Is there an equivalent for has_key?? Not sure why includes? doesn't have the same behavior...
<FromGitter> <j8r> Yes, a naming one
<FromGitter> <j8r> If there was only includes, no questions ask if contain is the same as includes or not
<FromGitter> <Sija> ok, whatever
Gasher_ has joined #crystal-lang
Gasher has quit [Read error: Connection reset by peer]
Gasher_ has quit [Remote host closed the connection]
Gasher_ has joined #crystal-lang
f1refly has quit [Ping timeout: 257 seconds]
f1refly has joined #crystal-lang
smurfendrek123 has joined #crystal-lang
<smurfendrek123> Hello, why does type inference fail for my @cells variable? https://paste.fedoraproject.org/paste/PhqEoxKMU2ukGmiX5vYQvw
<smurfendrek123> The issue seems to be that i'm cloning an array passed as an argument, Why does the type inference not work when cloning an array?
<smurfendrek123> How can i assign a class variable to a clone of a method argument?
<FromGitter> <dscottboggs_gitlab> @smurfendrek123 https://carc.in/#/r/6eig it works if you remove the `protected` and `private`, and define the type in the top level. ⏎ ⏎ You had 2 issues -- 1 you were defining a type in a method, which you can't do, and 2 you weren't defining the type of an instance variable at the top-level.
<FromGitter> <dscottboggs_gitlab> I realize it's kinda a pain but the type inference system isn't super intelligent and you have to define the types of all instance variables *explicitly* in either all initializers or at the top level of a class/struct
<smurfendrek123> FromGitter, but now my getter is public?
<FromGitter> smurfendrek123, I'm a bot, *bleep, bloop*. I relay messages between here and https://gitter.im/crystal-lang/crystal
<FromGitter> <dscottboggs_gitlab> same with class (`@@`)variables
<FromGitter> <dscottboggs_gitlab> that was necessary to make the code that is outside of the class work
<FromGitter> <Blacksmoke16> if you dont want to to be accessible from outside the class just dont use `getter` could just do `@cells : Array(String)`
<smurfendrek123> I know that won't work that's why i commented it out :p
<smurfendrek123> except the protected on initialize
<FromGitter> <dscottboggs_gitlab> you you could do what @Blacksmoke16 said or `private getter`
<FromGitter> <dscottboggs_gitlab> You could make initilize protected if you only use it from a subclass's class methods
<FromGitter> <dscottboggs_gitlab> but for the example I got rid of the private and protected modifiers
<smurfendrek123> Why does protected initialize not prevent me from creating a new row object outside of the module?
<FromGitter> <dscottboggs_gitlab> oh my... https://carc.in/#/r/6eih that's a good question
<FromGitter> <dscottboggs_gitlab> I'm quite surprised myself
<FromGitter> <dscottboggs_gitlab> OH perhaps it's because `#initalize` is an implicitly called method... I think you might have found a bug
<smurfendrek123> I'll make an issue on github then?
<FromGitter> <dscottboggs_gitlab> yeah, check to make sure it hasn't already been raised though, kinda weird this hasn't already been encountered
<FromGitter> <dscottboggs_gitlab> `#initlize` imlicitly defines `self.new` which allocates the memory then calls the initialize method, sets up the GC etc.
<FromGitter> <dscottboggs_gitlab> I think it's working as intended actually
<FromGitter> <dscottboggs_gitlab> https://carc.in/#/r/6eii ⏎ ⏎ `private def initialize` defines a `private def self.new`, but `protected def initialize` just defines a regular `self.new`? I bet `protected def self.some_method` doesn't work
<smurfendrek123> FromGitter, so how do i make my initialize protected?
<FromGitter> smurfendrek123, I'm a bot, *bleep, bloop*. I relay messages between here and https://gitter.im/crystal-lang/crystal
<smurfendrek123> dscottbogs_gitlab should i make my class protected? but what if i want to be able to use the class outside the module, but not create new objects of it
<FromGitter> <dscottboggs_gitlab> smurfendrek123 https://carc.in/#/r/6eir perhaps this will help?
<smurfendrek123> yup, thanks!
<FromGitter> <dscottboggs_gitlab> np!
<FromGitter> <dscottboggs_gitlab> but I do think this is an issue you should raise on github.
_whitelogger has joined #crystal-lang
_whitelogger has joined #crystal-lang
azuri5 has joined #crystal-lang
<FromGitter> <kimvex> Hello, how can I send an object via ⏎ ⏎ `HTTP :: Client.post ("http://server.com/upload", body: {"name_image": "my image", "File": file})`
laaron has quit [Remote host closed the connection]
<FromGitter> <kimvex> When he tried I get this error ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c7b888f53efa91203a50ea1]
<FromGitter> <kimvex> I know it must be a BodyType but I can not understand it
laaron has joined #crystal-lang
<FromGitter> <kimvex> or how they would do to send a file and an extra parameter
<FromGitter> <kimvex> I was able to solve the problem
azuri5 has quit [Read error: Connection reset by peer]
Gasher_ has quit [Remote host closed the connection]
Gasher_ has joined #crystal-lang
lvmbdv has quit [Ping timeout: 255 seconds]
Gasher_ has quit [Remote host closed the connection]
Gasher_ has joined #crystal-lang
hightower2 has joined #crystal-lang
Gasher has joined #crystal-lang
Gasher_ has quit [Read error: Connection reset by peer]
lvmbdv has joined #crystal-lang
ashirase has quit [Ping timeout: 240 seconds]
ashirase has joined #crystal-lang
lvmbdv has quit [Quit: dab]
Gasher has quit [Ping timeout: 245 seconds]
Gasher has joined #crystal-lang
blassin has quit [Quit: The Lounge - https://thelounge.chat]
blassin has joined #crystal-lang
Groogy has joined #crystal-lang
Yxhuvud has joined #crystal-lang
DTZUZO has quit [Ping timeout: 258 seconds]
<FromGitter> <j8r> do someone knows if there is a macro for Time to avoid the use of `date "+%Y.%m.%d"`
<FromGitter> <mamantoha> @j8r there is no such macro :( I'm using `crystal eval 'puts Time.now.to_s("%Y.%m.%d")'`.stringify.chomp
<FromGitter> <j8r> lol that's even worse than `date` @mamantoha :)
<FromGitter> <mamantoha> I know
<FromGitter> <j8r> anyway thanks for the response!
<FromGitter> <mamantoha> I thought about multi-platform support, but actually, I need only Linux
<FromGitter> <j8r> it works also on macos an bsd
Gasher has quit [Remote host closed the connection]
Gasher has joined #crystal-lang
ua_ has quit [Ping timeout: 250 seconds]
Gasher_ has joined #crystal-lang
Gasher has quit [Read error: Connection reset by peer]
ua_ has joined #crystal-lang
<FromGitter> <vladfaust> Hey guys, I'm looking for Phoenix error template in HTML format. Googling and lurking in its repository gave no result, I just can't find the needed file. Moreover, I remember having seen the template adapted for Crystal, but can't find it as well...
lucasb has joined #crystal-lang
ternarysolo has joined #crystal-lang
<FromGitter> <anamba> @vladfaust
<FromGitter> <vladfaust> Yes, thank you very much, @anamba!
ternarysolo has quit [Ping timeout: 250 seconds]
<FromGitter> <arnavb> Regarding yesterday's discussion, issues, and PR's for `contains key:`, the problem I see with `x.has_key("key").should be_true` is that when the assertion fails, then it will output something along "expected true, but got false". Sure, good spec naming would solve this, but IMO a better alternative would be to do what rspec does, which is have a `have_key` matcher. This way, when an assertion fails, it might
<FromGitter> ... fail with something more clear than what I mentioned before. ⏎ ⏎ Regarding checking for a key value pair using `contains`, this isn't feasible for me because I'm dealing with JSON data with lots of nested properties; listing a value for these would just be tedious.
<FromGitter> <whitenoiseoss> ```@[Link("postgres")] ⏎ @[Link("fmgr")] ⏎ @[Link("utils/builtins")] ⏎ lib LibPostgres ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5c7beabacbebcf784a32722b]
<FromGitter> <whitenoiseoss> how can I be sure it's actually finding those libraries?
<FromGitter> <whitenoiseoss> it seems to succeed in building that no matter what I put in Link
<FromGitter> <r00ster91> you first need to define some function and when then a library is not found, you will get an error
<FromGitter> <whitenoiseoss> aha ok, so if `fun blah = blah(stuff*)` it should error if it isn't real
<FromGitter> <r00ster91> unfortunately you cannot output custom errors or something when some of these libraries is not found
<FromGitter> <r00ster91> yep
<FromGitter> <whitenoiseoss> neat, let's give it a shot and see if it's finding all of those
<FromGitter> <r00ster91> the above will probably get you an undefined reference to blah error
<FromGitter> <whitenoiseoss> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c7bebadc1cab53d6f6b67d0]
<FromGitter> <whitenoiseoss> so in this case, this builds, which i'm guessing means everything needed was found okay. but @[Link("lynyrdskynyrd")] doesn't error because until it runs into a problem it doesn't care? it'll attempt to find a lynyrdskynyrd.h each time it sees a new fun?
<FromGitter> <r00ster91> try calling the function
<FromGitter> <r00ster91> I don't think this does anything yet
<FromGitter> <whitenoiseoss> oh ok
<FromGitter> <whitenoiseoss> indeed
<FromGitter> <whitenoiseoss> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c7bec7cd2d62067b738a74a]
<FromGitter> <whitenoiseoss> the cc command needs more -Ls
<FromGitter> <whitenoiseoss> `@[Link(ldflags: "...")]`
<FromGitter> <whitenoiseoss> cool
<FromGitter> <whitenoiseoss> so really all `@[Link("blah")]` does is throw `-lblah` to cc
<FromGitter> <r00ster91> yeah pretty much
<FromGitter> <whitenoiseoss> so @r00ster91 one more question, and this one is more of a doozy
<FromGitter> <whitenoiseoss> I've been writing a special Lua compiler, but @[Link("lua")] worked for that and was up up and away...for writing Postgres extensions there is a lot more work in it...and I need to build with this makefile: https://github.com/postgres/postgres/blob/master/src/makefiles/pgxs.mk
<FromGitter> <whitenoiseoss> can a Crystal Makefile do that?
<FromGitter> <whitenoiseoss> ```PG_CONFIG = pg_config ⏎ PGXS := $(shell $(PG_CONFIG) --pgxs) ⏎ include $(PGXS)``` [https://gitter.im/crystal-lang/crystal?at=5c7bef6d8a7def0752085a4c]
<FromGitter> <whitenoiseoss> if it cannot this might be the end of my `pg-extend-cr` project :P
<FromGitter> <r00ster91> did you run it yet?
<FromGitter> <whitenoiseoss> I did not. I'll try just making it like C and seeing what happens
<FromGitter> <r00ster91> hmm I'm not really sure
<FromGitter> <whitenoiseoss> err, yeah
<FromGitter> <whitenoiseoss> since Crystal has no concept of "make"
<FromGitter> <whitenoiseoss> not really sure what to do with it?
<FromGitter> <r00ster91> what exactly do you mean by "Crystal Makefile"?
<FromGitter> <whitenoiseoss> I don't think Crystal has Makefiles [anymore]
<FromGitter> <whitenoiseoss> but in C, I can build that code and "make install"
<FromGitter> <Blacksmoke16> it does
<FromGitter> <whitenoiseoss> this whole "make install" piece is lost on me in a Crystal context
<FromGitter> <Blacksmoke16> its mostly just used to build compiler and run specs tho
<FromGitter> <r00ster91> oh you mean you want to build your own crystal compiler?
<FromGitter> <whitenoiseoss> oho
<FromGitter> <whitenoiseoss> ohhh
<FromGitter> <whitenoiseoss> lol
<FromGitter> <whitenoiseoss> would I have to build my own Crystal compiler for this?
<FromGitter> <r00ster91> for what? making a postgres extension? No I don't think so
<FromGitter> <whitenoiseoss> hmm
<FromGitter> <whitenoiseoss> let me see how `pg-extend-rs` did this part
<FromGitter> <whitenoiseoss> ah, apparently Rust has a RustC and its own build files
<FromGitter> <whitenoiseoss> and in Go this is done with CGO
<FromGitter> <whitenoiseoss> maybe this isn't something Crystal does?
<FromGitter> <whitenoiseoss> or I'm just dumb and can't figure it out
<FromGitter> <whitenoiseoss> Rust just has a `.clang_arg(format!("-I{}", pg_include))`
<FromGitter> <whitenoiseoss> `@[Link(ldflags: "-I/usr/include/postgresql/11/server")]`
<FromGitter> <whitenoiseoss> this might be a problem rooted in my generated cc line is wrong
<FromGitter> <whitenoiseoss> CGO can actually just use a C Makefile, so that's how that one does it
<FromGitter> <whitenoiseoss> I'm not 100% sure how the Rust one is working, Rust is kind of a cluster syntax-wise
<FromGitter> <dscottboggs_gitlab> you just bind to the .h file and then use crystal build. You just need to get it working as a C library and then do that and LLVM should take care of the rest
Groogy has quit [Quit: WeeChat 2.4]
DTZUZO has joined #crystal-lang
<FromGitter> <whitenoiseoss> @dscottboggs_gitlab I am not sure what you mean. "bind to .h file"? also, "get it working as a C library" -- I am sure you know this, but I am trying to wrap the C libraries, so are you saying I should build the PG extension as a C library and then pull it in as a shared library?
<FromGitter> <whitenoiseoss> my objective would be to have only Crystal source
<FromGitter> <whitenoiseoss> the folks I would be writing this for wouldn't want to maintain C
<FromGitter> <dscottboggs_gitlab> TBH idk, I'm not to great with C building and linking. I'm trying to bind libav right now. I'm on ubuntu 18.04, so I installed `libavcodec-dev` which put all the `.h` files into my `/usr/include` default search paths. Then, to test it out, I wrote this little lib: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c7c07d4e8ea143737a6f5b8]
<FromGitter> <dscottboggs_gitlab> and it worked! I just did `crystal run` and the linking worked
<FromGitter> <whitenoiseoss> oh ok I see
<FromGitter> <whitenoiseoss> yes! that is how my Lua code works.
<FromGitter> <whitenoiseoss> as you can see..one second..
<FromGitter> <dscottboggs_gitlab> `avcodec_version` is defined in `avcodec.h`
<FromGitter> <whitenoiseoss> I am doing that here (lua_api.cr has the bindings)
<FromGitter> <whitenoiseoss> but with postgres, it seems to not be that simple...
<FromGitter> <whitenoiseoss> and I'm not sure what to do about it
<FromGitter> <whitenoiseoss> I am not a C expert, I've just done it here and there
<FromGitter> <dscottboggs_gitlab> same
<FromGitter> <dscottboggs_gitlab> what's going wrong?
smurfendrek123 has quit [Ping timeout: 246 seconds]
<FromGitter> <whitenoiseoss> so, here I can show you the locations it needs
<FromGitter> <whitenoiseoss> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c7c097835c01307536bd2fe]
<FromGitter> <whitenoiseoss> code:
<FromGitter> <whitenoiseoss> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c7c0999cbebcf784a334204]
<FromGitter> <whitenoiseoss> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c7c09b753efa91203a84947]
<FromGitter> <dscottboggs_gitlab> what kind of system are you running?
<FromGitter> <whitenoiseoss> I'm on Ubuntu 16.04 with this, as the Windows Linux subsystem
<FromGitter> <whitenoiseoss> but if you think it would help, I could reboot into Ubuntu 18.10 (Pop OS)
<FromGitter> <dscottboggs_gitlab> ok. And you have libfmgr-dev packages etc installed?
<FromGitter> <dscottboggs_gitlab> no any ubuntu is fine I just wanted to make sure you weren't trying to do this on MacOS lol :p
<FromGitter> <whitenoiseoss> ```code paste, see link```
<FromGitter> <whitenoiseoss> i *think* that's sufficient
<FromGitter> <dscottboggs_gitlab> does `dpkg -L postgresql-server-dev-11` help any?
<FromGitter> <whitenoiseoss> it just shows me the paths to the stuff I showed up at my first paste
<FromGitter> <dscottboggs_gitlab> there's also `libpq-dev` which might be what you're looking for
<FromGitter> <whitenoiseoss> which, as you can see from that one, the fmgr.h and postgres.h are in there
<FromGitter> <whitenoiseoss> hm, let me look at it
<FromGitter> <whitenoiseoss> libpq is the C application programmer's interface to PostgreSQL. libpq is a set of library functions that allow client programs to pass queries to the PostgreSQL backend server and to receive the results of these queries.
<FromGitter> <whitenoiseoss> hmm
<FromGitter> <whitenoiseoss> I guess it can't hurt to try it
<FromGitter> <whitenoiseoss> oh
<FromGitter> <whitenoiseoss> ```libpq-dev is already the newest version (11.2-1.pgdg16.04+1).```
<FromGitter> <whitenoiseoss> in the C and Go versions, the Makefiles call this: ⏎ ⏎ ```PG_CONFIG = pg_config ⏎ PGXS := $(shell $(PG_CONFIG) --pgxs) ⏎ include $(PGXS)``` [https://gitter.im/crystal-lang/crystal?at=5c7c0b9bd2d62067b7397234]
<FromGitter> <whitenoiseoss> which can be seen here: https://github.com/postgres/postgres/blob/master/src/makefiles/pgxs.mk
Groogy has joined #crystal-lang
<FromGitter> <HarrisonB> What are people’s strategies regarding post-test tear down? E.g. closing a server
marmotini_ has joined #crystal-lang
<FromGitter> <paulcsmith> I’ve been using at_exit with pretty good success https://github.com/luckyframework/lucky_flow/blob/a781ba4dc6351481b8a268cf74cbf5213aab2c32/spec/spec_helper.cr#L25
<FromGitter> <paulcsmith> Does anyone know how to use a NamedTuple generic in an instance variable. I’m trying to pass along options to another class but can’t figure out a way
<FromGitter> <paulcsmith> This is the closest I’ve gotten https://play.crystal-lang.org/#/r/6enx
<FromGitter> <paulcsmith> Never mind :) right after I posted I found some source code in crystal that helped
<FromGitter> <paulcsmith> https://play.crystal-lang.org/#/r/6eoe
<FromGitter> <TheOnlyArtz> Hey! How would I be able to add new elements to JSON::Any?
<FromGitter> <Blacksmoke16> would have to look into JSON::Builder or something
<FromGitter> <TheOnlyArtz> But JSON::Any != JSON::Builder
<FromGitter> <TheOnlyArtz> I can't do JSON::Any.field, it's not a thing.
<FromGitter> <Blacksmoke16> yea, iirc JSON::Any is immutable from reading JSON string
<FromGitter> <TheOnlyArtz> O_o
<FromGitter> <TheOnlyArtz> Nice to know
<FromGitter> <TheOnlyArtz> Can I parse Any to Builder?
<FromGitter> <TheOnlyArtz> Actually it looks like I can construct one directly from the desired IO
<FromGitter> <Blacksmoke16> well there you go
<FromGitter> <TheOnlyArtz> I can't manage to have the builder to be readable
<FromGitter> <TheOnlyArtz> I want to be able to read JSON's properties AND change it's properties
<FromGitter> <arnavb> Can someone explain this to me? I don't understand the behavior shown in this: ⏎ ⏎ ```{"a" => nil} ⏎ false ⏎ {"a" => nil} ⏎ true``` ⏎ ⏎ Why is the output different for the hash vs. the JSON and how can I make it output true instead? [https://gitter.im/crystal-lang/crystal?at=5c7c26bc47276019e9ad837c]
<FromGitter> <Blacksmoke16> would have to read it in via JSON.parse, then create a new JSON.build to build new structure with changes
<FromGitter> <TheOnlyArtz> uh that's what I thought about @Blacksmoke16 but it seems like a long way
<FromGitter> <TheOnlyArtz> Ok I will use it
<FromGitter> <Blacksmoke16> @TheOnlyArtz is prob better to look into like creating objects from the json vs json.parse
<FromGitter> <TheOnlyArtz> uh gotcha
<FromGitter> <TheOnlyArtz> Though, according to the website I should be able to go `JSON.to_json(JSON::Builder)`
<Yxhuvud> Hmm. Suppose I have a Slice with the exact same lifetime as the object that creates it (that also is the only thing that refer to elements in it), is it possible to embed it in the owning object somehow?
<FromGitter> <TheOnlyArtz> ```code paste, see link``` ⏎ ⏎ But it's not the case [https://gitter.im/crystal-lang/crystal?at=5c7c2825cbebcf784a34160a]
<FromGitter> <Blacksmoke16> got a playground link?
<FromGitter> <TheOnlyArtz> I'm working on my system
<FromGitter> <TheOnlyArtz> I can link the code
<FromGitter> <arnavb> Ok, so using `== nil` made the example output true. Why does `.nil?` not work though?
<FromGitter> <Blacksmoke16> you only need the `to_json(builder)` when overriding the `to_json` behavior, for like custom types and stuff
<FromGitter> <Blacksmoke16> otherwise everything just works
<FromGitter> <Blacksmoke16> @arnavb give me a min i can take a look
<FromGitter> <Blacksmoke16> i can make an example in a few
<FromGitter> <TheOnlyArtz> https://ghostbin.com/paste/ed9nx @Blacksmoke16 ⏎ Please don't mind the work flow , I just started with crystal today, relevant lines: 45 ` File.write(DB_PATH, JSON.to_json(db_builder))`
<FromGitter> <Blacksmoke16> well you're not actually writing anything
<FromGitter> <TheOnlyArtz> Because it doesn't work
<FromGitter> <Blacksmoke16> sec
<FromGitter> <TheOnlyArtz> I'm trying to write the JSON string
<FromGitter> <TheOnlyArtz> But I can't manage to extract one
<FromGitter> <Blacksmoke16> yea, moment
<FromGitter> <TheOnlyArtz> Sure 😄
<FromGitter> <Blacksmoke16> you should just be able to write the output of the io
<FromGitter> <TheOnlyArtz> What IO?
<FromGitter> <Blacksmoke16> the one that you're passing to `JSON::Builder.new`
<FromGitter> <TheOnlyArtz> But I'm modifying it
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/6epn
<FromGitter> <Blacksmoke16> as opposed to `JSON.to_json(db_builder)`
<FromGitter> <Blacksmoke16> would just be `db_io.to_s`
<FromGitter> <Blacksmoke16> or even `db_io` afaik?
<FromGitter> <TheOnlyArtz> the io changes accordingly?
<FromGitter> <Blacksmoke16> since you're passing that to `JSON::Builder.new db_io`
<FromGitter> <Blacksmoke16> then any changes you do like `db_builder.field bin_id, code`
<FromGitter> <Blacksmoke16> gets written to that io
<FromGitter> <TheOnlyArtz> damn Crystal is neat
<FromGitter> <Blacksmoke16> @arnavb issue seems to be the type of `json["a"]` is still `JSON::Any`
<FromGitter> <TheOnlyArtz> I'm getting ⏎ ⏎ `````` [https://gitter.im/crystal-lang/crystal?at=5c7c2cda53efa91203a93f3e]
<FromGitter> <TheOnlyArtz> Oh wait ok I know what to do
<FromGitter> <Blacksmoke16> Yea you'll need to start/end the document and object
<FromGitter> <Blacksmoke16> but there is prob a better way to go about doing this
<FromGitter> <arnavb> So wait, does that mean I have to explicitly cast it to nil?
<FromGitter> <Blacksmoke16> is there another type it could be?
<FromGitter> <arnavb> It's a nilable type so, it could be a string, int, bool, or nil
<FromGitter> <Blacksmoke16> `p json["a"].as_s?`
<FromGitter> <Blacksmoke16> `.nil?`
<FromGitter> <Blacksmoke16> thats saying try to cast the value as a string, otherwise return nil
<FromGitter> <arnavb> Huh.
<FromGitter> <arnavb> Thanks
<FromGitter> <Blacksmoke16> again, similar to what @TheOnlyArtz is doing it would prob be better to create objects from the json vs just using `JSON.parse`
<FromGitter> <Blacksmoke16> like
<FromGitter> <TheOnlyArtz> ``` db_builder.start_document ⏎ db_builder.field bin_id, code ⏎ db_builder.end_document``` [https://gitter.im/crystal-lang/crystal?at=5c7c2d7247276019e9adb293]
<FromGitter> <TheOnlyArtz> ?
<FromGitter> <arnavb> My initial usage involved JSON::Serializable
<FromGitter> <TheOnlyArtz> It still throws an errro
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/6epu
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c7c2d96212d0c1e1ac8cbe0]
<FromGitter> <arnavb> I was using JSON::Serializable before. Problem with that is that it's so tedious to document huge JSON objects in that format.
<FromGitter> <arnavb> *document the types of
<FromGitter> <Blacksmoke16> will still have to anyway
<FromGitter> <Blacksmoke16> otherwise the type of each property would be `JSON::Any` which is basic a big union of all types
<FromGitter> <Blacksmoke16> @TheOnlyArtz or even
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c7c2dde65ffa019ea802a1b]
<FromGitter> <arnavb> Yeah, it was going fine at first, then I saw this: https://developer.github.com/v3/repos/#get and I pretty much gave up on that.
<FromGitter> <arnavb> Github API doesn't document well what can and cannot be nil, so that kinda sucks as well.
<FromGitter> <Blacksmoke16> could use a macro to generate most of those
<FromGitter> <TheOnlyArtz> ```cr Exception: Write past end_document and before start_document (JSON::Error)```
<FromGitter> <Blacksmoke16> as most are just like `*_url`
<FromGitter> <TheOnlyArtz> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c7c2e57d2d62067b73a5ade]
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/6epv @TheOnlyArtz
<FromGitter> <Blacksmoke16> should be pretty much what you're trying to do
<FromGitter> <TheOnlyArtz> I'm doing what you've done
<FromGitter> <TheOnlyArtz> It just doesn't work
<FromGitter> <TheOnlyArtz> It throws the exception I wrote above
hightower2 has quit [Ping timeout: 250 seconds]
<FromGitter> <Blacksmoke16> prob easier to use an ORM with SQLite tho?
<FromGitter> <TheOnlyArtz> I prefer to solve other than run away
<FromGitter> <Blacksmoke16> fair enough, but is a diff between learning how something works and reinventing the wheel
<FromGitter> <Blacksmoke16> the issue here prob has something to do with the io
<FromGitter> <Blacksmoke16> which im not super familiar with
<FromGitter> <Blacksmoke16> does it work if you define everything within the `"/post"` endpoint?
<FromGitter> <TheOnlyArtz> uh
<FromGitter> <TheOnlyArtz> sec
<FromGitter> <TheOnlyArtz> Nope
<FromGitter> <Blacksmoke16> are just passing the io to file.write?
<FromGitter> <TheOnlyArtz> Yes
<FromGitter> <TheOnlyArtz> 1) the path ofc (as the first param)
<FromGitter> <TheOnlyArtz> The issue is writing with the builder
<FromGitter> <Blacksmoke16> hrm, sadly IO stuff isnt my specialty
<FromGitter> <TheOnlyArtz> Maybe someone else knows / can provide an example of modifying JSON's properties and writing it back to a file?
<FromGitter> <TheOnlyArtz> I'm using ⏎ ⏎ `````` [https://gitter.im/crystal-lang/crystal?at=5c7c32dbb1503b3d7074918f]
<FromGitter> <TheOnlyArtz> And getting the next exception: ⏎ `Exception: Write past end_document and before start_document (JSON::Error)`
<FromGitter> <Blacksmoke16> can you do another pastebin?
<FromGitter> <TheOnlyArtz> sure, sec
<FromGitter> <TheOnlyArtz> I can't manage to copy the code
<FromGitter> <TheOnlyArtz> I'm using nano
<FromGitter> <Blacksmoke16> ok
<FromGitter> <vladfaust> https://carc.in/#/r/6epx
<FromGitter> <TheOnlyArtz> @vladfaust It doesn't work for me using a FILE
<FromGitter> <TheOnlyArtz> https://ghostbin.com/paste/6adv2 @Blacksmoke16
<FromGitter> <Blacksmoke16> hmm
f1refly has quit [Quit: WeeChat 1.6]
hightower3 has joined #crystal-lang
<FromGitter> <dscottboggs_gitlab> does anyone know what this C-type is and how to write it in Crystal? ⏎ ⏎ ```duration_error : StaticArray(StaticArray(Float64, 2) MAX_STD_TIMEBASES)``` [https://gitter.im/crystal-lang/crystal?at=5c7c49c9cbebcf784a34ea96]
<FromGitter> <dscottboggs_gitlab> or is it perhaps just `Pointer(Pointer(Float64))`
<FromGitter> <vladfaust> @Blacksmoke16 found a hack to know ivars on class-level: https://carc.in/#/r/6eqp
<FromGitter> <Blacksmoke16> oo neat
<FromGitter> <Blacksmoke16> 💯
<FromGitter> <vladfaust> Not 100%, as it depends on properties
<FromGitter> <vladfaust> Or getters
<FromGitter> <vladfaust> But it would work in my case :)
marmotini_ has quit [Remote host closed the connection]
<FromGitter> <Blacksmoke16> depends onthe getter id imagine
<FromGitter> <Blacksmoke16> but yee, would work for me as well
<FromGitter> <vladfaust> No access to annotations, unfortunately, as https://crystal-lang.org/api/0.27.2/Crystal/Macros/InstanceVar.html is kinda poor or methods
<FromGitter> <Blacksmoke16> prob could still do it
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
<FromGitter> <straight-shoota> @vladfaust Why not use `TypeNode#instance_vars`?
<FromGitter> <vladfaust> Because they are unknown in class, only in methods
<FromGitter> <vladfaust> That's my usecase: https://carc.in/#/r/6er7
<FromGitter> <Blacksmoke16> yes, having access to that would be great
<FromGitter> <vladfaust> We used to argue with @asterite on this topic. And he said that "at this moment (i.e. in finished macro) instance variables are not fully known blah-blah". But we do have an access to *instance methods*. I feel like it's *unconsistent behavior* and if we have access to instance methods, we should have one to instance variables then.
* FromGitter * vladfaust now afraids that Ary will remove .methods
<FromGitter> <Blacksmoke16> my usecase was for using an annotation on an `property` def to override the getter to be a DB query
ua_ has quit [Ping timeout: 250 seconds]
<FromGitter> <Blacksmoke16> oh well
<FromGitter> <straight-shoota> @vladfaust I'm not very familiar with the semantic stage. But from what I understand, I think the issue is that while both ivars and methods are not fully known, that's not an issue for methods, because they don't need a type. So it doesn't matter if they're fully typed. But instance variables always have a type, but at that point, it might not be known.
ua_ has joined #crystal-lang
<FromGitter> <straight-shoota> I'm not sure this assessment is 100% correct.
<FromGitter> <vladfaust> Makes sense, @straight-shoota
<FromGitter> <vladfaust> https://carc.in/#/r/6erp yes, the type is unknown
<FromGitter> <straight-shoota> Thanks @Blacksmoke16
<FromGitter> <Blacksmoke16> np
<FromGitter> <straight-shoota> @vladfaust with your crazy idea you're derailing your own issue
<FromGitter> <vladfaust> I'd better delete it an leave for separate one
<FromGitter> <vladfaust> Hey, @straight-shoota you've said on Reddit that language is not expected for big changes
<FromGitter> <vladfaust> What's the status on removing Symbols then?
<FromGitter> <vladfaust> I'm not pursuing my own issue, just wondering
<FromGitter> <vladfaust> It is often seen in issues
<FromGitter> <vladfaust> No problem if don't have anything to answer yet, I understand, sorry
<FromGitter> <straight-shoota> Yeah. I wouldn't consider that a huge change. After all, it would just change some semantics but I figure most uses of symbol literals wouldn't even need any changes, when the API switches to enum instead.
<FromGitter> <straight-shoota> There is no decision on that topic though, not even a serious discussion about implications.
<FromGitter> <vladfaust> It should be done anyway -- the discussion, sooner or later
<FromGitter> <straight-shoota> But there is some drive to it, and I can definitely see symbols going away.
<FromGitter> <vladfaust> The team should consider symbol literal arguments, though
<FromGitter> <vladfaust> They bring much beauty to the language and familiar to Ruby devs
<FromGitter> <vladfaust> I mean https://carc.in/#/r/6ers
<FromGitter> <vladfaust> I'm sure there are other usecases where Enums are redundant but some kind of compile checks must be run depending on arguments
<FromGitter> <straight-shoota> It's not a bad idea, but it would be hard to implement. And it would be strange to have two different semantics for symbol literals.
Gasher_ has quit [Remote host closed the connection]