ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.23.0 | Fund Crystal's development: http://is.gd/X7PRtI | Paste > 3 lines of text to https://gist.github.com | GH: https://github.com/crystal-lang/crystal | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/ | Logs: http://irclog.whitequark.org/crystal-lang
Guest56511 has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<FromGitter> <johnjansen> it only happens when a virtual class is used within another class too
<FromGitter> <renich> good day, Crystalians!
<FromGitter> <renich> Well, evening here
<FromGitter> <renich> Hey, wait. If we use crystal... does that make us drug addicts?
Dreamer3 has joined #crystal-lang
<FromGitter> <renich> Hey guys, I have this: https://play.crystal-lang.org/#/r/2bcv. I'd love to be able to pass it either every parameter of a NamedTuple which contains all the parameters. How?
<FromGitter> <johnjansen> check out named arguments in case that meets your needs ⏎ https://crystal-lang.org/docs/syntax_and_semantics/default_and_named_arguments.html
<FromGitter> <johnjansen> then check out splats
<FromGitter> <renich> @johnjansen thanks, doing so... I think splats fit best, actually
<FromGitter> <renich> The splat worked fine.
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 240 seconds]
_whitelogger has joined #crystal-lang
rohitpaulk has joined #crystal-lang
vifino has quit [Ping timeout: 240 seconds]
vifino has joined #crystal-lang
rohitpaulk has quit [Read error: Connection reset by peer]
rohitpaulk has joined #crystal-lang
RX14 has quit [Ping timeout: 260 seconds]
minus has quit [Ping timeout: 240 seconds]
RX14 has joined #crystal-lang
<FromGitter> <sdogruyol> hey @crisward i've just seen https://github.com/crisward/kemal-session-mysql
<FromGitter> <sdogruyol> hope to see it working soon
hightower2 has joined #crystal-lang
minus has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 260 seconds]
<FromGitter> <sdogruyol> ugh https://play.crystal-lang.org/ seems to be down //cc @jhass
<FromGitter> <martincsimpson> Quick question
<FromGitter> <martincsimpson> do you guys have any resident sysadmins
<FromGitter> <sdogruyol> nope
<FromGitter> <sdogruyol> why?
<FromGitter> <martincsimpson> (play is working for me btw)
<FromGitter> <sdogruyol> guess it's some DNS problem
<FromGitter> <martincsimpson> I am a sysadmin, just wondering if any help was needed
<hightower2> sdogruyol: I just used it
<FromGitter> <martincsimpson> I became a ruby dev after my sysadmin / Cisco Certs
<FromGitter> <sdogruyol> @martincsimpson that's cool
<FromGitter> <martincsimpson> Anyway, just offering a hand if needed. :)
<FromGitter> <sdogruyol> wow, thanks @martincsimpson I'll keep that in my mind :P
hightower2 has quit [Ping timeout: 240 seconds]
<FromGitter> <crisward> @sdogruyol yes, we need a session store and we already use mysql with our sites, so this should hopefully a drop in replacement for the kemal-session/fileEngine we currently used. Think it'll probably be my weekend project. I'll update the readme when its done and tested.
<FromGitter> <crisward> For lowish traffic sites mysql is fine. For bigger sites we tend to lean towards redis, but that's already taken care of.
Groogy_ is now known as Groogy
<Groogy> Morning!
<FromGitter> <sdogruyol> @crisward that's great to hear. Please feel free to reach me for any help
<FromGitter> <sdogruyol> @Groogy morning!
<FromGitter> <codenoid> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=595f37b5c101bc4e3a5e72ff]
<FromGitter> <codenoid> :satisfied: still playing with the db
mark_66 has joined #crystal-lang
<FromGitter> <crisward> @sdogruyol Think I should be ok, but I'll let you know if I get stuck.
<Groogy> one my new parts are DOA so all my crystal projects been delayed as I've been debugging that :( I was hoping to play around with the language the entire week
<Groogy> computer parts*
<Groogy> working through the ubunutu shell on windows 10 is not directly the best
<jokke> hi
<jokke> i'm having trouble with IO.copy
<jokke> the source and destination contents differ
<jokke> i'll put together a minimal example
rohitpaulk has joined #crystal-lang
<jokke> hm it seems to be another problem, since i can't reproduce it in a minimal example
<jokke> that's where i copy a file to the response
<Groogy> how do the content differ?
<jokke> there's the number 4 in the next line
<jokke> and then no line ending
<jokke> so "foo\n" becomes "foo\n4"
<Groogy> and "foo\n" was in the buffer before or it comes from context.response as well?
<jokke> "foo\n" is the contents of a file
<jokke> which is opened and then copied to the response
<jokke> hm content_length is wrong
<Groogy> ooooh so it goes that way my bad
<oprypin> jokke, do u know that u have language: crystal in your own pastebin?
<jokke> what the hell...
<Groogy> have you tried to log directly after the IO.copy to see that the correct value is there
<jokke> oprypin: no
<Groogy> also is this a Kemal structure?
<jokke> so the problem is this: for some reason Content-Length is set to 5
<jokke> but File.size(blob) is 4
<Groogy> well you have the null character?
<Groogy> or do Crystal not null terminate?
<jokke> :)
<Groogy> also
<jokke> Groogy: it shouldn't do that because i'm writing raw bytes to the result
<Groogy> you are copying the text directly onto response?
<Groogy> but you also modify the response members?
<jokke> response members?
<FromGitter> <sdogruyol> @Groogy what's kemal structure?
<Groogy> "context.response.content_length = File.size(blob)"
<jokke> yes
<Groogy> no I was asking Jokke if it was
<jokke> that's exactly what HTTP::Server::Handlers::StaticFileHandler does
<Groogy> and then you provide response directly to IO.copy, so is response a string or an object? Does IO know how to properly write to response?
<FromGitter> <sdogruyol> @groogy that's from Crystal std
<Groogy> Crystal IO object just do << on any object given to it?
<jokke> huh?
<jokke> Groogy: response is an IO object
<jokke> so is file
<Groogy> No I am just curious how the IO object manages t owrite to context.response which obviously must be an object?
<jokke> wat
<jokke> it's an IO object
<jokke> sdogruyol: you haven't stumbled across this before?
<jokke> does kemal do something "smart" with content-length?
<FromGitter> <bew> Groogy: you can check the sources for `IO.copy`: https://github.com/crystal-lang/crystal/blob/master/src/io.cr#L1061
<jokke> hm it seems setting content_length is just ignored
<Groogy> I don't see any write function in the StaticFileHandler or in the included modules 눈_눈
<jokke> i tried setting it to 1000 and it's still 5 in the response headers
<Groogy> probably sets it by itself when you write to it?
<jokke> yeah apparently
<Groogy> what happens if you set it afterwards?
<jokke> well.. that's not how http works
<Groogy> could also be encoding in the file? It reads some encoded character that is hidden otherwise?
<Groogy> well the response havent' been sent yet after you stop writing to the response right?
<jokke> it should
<jokke> streaming
<FromGitter> <sdogruyol> @jokke not sure what you're talking about but i've stumbled accross something like that before
<Groogy> No normal webpage requests is not streaming?
<jokke> Groogy: otherwise you'd have to load up the whole file into ram before sending
<jokke> sure is
<jokke> how do you think yoy download multi gigabyte files?
<Groogy> yeah but that's a specific sort of connection
<jokke> the server sets the content length and maybe transfer encoding and then starts streaming the data to the socket
<jokke> no it's not
<jokke> it's basic http
<jokke> there's no reason for you to start receiving the data before the server has finished writing
<jokke> *not to
<jokke> everything the client needs to know is given in the header
<Groogy> you are talking about persistent connection right?
<Groogy> either way it doesn't matter
<Groogy> this isn't directly the protocol but an object
<jokke> which is just a proxy to the protocol
<Groogy> yes but obviously the object is setting the content length based on what you are writing to it
<Groogy> so it isn't sending immedietly
<Groogy> what if oyu write twice to it? how does the object react then?
<Groogy> that would be really bad because you shouldn't in environments like this leave objects in a corrupt state
<Groogy> my guess is the objects sends it data outside of the block you provide to the route handler
rohitpaulk has quit [Ping timeout: 240 seconds]
<Groogy> function used by IO.copy though is the #write which calls @output.write and I see a #flush method used with that before the headers are written.
<Groogy> wonder where the unbuffered version is used though
<jokke> it's called by IO::Buffere
<jokke> d
<jokke> this is most definately a bug in that class
<Groogy> yeah I see
<Groogy> yeah because it's definetly weird, because the IO.copy does potentially several writes to the buffer
<Groogy> if you have a file over 4k bytes
<jokke> sure
<Groogy> it will do more htan one
<jokke> that's how it's supposed to work
<Groogy> yeah but it sets the size afterwards
<jokke> it's weird though: in #close the content length is set. but only if the headers aren't written but it ensures that headers are written before writing anything to the io
<Groogy> though this is only if the @sync variable is set though
<Groogy> in the function reset it sets reset to false again, and the default is false as well
<Groogy> but not sure if something else might set it to true
<Groogy> otherwise the unbuffered_write is delayed until certain things happen
<Groogy> i.e if we pass by the buffer size
<Groogy> which is 8192 bytes
<jokke> yeah
<Groogy> so back to the problem, my guess is encoding problem? There is a byte extra of data which gives you the number of 4?
<jokke> i also wonder why not setting content_length at all doesn't result in Transfer-Encoding: chunked as the code suggests
<Groogy> maybe UTF-8 bom character or something?
rohitpaulk has joined #crystal-lang
hightower2 has joined #crystal-lang
<jokke> okay it seems to be a problem with small files
<jokke> i just tried with 1M of random data
<jokke> has the same md5sum as the original
<Groogy> the small one was with text right? Is the 1M of random data done binary or also text?
<Groogy> because from what I see, what you will be writing is binary so if you have a weird encoding in the text it is gonna just write that "straight"
<jokke> mh could be
<jokke> but still
<jokke> crystal shouldn't make assumptions
<jokke> a text file is a "binary" as well
<jokke> as in: it consists out of bytes
<jokke> this seems to be a kemal issue
<jokke> can't reproduce with pure HTTP::Server
<jokke> yup
<jokke> definately kemal
<FromGitter> <sdogruyol> @jokke can you report an issue please?
<FromGitter> <sdogruyol> i didn't follow the whole thread
<jokke> yes
<FromGitter> <sdogruyol> thank you
<Groogy> Yeah they are binary, but if whatever editor think it is some weird encoding then when reading it back binary and then with ASCII nothing is going to make sense
<jokke> sure
<jokke> but IO.copy copies bytes
<jokke> it doesn't care about encodings
<Groogy> yeqah but you are setting an encoding in the header right? :P
<jokke> no
<jokke> content type is application/octet-stream
<Groogy> eh not encoding
<Groogy> content type
<Groogy> yeah so when you end up receiving it in the webbrowser, it has no idea what encoding the text is
<Groogy> and probably just defaults to UTF-8 or ASCII
<jokke> i'm not using a browser
<jokke> no
<jokke> octet stream is binary
<jokke> no encodings whatsoever
<Groogy> yes, but the source file has an encoding
<jokke> that doesn't matter :D
<Groogy> it does, because you are sending it binary
<Groogy> i.e byte for byte
<jokke> sigh
<jokke> you're not really making sense
<Groogy> If you are sending let's say Latin1 text binary, but the receiving end does not know it is latin1 text it will get some unknown weird characters
<jokke> wouldn't you agree that if i copy a file byte by byte the result should be _exactly_ the same
<Groogy> yes it is exactly the same
<jokke> see
<jokke> and it isn't
<jokke> hence it's a bug
<Groogy> But it is
<jokke> no!
<Groogy> Character count is not the same as byte size
<jokke> dud
<jokke> e
<jokke> you think i'm counting chars?
<jokke> im looking at the _bytes_ of the original and resulting files
Raimondii has joined #crystal-lang
<Groogy> no I didn't say that, but I am just pointing out that you took two different kinds of data and saw behavioural change and then putting that as the cause of problem is between small sets of data and big sets of data
<jokke> and they differ
<jokke> NO!
<Groogy> No you said one is text and one is binary
<Groogy> source file that is
<jokke> dude
<jokke> you don't understand the problem
<jokke> let's put it this way
<jokke> what makes a text file text and what makes a binary?
<jokke> what's the difference?
<Groogy> there's no difference, it is all a matter how you view the data contained within the file.
<jokke> exactly!
Raimondi has quit [Ping timeout: 268 seconds]
<jokke> and crystal is not an editor
Raimondii is now known as Raimondi
<Groogy> What I said does not contradict that
<Groogy> You wrote a file manually
<Groogy> and the 1m data is generated I am guesisng by some tool?
bjz has joined #crystal-lang
bjz has quit [Client Quit]
<Groogy> guessing*
<jokke> it's just from /dev/urandom
<jokke> now:
<Groogy> yes but the file you wrote manually might as well have extra characters in it
<jokke> what if /dev/urandom would've outputted a "text file"
<jokke> totally possible
<jokke> not probable but possible
<Groogy> that's what I said
<Groogy> That is literally what I said, seeing random numbers or unknown characters in a scenario in this is very probably to be encoding
<Groogy> I know because I've been through this before
<Groogy> Assuming two different sets of data being generated completley differently are equivalent is very false assumption to make
<jokke> ...
<jokke> input is "foo"
<jokke> sorry "foo\n"
<jokke> output is "foo\n4"
bjz has joined #crystal-lang
<jokke> content-length is 5
<jokke> hence: content-length is _wrong_
<jokke> nothing to do with encoding
<Groogy> no it obviously gets a fifth character from somewhere
<jokke> of course
<jokke> from ram
<jokke> it's just a random byte which happens to be in ram
<jokke> if you've worked with C before, you know what i mean
<Groogy> Yes I have, but nothing in the code implies that it reads past the given string
<Groogy> since it gets the size of the string from the source itself
<jokke> .......
<jokke> look. at. the. strings.
<Groogy> though it probably isn't a BOM character since it is 3 bytes big
<Groogy> I am looking at the code Jokke
<jokke> count the characters
<jokke> count the bytes
<Groogy> a character in Crystal is 4 bytes big
<jokke> what!?
<jokke> count the bytes of my input and output strings above, please
<Groogy> "A Char represents a Unicode code point. It occupies 32 bits."
<jokke> a string is not an array of chars
<Groogy> either way the code as far as I can see gets the size from the string provided and writes specifically that amount
<jokke> in crystal
<jokke> i will spell it out for you. f o o \n: 4 bytes. f o o \n 4: 5 bytes
<jokke> content-length is 5 bytes
<jokke> so the byte that represents the character 4 is just the next byte on the heap after the byte that represents the character \n
<Groogy> that's not how it works....
<jokke> lol
<Groogy> How about you ask the string for it's bytesize?
<jokke> how about _yoy_ do that
<jokke> *you
<Groogy> well I don't have your source
<Groogy> I don't get why you are so angry
<jokke> because you fail to understand. and i've tried a while now
<jokke> i gave you the strings
<jokke> use the method on them
<FromGitter> <bew> wheird? https://carc.in/#/r/2bg2
<Groogy> No I don't, I am trying to explain to you visible characters does not mean that you don't have more characters there and when you then transfer that data binary and hence losing the context of those bytes at the destination it will show up wrong
<FromGitter> <bew> weird*
<FromGitter> <bew> bytesize and size is the same here
<Groogy> I do not have specifically the file being used where the fault lies in
<jokke> i will upload it for you :D
<Groogy> @bew the string is pretty smart, it depends on the encoding
<Groogy> like if you need multibyte chars it will do that
<jokke> i'm telling you. my file contains _exactly_ the characters i've shown you
<jokke> i'm not stupid
<Groogy> For instance there is a lot of characters that are pretty rare for you to use, we for instance as a DLC ownership protection method used non-breaking spaces to see that files hadn't been tampered with
<jokke> i know about encoding. i've got a degree in computer science. i should know...
<jokke> and i'm telling you now. it has _nothing_ to do with this problem
<Groogy> And? I've taught at Universities?
<jokke> what have you taught?
<Groogy> and I am not saying it has to do wwith that problem, I am saying doing the correleation that you did was faulty
<Groogy> Game development
<Groogy> or rather it was one class I was invited to because of my book
<jokke> mh
<jokke> and you have studied computer science?
<Groogy> no
<jokke> well it's beyond the point anyway
<Groogy> I started working when I was 15 instead
<jokke> i don't want to get personal
<FromGitter> <bew> please don't fight!
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<Groogy> sorry wasn't my intention bew
<jokke> it kind of insults my intelligence to be told that my problem is something very trivial which every 1st semester would figure out easily. I've now tried to explain for like half an hour or longer how it clearly isn't the case here but i'm at my limit of patience now so i'll just stop and you are free to believe what you will.
<Groogy> At no point where I infering on your intelligence, trivial problems happen all the time
<jokke> and i'll feed my cats :D
<Groogy> And because they are trivial you usally overlook it
<Groogy> 99% of a progammers life is going to be "Oh damned I'm an idiot, that's so simple"
<jokke> you're right of course.
<Groogy> and I don't believe anything about you since I do not know you, I was just trying to give you a pointer on that it might not be related to actual size data since the data sets came from two different sources
<jokke> encoding is a good bet as any in this case but what bugged me was that despite me arguing against it being the problem here you kept going
<FromGitter> <codenoid> hi jokke & groogy, can you help me with this :worried: https://github.com/crystal-lang/crystal-db/issues/58
<jokke> anyway. no hard feelings, right?
<jokke> actually i need to apologize. i've been a dick and i really appreciate people helping out on irc. I'm the reason why someone might not want to by reacting like this.
<Groogy> Nah it's fine, I should have let it go when it became clear I wasn't helping anymore
<Groogy> Eitherway codenoid, I am going on lunch right now but what socket is it that closes? (that you marked out with comment), the http params or the mysql?
* jokke shakes hands with Groogy
<FromGitter> <codenoid> oh sorry, it's different problem, i'll remove that
<FromGitter> <codenoid> yayyy :sparkles:
<FromGitter> <codenoid> updated with `my simple query :`
bjz has joined #crystal-lang
<FromGitter> <bew> jokke, using `send_file context, DATA.to_slice` instead of using `IO.copy` works well
<FromGitter> <sdogruyol> @bew could you please put that into the issue https://github.com/kemalcr/kemal/issues/374
<FromGitter> <bew> yep
<FromGitter> <sdogruyol> thanks :+1:
<FromGitter> <bew> wher can I find links to the docs of kemal/helpers/helpers.cr ?
<FromGitter> <bew> @sdogruyol
<FromGitter> <bew> nvm, found it
<FromGitter> <bew> @sdogruyol maybe it would be good to have a *tested* `send_io` to send any io ?
<FromGitter> <bew> but for that I don't know how to get the content_length of the io in advance..
<FromGitter> <codenoid> got `better` performance ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=595f620a0de4d2545e027302]
<crystal-gh> [crystal] akzhan opened pull request #4686: skip_file macro replaced with skip macro. (master...skip_file-macro-replaced-with-skip-one) https://git.io/vQo0T
<jokke> does anyone know how i can proxy everything from one socket to another?
<FromGitter> <sdogruyol> pipe ?
<jokke> you mean IO.pipe?
<FromGitter> <sdogruyol> yeah
<FromGitter> <sdogruyol> a socket is actually an IO
<jokke> yeah sure
<jokke> but pipe is a class method
<FromGitter> <bew> you need to create a pipe using `IO.pipe`, and connect the input/output of the pipe to the sockets
<jokke> yes. that "connect" part is what i'm not getting
<RX14> no pipes
<RX14> just spawn 2 fibers
<RX14> one reads and then writes in 1 direction
<RX14> the other does the same in the opposite direction
<jokke> yeah i thought that
<jokke> but
<jokke> is there a blocking IO.copy?
<RX14> ideally we'd have asynchonous bindings for splice()
<RX14> jokke, IO.copy *is* blocking
<RX14> it copies to EOF
<jokke> oh!
<jokke> well then cool
<jokke> so my code was right before i even asked :D
<RX14> did you test it...
<jokke> ofc not :D
<RX14> why :(
<jokke> because this is a little script i wanted to try out
<FromGitter> <bew> that's cool, I always forget about fibers...
<Groogy> and back, long lunch for getting my fried MoBo replaced. @bew did you get help with your thing?
<Groogy> or wait no that was @codenoid
<Groogy> sorry
<FromGitter> <bew> np
<FromGitter> <suvendusamanta> Can I create a subclass in an inner (sub-)directory which inherit from a class defined outside the (sub-)directory. If yes, How?
<Papierkorb> Directories and their structure don't matter to the language. Module paths are global, and can be accessed from anywhere
<FromGitter> <suvendusamanta> ./src/crust/num/la ⏎ ├── matrix ⏎ │   ├── matrix_dense.cr ⏎ │   ├── matrix_partition.cr ⏎ │   └── matrix_sparse.cr ... [https://gitter.im/crystal-lang/crystal?at=595f6fa21c8697534afd6a2c]
<FromGitter> <suvendusamanta> thanks, in above example, can I define MatrixDense in matrix_dense.cr which will be derived from Matrix class defined in Matrix?
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<Papierkorb> If both files are require'd, of course.
bjz has joined #crystal-lang
bjz has quit [Client Quit]
<Groogy> It works like in Ruby right? If it's been defined and loaded you can use it however right?
<Groogy> there's no rules on the language based on file/compile units etc.? Like D for instance
<FromGitter> <suvendusamanta> I am not experience in ruby ... I matrix.cr look like require "./matrix/*" ⏎ module LA ⏎ class Matrix ⏎ end ⏎ end [https://gitter.im/crystal-lang/crystal?at=595f70d9c101bc4e3a5f727f]
<FromGitter> <suvendusamanta> and matrix_dense.cr is look like require "../matrix" ⏎ ⏎ module LA ⏎ class MatrixDense < Matrix ⏎ end ... [https://gitter.im/crystal-lang/crystal?at=595f71164bcd78af5686e8e8]
<FromGitter> <suvendusamanta> compiler giving error saying "undefined constant Matrix".
<Papierkorb> Please gist any error you're getting, in full.
<FromGitter> <suvendusamanta> ok thanks
<Papierkorb> Just make sure that all files are required. Do that once, in a central file. no need to do so in every file.
<Papierkorb> No require/import spam at start of the file as in other languages
<FromGitter> <suvendusamanta> ok, thanks a lot
<FromGitter> <codenoid> still waiting some help groogy while i thinking to use GO for database connection (with more js)
<FromGitter> <sdogruyol> lol
fiete has quit [Quit: WeeChat 1.7.1]
fiete has joined #crystal-lang
<jokke> i'm a bit confused about TCPServer#accept
<jokke> it seems to be called only once. no matter how many times i connect
<jokke> (tried with curl)
<jokke> hah never mind :D
<FromGitter> <chyzwar> content_length should be in bytes, File.size(filename) show size of filename
<FromGitter> <bew> it returns the size of the file named *filename*
<Groogy> ^
<FromGitter> <chyzwar> .size(filename) : UInt64 ⏎ Returns the size of filename bytes.
<FromGitter> <chyzwar> then docs should be diffrent. It should say Return size of file with filename
<FromGitter> <chyzwar> I think that #size should be uzed
<FromGitter> <chyzwar> ``````
<FromGitter> <schoening> Is my_array[ index ] lookup speed 0(n) ? :(
<FromGitter> <schoening> Tried writing a loop that would only do comparison between all its values once, but if arrays gotta iterate every check anyways then that seems pointless? ⏎ https://play.crystal-lang.org/#/r/2bh8
hightower2 has quit [Ping timeout: 240 seconds]
<Papierkorb> Array#[] is O(1)
<Groogy> I mean the loop itself is O(n) though?
<Groogy> actually the loop you linked is O(n^2) unless I misunderstood something?
<FromGitter> <schoening> Yeah the loop is not the problem I was worried about array itself, it didnt occur to me that the #[] I was looking for is specified deeper into the hirachy and not on array.
<Groogy> ah you were worried it was a linked list?
<FromGitter> <schoening> The loop will grow yeah. But less so than if I did just iterater twice over game_objects :) . better implementations are ofc welcome!
<Groogy> it depends on what you want to do, there is no generic "this is better" Reading it as "game objects" is this for the main loop of a game?
<Papierkorb> You'd have to tell us what you're trying to solve, not show what you're doing
<FromGitter> <schoening> Maybe? :) I'm not good on the sematics of things.. I only saw the #[] range() definition and got scared
<Groogy> Actually here's my advice, just go with it and when it becomes a problem, solve it then ;)
<Groogy> there's no point in solving a potential problem without knowing if it will be a problem for you
<FromGitter> <schoening> Sorry yeah, thats just iteration in the main loop. This works fine, I can't think of a faster way of looping while having to compare two things. So I only mentioned an optional "feel free to tell me it can go faster" haha
<FromGitter> <schoening> Yeah agree @Groogy
<Groogy> There are a bunch of things you can do to improve it actually, depending on what it needs to do
<Groogy> for instance we at Paradox have very smart lists that divide the world into different things based on various conditions. Like we have in our script language you can do every_province = {} or owned_provinces = {}
<Groogy> guess which one is fastest :P
<Groogy> but it becomes very specific on what is it that this specific thing needs to do, where "can I find a shortcut"
<FromGitter> <schoening> Ahh
<Papierkorb> That's bascially an index or cache
<Groogy> but yeah get to the performance problem and don't be afraid of refactoring stuff
<Groogy> don't solve things just to solve them
<Groogy> just for the sake of solving*
<FromGitter> <schoening> Exactly :p I'm not that worried. But im sitting on a bus and the best I could do was trying out a new loop in crystal
<Papierkorb> Choose the naive implementation, but not the stupid one ;)
<Groogy> ^
<FromGitter> <schoening> Sound good yeh
<Papierkorb> schoening, comparing one to every other element will always be O(n²). You can't get better than that. The trick is not having to do it :)
<Papierkorb> But then, comparing is quite fast, and as long your list is small, you probably won't even notice
<Groogy> and as long as the comparison is simple enough
<Groogy> but if it is planned to be like collission testing for objects in a large world with a lot of entities, I would look into Quad trees schoening, or Oct Tree's if 3D
<Groogy> actually read up on it anyway, it's still good to know
<FromGitter> <schoening> Yeah exactly. Was thinking of learning to do a quad tree next
<FromGitter> <schoening> Ofc! Learning for the sake of it is nice. Just gotta find a balance between that and actually getting something done :D
<FromGitter> <umutuluer> Hi i have a question
<FromGitter> <umutuluer> why does crystal support windows? i have any idea about this
<FromGitter> <umutuluer> @sdogruyol me too, for choosing this name, because i admire mustafa kemal
<Groogy> Atatürk? am I missing some context? xD
<FromGitter> <sdogruyol> @Groogy Mustafa Kemal Ataturk
<FromGitter> <umutuluer> so, i guess, am i wrong?
<FromGitter> <sdogruyol> @umutuluer windows support is still in the making you can follow the progress here https://github.com/crystal-lang/crystal/projects/6
<FromGitter> <umutuluer> now i am trying via bash, i will check this
<FromGitter> <sdogruyol> ubuntu on windows works @umutuluer
<FromGitter> <umutuluer> yes i know, but is not pure
<FromGitter> <umutuluer> because of that, i asked that is there any option
<FromGitter> <sdogruyol> unfortunately, there's not for now
<Groogy> Yeah I know who he is :P I'm a history geek
<Groogy> Ubuntu on Windows works pretty nicely, but yeah not pure. If oyu need to do graphical stuff you can install a Windows X Server
<Groogy> works so-so
<oprypin> i wonder. if Crystal mostly supports Windows but not stdlib and exceptions,
<oprypin> then could a framework that doesn't rely on stdlib and exceptions already work?
<FromGitter> <codenoid> `12420 requests in 10.01s, 34.75MB read` , not bad
<FromGitter> <sdogruyol> @Groogy that's amazing :)
<Groogy> from what I understood, oprypin, the problem is literally the std lib?
<FromGitter> <sdogruyol> mostly
<FromGitter> <sdogruyol> because it has lots of POSIX-isms
<FromGitter> <codenoid> really bad
<oprypin> i feel like getting rid of posixisms could even be fun for the most part
<oprypin> but the core stuff (io, fibers, exceptions) requires the best people
<FromGitter> <sdogruyol> yeah, idd
<FromGitter> <bararchy> Got a 340 lines long file in sublime and the format on save is starting to be slowwww
<FromGitter> <bararchy> @codenoid Stop spamming people and issues for help :\ not cool
<FromGitter> <sdogruyol> @bararchy really?
<FromGitter> <bararchy> Yeha :\ not sure why
hightower2 has joined #crystal-lang
<FromGitter> <codenoid> yasss, brian leave some comment
Raimondi has quit [Quit: WeeChat 1.8-dev: ¡Chau!]
<FromGitter> <codenoid> `undefined constant Session`
<FromGitter> <sdogruyol> @codenoid use kemal-session 0.8.0
<FromGitter> <codenoid> in srahd,.yml 0.7.0, ⏎ work with ⏎ ⏎ `````` [https://gitter.im/crystal-lang/crystal?at=595f93e86ae41d5d33c6a861]
Raimondi has joined #crystal-lang
<crystal-gh> [crystal] waj pushed 1 new commit to master: https://git.io/vQo5U
<crystal-gh> crystal/master 158a818 Juan Wajnerman: Updated Dockerfile.release to build 0.23.0:...
hightower2 has quit [Ping timeout: 240 seconds]
<travis-ci> crystal-lang/crystal#158a818 (master - Updated Dockerfile.release to build 0.23.0:): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/251192034
<travis-ci> crystal-lang/crystal#158a818 (master - Updated Dockerfile.release to build 0.23.0:): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/251192034
<travis-ci> crystal-lang/crystal#158a818 (master - Updated Dockerfile.release to build 0.23.0:): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/251192034
w-p has quit [Quit: Leaving]
<FromGitter> <schoening> Trying to google some comparisons on amber and amethyst framework brings up a whoooole bunch of homepathic mumbo jumbo xD
<FromGitter> <fridgerator> lol
<FromGitter> <sdogruyol> Lol
Philpax has quit [Ping timeout: 260 seconds]
wontruefree has joined #crystal-lang
wontruefree has quit [Quit: Is gone... Just plain old gone]
mark_66 has quit [Remote host closed the connection]
<FromGitter> <renich> Good day, Crystalians
<crystal-gh> [crystal] matiasgarciaisaia closed pull request #4649: Fix #4639: Macro lookup from included module broken (0.23.1...fix/4639-macro-lookup-from-included-module) https://git.io/vQROW
rohitpaulk has quit [Ping timeout: 240 seconds]
bit_lySLH2uSZHed has joined #crystal-lang
bit_lySLH2uSZHed has left #crystal-lang [#crystal-lang]
olbat has quit [Ping timeout: 246 seconds]
tzekid has joined #crystal-lang
wontruefree has joined #crystal-lang
wontruefree has quit [Quit: Is gone... Just plain old gone]
wontruefree has joined #crystal-lang
wontruefree has quit [Client Quit]
<oprypin> i've been trying to get CrSFML working on Windows
<oprypin> i'm almost there but exported globals don't work "unresolved external symbol inputstream_read_callback referenced in function __crystal_main". does anyone know what I'm missing? https://github.com/oprypin/crsfml/blob/sources/voidcsfml/include/voidcsfml/system.h#L32
<FromGitter> <sdogruyol> @renich good day!
<oprypin> is it possible that Crystal is not doing the equivalent of `__declspec(dllimport)` that's being mentioned everywhere?
<FromGitter> <renich> @sdogruyol o/
<FromGitter> <sdogruyol> @oprypin i'm not sure what that is
<oprypin> i'm 99% sure it's being exported properly
<oprypin> looking at this, the application needs to also *import* the global https://stackoverflow.com/a/8044218
Renich has joined #crystal-lang
<tzekid> Hi
<FromGitter> <sdogruyol> hey
<tzekid> what's up with method generics ? ( e.g. https://play.crystal-lang.org/#/r/2bii )
<FromGitter> <sdogruyol> @oprypin is this for Windows support?
<FromGitter> <mverzilli> (for tzekid)
<tzekid> thanks :)
<FromGitter> <mverzilli> the T there is a free variable, so it needs to be quantified
<FromGitter> <sdogruyol> forall is kind of underdocumented :P
<FromGitter> <mverzilli> if you were inside a class (like `Array(T)`) it would mean "the same T as this instance"
<oprypin> sdogruyol, it's related. just trying to run my lib on Windows. it's a good candidate for being the first useful thing actually working because external libs dont use standard library's I/O and exceptions
<FromGitter> <mverzilli> @sdogruyol yep
<oprypin> C lib
<FromGitter> <sdogruyol> @oprypin wow, is there anything to help?
<crystal-gh> [crystal] MakeNowJust opened pull request #4687: Get version number from CHANGELOG.md when cannot get it from git (master...fix/crystal/4642-version-build-tar-ball) https://git.io/vQK0u
greengriminal has joined #crystal-lang
<oprypin> well.. help me import those variables. though i could rework to export a setter function instead of a global
<oprypin> on POSIX if a library exports a global variable, you can link to it and just use it. on Windows apparently you must explicitly specify that it's being imported
<oprypin> and Crystal is not doing that import thing and I have no idea how to do it, because the docs keep saying "yeah, just use `__declspec(dllimport)`" - but that applies only to MSVC
<Papierkorb> How does Crystal link on Windows?
<Papierkorb> So a C compiler too?
<oprypin> obj is produced on Linux through cross compile, then using `link` from "Microsoft Build Tools"
<Papierkorb> Or rather, for crsfml, you're compiling through MSVC?
<oprypin> Papierkorb, no C compiler is involved
<oprypin> Papierkorb, I compile the C bindings to a C++ library usign MSVC, yes
<Papierkorb> And that works I assume?
greengriminal has quit [Client Quit]
<oprypin> I know it works on Linux but i've yet to try it on Windows
<oprypin> could try compiling a basic C program using those bindings, but it's not trivial so i've not done that yet
<Papierkorb> Well, it should if correctly use the dllimport stuff in there
<Papierkorb> +you, and re-order the words. oh well.
<oprypin> so now i need to find a way to compile a thing on Windows and specify include + library path
<oprypin> just to confirm that it's Crystal missing something
<Papierkorb> Just write a C program which calls some kind of init function from VoidSFML. If that runs, it'll work for Crystal as far the C end is concerned
<oprypin> Papierkorb, I have the C program
<oprypin> > so now i need to find a way to compile a thing on Windows and specify include + library path
<Papierkorb> MSVC project?
<oprypin> cl -I include test.c getting syntax errors on header files which were just compiled into a lib just fine
<oprypin> nvm..
<oprypin> yep it works
<oprypin> cl -I include voidcsfml-window.lib voidcsfml-system.lib -Tp test.c easy enough
<FromGitter> <sdogruyol> Woot
<oprypin> sdogruyol, to clarify, no Crystal is involved in the thing that works. just eliminating errors in other components
<oprypin> so it's back to how to do the equivalent of `__declspec(dllimport)` in Crystal
greengriminal has joined #crystal-lang
greengriminal has quit [Quit: This computer has gone to sleep]
greengriminal has joined #crystal-lang
<FromGitter> <konovod> Hi all. No idea on how to do `dllimport` but wow, crsfml working on windows would be awesome. Crystal on windows still use `gc`\`libevent`\`pcre` without any additional specifiers, so maybe problem isn't in `dllimport`?
<oprypin> konovod, the problem is specifically with using exported globals. using exported functions works without dllimport
greengriminal has quit [Client Quit]
<oprypin> globals that you would write like lib Lib; $global_var : Type; end
<FromGitter> <konovod> oh. exported vars.
greengriminal has joined #crystal-lang
greengriminal has quit [Client Quit]
<FromGitter> <konovod> I don't see them in voidcsfml. What they are used for? Can't you just replace them with functions?
<oprypin> konovod, I can indeed replace globals with setter functions
<oprypin> it would be good to get it working though. that may not always be an option
<oprypin> they are used to set a callback which is used to fake class inheritance
<FromGitter> <konovod> Now I see. well, exported vars are not very common imho. I know app have to *export* two vars to enforce discrete video on laptops though.
<oprypin> https://msdn.microsoft.com/en-us/library/aa271769(v=vs.60).aspx Using __declspec(dllexport) and __declspec(dllimport) on Data
<oprypin> I changed `$global : Type` into `__imp_global : Type*` - apparently that works. at least it links
<oprypin> so crystal would probably need to have such a substitution implemented
<oprypin> CrSFML works!
<FromGitter> <fridgerator> :thumbsup: :tada:
<FromGitter> <konovod> omg. time to do serious gamedev
<oprypin> ikr
<FromGitter> <hugoabonizio> @oprypin :confetti_ball: :tada:
<oprypin> i'm failing to find an example that fails to work due to sfml failure. one is missing libGL and one is missing libyaml
<oprypin> (because I happened to use them in that particular example)
<oprypin> hm got a first one `slither.o : error LNK2019: unresolved external symbol __powisf2 referenced in function .Float32....Int32..Float32`
<oprypin> that's just a posix math function apparently
<Papierkorb> Ah yeah the Windows libc is sh.. I mean not up to POSIX standard
<FromGitter> <mverzilli> "CrSFML works!" <- wtf how's that possible!?
<oprypin> as i was saying, "just trying to run my lib on Windows. it's a good candidate for being the first useful thing actually working because external libs dont use standard library's I/O and exceptions"
<oprypin> big enough, isolated enough framework
<FromGitter> <mverzilli> that's amazing!
<oprypin> worked with just one hitch, based on https://github.com/txe/crystal/tree/win
<FromGitter> <schoening> ```AABB.for_each_intersect_between players do |p1, p2| ⏎ puts "#{p1}, #{p2}" ⏎ end``` ⏎ ⏎ Hehe.. I might be going a bit far with it but I love this pseudocode syntax right now as a beginner haha. Too bad I never tried out Ruby, had to get tortured with php instead [https://gitter.im/crystal-lang/crystal?at=595ff4e3c101bc4e3a61f2e2]
<FromGitter> <bararchy> @fridgerator Hi, just saw your fantasy football genetic project, really really cool !
greengriminal has joined #crystal-lang
hightower2 has joined #crystal-lang
<FromGitter> <renich> How do I convert a Hash into a NamedTuple? I mean, is there a mapping method or something?
<FromGitter> <fridgerator> thanks :thumbsup:
<Papierkorb> renich, not possible to do automatically
<Renich> Papierkorb: so I need to map it manually?
<Renich> with a map?
<Renich> oh... no, that won't work, right?
<oprypin> {a: hash["a"].as(Int32), .........}
<oprypin> you have to have the full knowledge of predefined field names and types
<Renich> oprypin: yeah, they can't be arbitrary... oh, well, it seems I will be stuck with Hashes then
<Renich> oprypin: maybe I can just convert it to yaml and back to NamedTuple? Everything would be a string, though...
<oprypin> Renich, you can do that but there's nothing to gain from that
<Renich> why?
<oprypin> > you have to have the full knowledge of predefined field names and types
<oprypin> no workaround, no hack
<oprypin> if you're looking for a way to do it under this condition, i just showed it. if you're looking for a more compact way, you can write a macro
<Papierkorb> Renich: why do you need that?
<FromGitter> <straight-shoota> Actually there is `NamedTuple.from(hash: Hash)`
<oprypin> <a particular class of namedtuple>.from
<FromGitter> <straight-shoota> of course this only works if you know the keys and their types beforehand
tzekid has quit [Remote host closed the connection]
<oprypin> >> {a : Int32}.from({"a" => 5})
<DeBot> oprypin: no overload matches 'Tuple(Nil)#from' with type Hash(String, Int32) - https://carc.in/#/r/2bjr
<oprypin> i must have forgotten how to specify namedtuple
<FromGitter> <straight-shoota> > NamedTuple(a : Int32).from({"a" => 5})
<oprypin> >> NamedTuple(a : Int32).from({"a" => 5})
<DeBot> oprypin: Syntax error in eval:17: expecting token 'CONST', not 'a' - https://carc.in/#/r/2bjs
<oprypin> >> NamedTuple(a: Int32).from({"a" => 5})
<DeBot> oprypin: # => {a: 5} - https://carc.in/#/r/2bjt
<Renich> Papierkorb: I want all my methods to be able to use splat
<FromGitter> <straight-shoota> does DeBot only evaluate from IRC?
<oprypin> straight-shoota, yes
<Papierkorb> Renich: You can..? Defining them through Hash is weird, and if you do that from inside Crystal, needlessly slow
<Renich> Papierkorb: RESTful API returns json. Then, I need to add stuff to that json and convert it to a NamedTuple
<Renich> I create order, it returns only the success message, saying that order #n was created, I need to parse the message to extract the order # and put it into the order again, which is a NamedTuple for now. So, I convert it into a hash, merge, and... I get stuck
<oprypin> i think it's a neat enough idea
<oprypin> Renich, https://carc.in/#/r/2bjx
<oprypin> let me simplify
<oprypin> actually cant simplify. just different. Renich, https://carc.in/#/r/2bk7
<oprypin> to see behind the scenes https://carc.in/#/r/2bk8 https://carc.in/#/r/2bk9
<oprypin> Renich, btw i should've read your last message. total XYproblem
<Renich> Interesting, oprypin. The power of Macros is really cool. I just haven't gotten around to understand them that much.
<Renich> Really cool. The debug feature helps understand what it does much better. thanks a lot for the examples.
<oprypin> Renich, you really shouldn't convert to Hash to merge namedtuples, that's all
<Renich> oprypin: yes. How do you merge named tuples? t + t?
<Renich> on a new one?
<oprypin> I want to know that as well. but can't you rethink it somehow?
<oprypin> do JSON.mapping, get an object, reserve one unused field in it, populate it afterwards, etc
<oprypin> merging tuples should be a thing
<oprypin> but i dont know how
<Renich> That is a good idea actually
<Renich> I will try to map it and reserve the additional stuff
<Papierkorb> Almost done..
<Papierkorb> And it works
<Papierkorb> Wondering why it's #merge for Hash, but #+ for Array. Don't see why Hash#+ shouldn't be a thing
<oprypin> Papierkorb, because + should be symmetric
<Papierkorb> ..?
<oprypin> Papierkorb, in merge one mapping has precedence over the other
<oprypin> see also: Set & |
<Papierkorb> Ah dang, no yielding version possible, or at least not one without unexpected behaviour
<Papierkorb> > BUG: trying to assign Int32 <- Symbol
<Papierkorb> And now it even found a bug
<Papierkorb> CC Renich
<Renich> Papierkorb: ah! Cool! Thanks, man!
<Renich> Papierkorb: that's really cool, man. Thanks a lot.
<FromGitter> <renich> So, for now, I am moving to this: https://carc.in/#/r/2bkf
<FromGitter> <renich> Got stuck passing the order to the URI parser
<FromGitter> <renich> I can't convert a mapped JSON to a tuple or hash
<FromGitter> <renich> which is what .encode accepts
<Papierkorb> And corresponding PR https://github.com/crystal-lang/crystal/pull/4688
<crystal-gh> [crystal] Papierkorb opened pull request #4688: Add NamedTuple#merge(other : NamedTuple) (master...add-namedtuple-merge) https://git.io/vQKdv
<oprypin> renich, hm wow, sorry about the dilemma. i dont even know
<Renich> no worries, oprypin:
<oprypin> basically i really recommend Papierkorb's solution
greengriminal has quit [Quit: This computer has gone to sleep]
hightower2 has quit [Ping timeout: 240 seconds]
<oprypin> Renich, https://carc.in/#/r/2bkh
<Renich> oprypin: man! You're a macro magician! ;=)
<Renich> Thanks a lot. This really helps me understand macros better. Little by little.
hightower2 has joined #crystal-lang
hightower2 has quit [Ping timeout: 255 seconds]
greengriminal has joined #crystal-lang