<jhass>
asterite: working on MatchData#[]? and the like ;)
<asterite>
Cool :)
<asterite>
A lot of things are just left overs from when we actually started the language, so I guess there will be many more “small” things like this to clean up
<asterite>
I like it that you kept the [] / []? convention
<jhass>
I think it's a very useful one
<jhass>
I sometimes imagine []? as a shortcut to has_key?() has_match?() etc
<asterite>
I think it lets you program like in Ruby (raise exception) or Go/Erlang where you have to explicitly deal with the “error” branch
<asterite>
Yes, also that
<jhass>
foo[x] if foo[x]?
<jhass>
can always optimize that codepath if turns out to be critical ;)
<jhass>
but I think it reads nicely that way
asterite_ has joined #crystal-lang
<asterite_>
Well, that was fast :)
asterite has quit [Ping timeout: 246 seconds]
asterite_ is now known as asterite
<zamith_>
asterite: I have finished the specs refactor
zamith_ is now known as zamith
<zamith>
you can merge ir if you want
<asterite>
Oh! I saw it yesterday but didn’t have my computer. Then I forgot about it, sorry! (I have a bad memory some times)
<asterite>
Thanks! I’ll merge it soon :)
<zamith>
np
<zamith>
;)
<asterite>
“220 additions and 389 deletions” is very good :)
<asterite>
Ah, I see. Maybe that’s why it’s not there in Ruby
<jhass>
yeah
<jhass>
glibc 2.12 isn' that old either I guess
<asterite>
You were using it for debug purposes?
<jhass>
kind of, I also like it when I can see what things are in my process hierarchy
<asterite>
Well, we could have those methods do nothing in the systems where it’s not supported
<jhass>
I'd rather not, I think that's too unexpected
<asterite>
Ok
<jhass>
mh, I suppose you don't see a way where I could read some json, having only parts of it in json_mapping and dumping the parts I don't have in there back unchanged?
<jhass>
or do that with any method really
<asterite>
Back unchanged as a string or as a Json::Type?
<jhass>
don't really care too much about the crystal side except that I don't know all keys, I know only the key I want to change but not loose everything else
<jhass>
can the regular json parser do it?
<asterite>
Ah, I see. Yes, this is something I also needed a couple of times. I guess we would need to enhance json_mapping to suport it (I think also enhance JSON:PullParser). JSON::Parser could do it, but I don’t know what’s the interaction between it and the pull parser would be
<asterite>
The regular json parser does it, but it works for the whole json, not for parts of it
<asterite>
I guess we could have something like `json_mapping({value: JSON::Any})`, and have JSON::Any.new(JSON::PullParser) create a JSON::Type (the union of all possible types)
<asterite>
It would be nice to use value: JSON::Type, but there’s no way to add methods to a type alias (and I don’t think we’ll have support that)
<jhass>
mh, sounds interesting
<asterite>
We originally wrote the generic parser, but soon realized it would be a pain to work with a generic object like that, because of the static type aspect of the language
<asterite>
so then we thought about the pull parser, and we were able to quickly map objects (without the macro)
<asterite>
then came the macro
<jhass>
:D
<asterite>
so that’s why the parser is like a different beast. But both use the lexer at the bottom
<asterite>
Would you be interested in doing the JSON::Any thing?
<asterite>
I can do it, but I’ll probably do it in some time in the weekend or next week
leafybasil has quit [Remote host closed the connection]
<jhass>
not sure yet, I think I'll try first whether I can do what I want with the regular one
<asterite>
Ok. I’ll try to do it then, I think it’s very useful and needed
<asterite>
I’m really amazed that people like you and ysbaddaden try to build apps with Crystal, despite the language being so young, and in the meantime feeling all the gaps, even if those gaps mean interfacing with very low-level C :-)
<asterite>
filling
asterite_ has joined #crystal-lang
asterite has quit [Ping timeout: 276 seconds]
asterite_ is now known as asterite
<jhass>
heh, it's part of the fun ;)
<jhass>
doing low level stuff in a language that has the syntax like a highly abstracted one, in fact being able to transition between the two styles of programming so seamlessly is something new to me and very exciting ;)
<asterite>
:)
<asterite>
I sometimes like to see Crystal as C with a unified, clean syntax (so a pointer doesn’t have a special semantic and it looks like a regular object), plus with many accumulated knowledge already there (sockets, json, array, hash), and a GC for not having to think (too much) about memory
<jhass>
mmh
<asterite>
Or at least as a very thin layer on top of C
<jhass>
I'd like to add most of the errno constants
<asterite>
It basically returns a union of all possible json types
<asterite>
The type is actually a union, not a JSON::Type, but that alias makes it possible to write `[] of JSON::Type` to insert that union and being able to talk about it :)
<zamith>
oooh
<zamith>
then I still have to type cast the values, for type specific methods, right?
<asterite>
Yes. But you’d normally use JSON::Any when you are not interested in that value, but still want to keep it so when you serialize back the value it’s unchanged
<asterite>
At least that’s what jhass needed (and me, a couple of times)
<asterite>
Another possiblity would be to keep the raw json value as a string, maybe with a possible JSON::Raw mapping, which would be much more performant, but for now I guess it’s ok
<zamith>
I haven't used json_mapping a lot
<zamith>
I'll try to work more on crystalshards
<asterite>
I used it today to see if prax.cr was there :)
<zamith>
it will probably surface a few issues with frank
<zamith>
oh really?
<zamith>
nice
<zamith>
it's really ugly
<zamith>
though
<zamith>
:s
<asterite>
I think it’s a very nice project. I’d sort the project by “when was the last commit” or maybe the amount of stars or some kind of activity
tymat has quit [Ping timeout: 252 seconds]
<zamith>
yeah, true
<asterite>
So you can see “abandoned” or “let’s try this language… ok, enough” projects at the bottom
<zamith>
I also want to add search
<zamith>
and pagination
<zamith>
right now it only shows 100 projects
<zamith>
:S
<asterite>
I think the 100 limits is fine for now, I don’t believe there are more than 30 or so right now
<zamith>
pagination of the github requests i mean
<zamith>
there are about 40
<zamith>
I added the total to the site
<zamith>
:p
<asterite>
I used to use the “trending Crystal repos” in github, but your website is much more useful and accurate
<zamith>
another thing is to have a community based voting system or flaggin system
<zamith>
there are some projects there that are not crystal
<zamith>
but github thinks they are
<asterite>
Yes, those critter-related projects
<zamith>
ans some that are not crystal deps compliant
<zamith>
under the number of commits, contributors and such
<zamith>
if you click the colored line, you can see the language stas
<zamith>
*stats
<asterite>
Ah, yes
<asterite>
jhass: check that travis failed, it seems there’s a duplicated constant. You can try to compile with —cross-compile in your machine to easily see if there are other dups
<jhass>
oh, right
<jhass>
I know I should've compared line counts :P
zamith has quit [Ping timeout: 245 seconds]
<asterite>
Don’t worry, that’s why there’s a build server :)
<jhass>
another wild idea for the json stuff: allow passing JSON::Type/JSON::Any to the pull parser, which then would do the casts on the read_xx calls
<jhass>
then for example you could feed an attribute of a mapping conditionally to another mapping
<jhass>
do you think that could work?
<asterite>
How’s that? I don’t really understand what you say. Maybe an example? :)
<jhass>
let me try
<jhass>
let's say we have class A; json_mapping{a: String, b: JSON::Any}); end; and class B; json_mapping({c: String}); end; then I think it would be nice if you could do a = A.from_json(read_file); if a.some_weird_condition; b = B.from_json(a.b); end
<jhass>
I know, that'll probably require some larger reworkings of the pull parser, or writing a child class of it or something, as said just a wild idea
<asterite>
Or, you mean like storing a “pointer” to the pull parser so another type could parse from there?
<jhass>
maybe, though I think I'd like the flexibility to use either variant, the current one and that
<asterite>
Why wouldn’t you map it directly into A if you know the type?
<asterite>
Or the type will be based on a certain condition?
<jhass>
yes, that's why I had that idea
<jhass>
in fact I'd like to manually read the object from the parser and then have a condition on which I choose the types of the values for
<asterite>
Yes… in that case right now you need to do implement self.new(PullParser) and do that logic there… it’s kind of tedious. But yeah, we might need to do it better
<jhass>
anyway, currently I just parse it twice, it's a small file, so it's okay for now ;)
<jhass>
(I know, I could pass my custom type to the mapping, but I need to pass other stuff along)
<jhass>
while we're at wild ideas, what do you think about class Foo(T); def bar; T::Bar.new; end; end; ?
<asterite>
Does that work?
<jhass>
nope :P
<jhass>
I wonder if we would like it to ;)
<jhass>
probably not because T can be a union
<asterite>
Yes, I was thinking the same. But I think it should work right now and (maybe) crash the compiler on a union, but it doesn’t even work
<asterite>
We could make it work. It can lead to nice patterns, I think
<asterite>
What would you use it for?
<asterite>
(it doesn’t work right now probably because it’s a bug)
<jhass>
spend too much time at that part, parsing twice is fine for now, it's just a small file
<jhass>
and the code is actually smaller
<jhass>
sort of
<jhass>
and there's no global state except for in two plugins themselves, but not in the framework
<jhass>
iirc at least
<jhass>
I think I even tried doing Plugin:Class at one point
<jhass>
since that was in one of the error messages
<jhass>
syntax error, obviously
<asterite>
Yes. Well, the `.class` in a type is not very known and it’s not documented, so… and previously it had some bugs, but now it seems to be working more or less
<asterite>
Still, parsing a json from the type in memory is interesting :)
<asterite>
Gotta go now… bye!
asterite has quit [Quit: asterite]
asterite has joined #crystal-lang
<asterite>
jhass: I think that with my gist and the possibility to iterate the subclasses of a type at compile-time, that global state would go away. But first I'll fix a few bugs
<jhass>
I see if I can make the union parser work anyway
<jhass>
I mean it works for json_mapping
<jhass>
but emulating the read_next api is hard
sferik has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
sferik has joined #crystal-lang
sferik has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<asterite>
I think we could include your json union parser. I'm not sure it will be needed though, if we have more powerful metaprogramming capabilities