qard has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
wuehlmaus is now known as Guest74945
dylanmei has quit [Quit: ZZZzzz…]
waj has joined #crystal-lang
NeverDie has joined #crystal-lang
Regexident has joined #crystal-lang
Regexident has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
Regexident has joined #crystal-lang
waterlin1 has joined #crystal-lang
waterlink has quit [Ping timeout: 260 seconds]
dylanmei has joined #crystal-lang
waj has quit [Remote host closed the connection]
<crystal-gh>
[crystal] asterite pushed 1 new commit to master: http://git.io/vG52H
<crystal-gh>
crystal/master 1af348c Ary Borenszweig: `require` can now only be used at the top-level: never inside types, defs or expressions like "if". Fixes #1146
<travis-ci>
manastech/crystal#1af348c (master - `require` can now only be used at the top-level: never inside types, defs or expressions like "if". Fixes #1146): The build passed. https://travis-ci.org/manastech/crystal/builds/78687237
waj has joined #crystal-lang
dylanmei has quit [Quit: ZZZzzz…]
Regexident has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
dylanmei has joined #crystal-lang
havenwood has joined #crystal-lang
waj has quit [Read error: Connection reset by peer]
waj_ has joined #crystal-lang
trapped_ has joined #crystal-lang
iamstef has quit [Ping timeout: 252 seconds]
iamstef has joined #crystal-lang
trapped has quit [Ping timeout: 252 seconds]
tatey_ has quit []
tatey_ has joined #crystal-lang
tatey_ has quit [Client Quit]
waj_ has quit [Read error: Connection reset by peer]
NeverDie has quit [Quit: I'm off to sleep. ZZZzzz…]
dylanmei has quit [Quit: ZZZzzz…]
tatey__ has joined #crystal-lang
tatey_ has quit [Ping timeout: 255 seconds]
tatey__ has quit [Ping timeout: 252 seconds]
ssvb has quit [Ping timeout: 272 seconds]
shout-user85 has joined #crystal-lang
shout-user85 is now known as jonahgeorge
Guest74945 is now known as wuehlmaus
<jonahgeorge>
Hey everyone, curious about getting help with marshalling data from JSON into a class. My "endpoint" returns two different structures and I'm unsure how to handle the cases in Crystal. http://play.crystal-lang.org/#/r/do4
<jhass>
jonahgeorge: maybe it also returns a matching http status code?
<jhass>
then I'd go for something like if response.stats == 200; handle_food Food.from_json(response.body.not_nil!); else; handle_error Error.from_json(response.body.not_nil!); end
<jhass>
*status
<jhass>
eh, Array(Food).from_json of course
<jonahgeorge>
jhass: Ok, that makes sense for these two cases. I was primarily curious if there is a better pattern for "unknown" JSON to a series of classes
<jhass>
that pretty much outlines the common patterns
BlaXpirit has joined #crystal-lang
<jhass>
defining a mapping will not make JSON.parse magically use it though
<jonahgeorge>
jhass: Awesome, I'll check that out
<jhass>
so if you want to feed it into that you'll have to serialize (or keep the original serialization around) again after determining what it is and feed that into from_json
jonahgeorge has quit [Quit: Bye!]
kyrylo has joined #crystal-lang
Dreamer3 has quit [Ping timeout: 252 seconds]
tatey_ has joined #crystal-lang
Dreamer3 has joined #crystal-lang
jokke has quit [Remote host closed the connection]
jokke has joined #crystal-lang
havenwood has quit [Ping timeout: 244 seconds]
Ven has joined #crystal-lang
leafybasil has quit [Remote host closed the connection]
leafybasil has joined #crystal-lang
Ven has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
leafybasil has quit [Ping timeout: 246 seconds]
leafybasil has joined #crystal-lang
Regexident has joined #crystal-lang
Regexident has quit [Client Quit]
dyulax has joined #crystal-lang
Ven has joined #crystal-lang
oal has quit [Remote host closed the connection]
[spoiler] is now known as _spoiler_
_spoiler_ is now known as [spoiler]
waj has joined #crystal-lang
waj has quit [Ping timeout: 244 seconds]
ssvb has joined #crystal-lang
NeverDie has joined #crystal-lang
NeverDie has quit [Client Quit]
NeverDie has joined #crystal-lang
Ven has quit [Read error: Connection reset by peer]
Ven has joined #crystal-lang
<crystal-gh>
[crystal] asterite pushed 5 new commits to master: http://git.io/vGFMp
<crystal-gh>
crystal/master 0b61753 Ary Borenszweig: Fixed #1362: Misleading error message when passing incorrect type to lib fun
<crystal-gh>
crystal/master f010b5e Ary Borenszweig: Documented Enum, and changed `Enum.from_value` to raise, and added `Enum.from_value?`
<crystal-gh>
crystal/master a4111f3 Ary Borenszweig: Added `Array.product` and `Array.each_product` that accept splats
<crystal-gh>
[crystal] asterite pushed 2 new commits to master: http://git.io/vGFDz
<crystal-gh>
crystal/master 0ac2c2a Tobias Pfeiffer: Remove the Enumerable#first(n) alias for Enumerable#take(n)...
<bougyman>
jhass: i'm not clear on why that has anything to do with baking a repl into a language. lisp is multi-paradigm, it can do procedural just fine.
<waj>
bougyman: I think it's not impossible, but just a little hard. Types representation can mutate as you evaluate code and that conflicts right now with the way the codegen works.
<bougyman>
waj: i wouldn't think it's easy. if it were more languages would do it. There's certainly plenty of reference material in the different lisp implementations on how to accomplish it, though.
<bougyman>
they've had 5 decades to overcome the 'hardness' of it.
<waj>
yup, although I'm not sure we could just copy the way lisp works into crystal
<crystal-gh>
[crystal] asterite pushed 1 new commit to master: http://git.io/vGbzT
<crystal-gh>
crystal/master d1d3616 Ary Borenszweig: Updated changelog and docs
<bougyman>
there are a lot of lispish behaviors in crystal already.
<asterite>
bougyman: can you have "undefined method" at runtime in lisp?
<bougyman>
asterite: non-existent function, but yes.
<asterite>
So for me that classifies as a not-compiled language
<asterite>
They don't use those names... maybe a better name is `receive_request` and `send_request`?
dylanmei has joined #crystal-lang
<jhass>
well, you have my brainstorming under the commit :P
<asterite>
I don't know, those names won't be used in code, they'll be expanded by the "select" AST node that we'll eventually add
<jhass>
I feel like we could also have at least the common case abstracted
<jhass>
Channel.receive_first(ch1, ch2)
<asterite>
But `select` is "select the first one that..."
<jhass>
and return the value, not the tuple because which one returned is also uninteresting in many cases IMO
<asterite>
Oh, you mean because Enumerable#select returns an Array?
<jhass>
I don't mean anything in particular
<asterite>
Oh, and this won't be 1.0, so we have plenty of time to think of better names :)
<jhass>
the whole interface feels rather crufty atm, it's fine to build language level abstractions upon but going into a release as an alternative free interface for now like that...
<jhass>
I feel like either it should read nicely already or (or and) be hidden behind common case abstractions
<asterite>
But you won't use that interface directly, you'll use `select; when val = ch.receive; puts val; end`
<jhass>
I'm talking about now though
<asterite>
Mm... later you'll have to refactor Channel.select calls to use the select expression, so you'll have to change it anyway, I think
<jhass>
so what about value = Channel.receive_first(ch1, ch2, ..); and Chanel.send_first(value, ch1, ch2, ...) for now until language level select is a thing? I think sending and receiving at the same time will be the rare case
<asterite>
I mean, in user code
<jhass>
it's easy to do and reads so much nicer IMO
<asterite>
We could do that. In fact I think I suggested the "receive" part to waj. If waj agrees, we can do it
<waj>
we can add `receive_first` and `send_first` but it's not one or the other
<waj>
and those methods would be using `Channel.select`
<jhass>
sure, that's what I mean
<jhass>
hide the interface for now in easy common case abstractions
<jhass>
sort of like we do with Process.run actually
<waj>
regarding, `send_op` and `receive_op`, I also would like to find better names
<waj>
I suggested `_async`, but I now understand that they are not even async operations, because if they are not selected the operation is not performed at all
<waj>
maybe something more explicit with the operation: `_case` or `_select_case`
<waj>
that would make it more similar to Go :P
kostya has joined #crystal-lang
<asterite>
jhass: want to add Channel.receive_first and Channel.send_first ?
<crystal-gh>
[crystal] dfockler opened pull request #1364: Fix #1281 Changed error output for writing to read-opened file (master...fix-1281) http://git.io/vGb6N
<jhass>
Oh, weird, my initial one was wrong I guess
<jhass>
dfockler: alright, rollback, git rebase --abort
<jhass>
we'll need to get a different rev to get the merge out, didn't realize it's an actual merge commit :P
<dzv>
@asterite: Is there a structured way to handle fiber local data? I'm trying to handle db transactions transparently. db.query_like_methods needs to get a transaction object (if there is one) from Fiber.current
<jhass>
dfockler: git remote -v lists usptream pointing to manastech/crystal or how did you set it up?
<ytti>
yesterday i tried to figure how to see THIS_FILE commits
<ytti>
and compare latest to latest-1
<ytti>
but there probably isn't any way to abstractly refer to commits affecting specific file
<dfockler>
I just need some of those blocks on my desk
<slash_nick>
ytti: probably something to loop through refs calling git show --stat and checking for matches
<ytti>
git log --follow -p file
<ytti>
will show commits for that file
<ytti>
but not specifically just X and X-1
<ytti>
git log
<ytti>
will tell commits affecting specific file
<ytti>
but no way to abstractly refer to them without hash
<jhass>
I guess some --online -n1 | cut | xargs magic then ;P
<jhass>
or more --format %whatever to skip the cut
<ytti>
yeah
rhaps0dy has quit [Remote host closed the connection]
<slash_nick>
not `git log HEAD^..HEAD --follow -p`?
<asterite>
dzv: I don't know about fiber-local data, you could reopen Fiber and use instance variables
<crystal-gh>
[crystal] jhass closed pull request #1364: Fix #1281 Changed error output for writing to read-opened file (master...fix-1281) http://git.io/vGb6N
<jhass>
asterite: haha, that's what I said too
<jhass>
but it's not nice, especially if many libraries start to do it
* asterite
whispers waj told me
<waj>
:D
<asterite>
but maybe there should be some other day... we should think hard... or just see what go does :-D
<dzv>
is there a more structured way to do that? there's also the problem of leaking transactions. do i also hook in to finalize to abort/release unfinished transactions? i
<waj>
using instance variables is probably the most efficient one
<jhass>
I could imagine something like Java's ThreadLocal class
<jhass>
interface wise
<crystal-gh>
[crystal] luislavena opened pull request #1366: Correct formatting issues in changelog (master...tweak-changelog) http://git.io/vGNUc
<dzv>
finalize may also come too late (or never if the gc doesn't run). if a transaction is held in lmdb it can block any other operation possibly deadlocking the app if it isn't released
<waj>
dzv: there is currently no other way. Transactions and DB connections should override `finalize` to handle those situations
Ven_ has quit [Ping timeout: 240 seconds]
<jhass>
luislavena: o/
<luislavena>
seems you guys are hard at work wrapping for another release?
<luislavena>
or is just because is friday? :D
elia has quit [Client Quit]
<waj>
yup! new release is coming
<waj>
dzv: how is that solved in other languages/frameworks?
<dzv>
threadlocal + deadlocking for gc'd languages i assume.
<dzv>
i think activerecord leaks or slowly regains connections if you don't explicitly free but i don't remember exactly
<dzv>
perhaps running the finalizer immediately when the fiber block exits would solve the issue?
<waj>
mm... what if there are still other references to the object
<dzv>
hmm. maybe a finished method or set of callbacks?
<waj>
I wouldn't include that in the stdlib by default. If you need callbacks you can always spawn the fiber with a begin/ensure to release resources before it finishes.
<dzv>
not if i want transparent db access. the fiber is spawned by the users code or possibly libraries code
luislavena has quit [Remote host closed the connection]
<jhass>
dzv: why not use a classic connection pool?
<willl>
there are for sure situations where AR (and maybe others) just keep connecting over and over again, then people hit the 500 connection limit we set. see those tickets frequently
dfockler has quit [Remote host closed the connection]
<dzv>
the finalizer/finished method is for returning resources to the pool and closing transactions
<waj>
jhass: oh no! the build got stuck again!? :(
<dzv>
should that get wrapped in a transaction block?
<jhass>
waj: that was before your fix ;)
<jhass>
I just didn't rebase since
<waj>
dzv: maybe not right there around that line, but if you're designing a web framework, for example, you can release the resources right before finishing with the request
waterlink has joined #crystal-lang
elia has quit [Quit: Computer has gone to sleep.]
<waj>
jhass: oh, ok... my heart has stopped for a moment... :)
<jhass>
heh, sorry I guess :P
<dzv>
i'm not designing a web framework. i'm designing a db shard and i would prefer to not leak things if i can avoid it. i don't expect other programmers to handle every situation perfectly. they will leak if explicit freeing is required and wonder why their app stops responding
<dzv>
willl mentioned this happens frequently with AR and it's a well known framework with well known pool semantics. if AR can't be used "correctly" then i think the design can be improved with a quick finish/finalize in the fiber
<willl>
it's often, I think, due to an exception or timeout, and those cases not returning the connection to the pool. It's hard to track down when it's someone else's app
<waj>
I think I like Go's approach now
<waj>
btw... few days ago, I started with asterite to design a common DB interface
<dzv>
go's is?
<waj>
in Go, you create a DB object and perform queries to it. It maintains an internal pools of connections and you only get interested on a specific connection if you need to start a transaction
<willl>
please don't make a terrible one like go's database/sql
<waj>
anything we do will be open to discussion with all of you guys :)
<willl>
go's you can't set session state at all, because they don't have a place to set that on each connection in the pool
<willl>
also they "reconnect" but only five times, and they do it right away, so any transient network problem you just burn through all 5
<dzv>
that's for raw sql connections. what about AR style object mapping with User.find?
<willl>
also if you don't connect because of an error, they don't return an error until the first query you do
<waj>
willl: I'm not sure I follow the issue of the session state
<willl>
also if you don't know at the time you write your query how many columns you have, because all you can do is rows.Scan you're mostly screwed
<waj>
dzv: can't AR work on top of that?
<willl>
postgres you can `set time zone to 'UTC'` and such, and that is state that lives on that session
<willl>
because you get a random thing from the pool each time, you can't know you have one with state set
<waj>
but you can use `Begin` to get a Tx attached to a single connection
<willl>
yeah but then you have to set the state each time you want, not just at first connection
<waj>
oh... I see. So you'd like to have a callback for example, to execute on every open connection
<dzv>
waj: User.find would still need the connection from Fiber.current but that can be monkey patched. the queries would need to be wrapped in Db.open blocks still. i dislike this requirement from an ease of use perspective
<willl>
waj: yeah that'd work
<dzv>
but maybe that is better since connections would probably be released sooner
<willl>
but generally due to how terrible database/sql is, you should never use go if you want to use postgres. And the people on my team wrote go's postgres driver...... :(
<waj>
dzv: if you don't need an explicit transaction then maybe you don't need to use a connection by fiber, am I right?
<waj>
willl: hehe, I used the postgres driver myself and it wasn't that bad :)
<dzv>
incorrect. transaction { u = User.find; u.something = 1; u.save } # the transaction isn't referenced in any method. they use Fiber.current behind the scenes to look it up
NeverDie has quit [Quit: I'm off to sleep. ZZZzzz…]
<waj>
I didn't think of that, but starting with an adhoc db connection pooling, so every connector don't have to have their own
<asterite>
maybe we should create an issue in the repo and continue the discussion there, so it doesn't get lost :)
<asterite>
(later)
<waj>
I wish we could be all on the same room with a whiteboard for this ;)
<dzv>
and not db specific. general object pooling yes?
ledestin has quit [Ping timeout: 264 seconds]
<crystal-gh>
[crystal] asterite closed pull request #1314: Raise Errno when failing to allocate a new fiber stack (master...fiber_allocate_error) http://git.io/vGYu0
<waj>
something like what willl suggested? yup, maybe
waterlink has quit [Ping timeout: 244 seconds]
<dyulax>
something like PHP's PDO?
<crystal-gh>
[crystal] kumpelblase2 opened pull request #1369: Added convenience method to open a websocket to a server. (master...patch-1) http://git.io/vGNBq
<crystal-gh>
[crystal] jwaldrip opened pull request #1370: don't require a Projectfile when generating docs (master...master) http://git.io/vGN0r
<dzv>
separate from pooling a standard base library for SQL connection/columns/rows that pg, mysql and other drives to inherit from would be useful
<trapped_>
i was using it in go, not sure if there's some strange syntax
<BlaXpirit>
looks definitely wrong
<trapped_>
i would've said that too but it works
<trapped_>
or at least, it's been working for a year now without issue
<BlaXpirit>
trapped_, found this cool email address. does it validate? 伊昭傑@郵件.商務
<trapped_>
very well
<trapped_>
it is unfortunate that i must admit it has happened to me before that i had to receive an email from a chinese address
<trapped_>
however, all i could read was ������;
<asterite>
Ugh, I'm now getting `/bin/sh: line 1: /usr/bin/cc: Argument list too long` when doing `make crystal spec`. Tried https://github.com/manastech/crystal/pull/1293 too but I get the same error :-(
<dzv>
i was wondering how long it would take for that to happen
kostya has quit [Remote host closed the connection]
<BlaXpirit>
oh no :s
elia has joined #crystal-lang
<asterite>
Well, using relative filenames solves the problem for now :-)
<dzv>
there are just too many files being linked together at once
<asterite>
we were passing absolute filenames
<dzv>
delays the problem for now
<asterite>
and later we'll probably want to put generate code of nested types inside the container, to reduce the number of files
<dzv>
any large crystal project will have the same problem
<asterite>
dzv: how do you deal with it in large C code bases?
<dzv>
idk. normally c has larger blocks of code in a file. crystal has lots of small files
<dzv>
you could combine code in to multiple static libraries and link them at the end
<Renich>
I am trying to create the ebuild so I can collaborate with the overlay so Funtoons and Gentoons can install crystal
<jhass>
well, figuring out how to bootstrap from official stuff would certainly be preferable then though
<Renich>
jhass: that is true
<jhass>
that's what we do for arch, download the tarball there and recompile against arch's packages (and tell people that have hardening-wrapper installed to disable it for the package build)
<Renich>
jhass: well, that's gonna be, pretty much, the path to follow