ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.34.0 | 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> <watzon> Does anyone know if there are plans to eventually support closures in C callbacks?
karchnu has left #crystal-lang ["WeeChat 1.9.1"]
<oprypin> watzon, umm depends on what you mean. looking at it one way, it's been supported from the beginning. looking another way, it's impossible
<oprypin> it just requires a passthrough pointer to push the closure data through. or i guess you could make the closure global which kinda defeats the point
<FromGitter> <watzon> Hmm forgot about the wrapper
<FromGitter> <watzon> There's no way to make this simpler on the developer?
<FromGitter> <watzon> Because I find myself getting this pretty often when trying to wrap C libs
<oprypin> watzon, well if ithelps, the code doesnt need to be so complicated. see simpler one https://github.com/oprypin/crystal-chipmunk/blob/1fbf0a10365ec9751d01dc0dc88e2abcee0f6994/src/chipmunk/space.cr#L279-L282
<oprypin> `pointerof(block)`; `data.as(typeof(block)*).value.call`
<oprypin> i actually forgot what the point of Box was
<FromGitter> <watzon> Hmm that actually might help
<oprypin> watzon, but the thing is you can pass a whole object as that `data` and call its methods normally
<oprypin> `data.as(MyObject*).value.any_method()`
<oprypin> damn, i just looked through my own code and it's pure genius
<FromGitter> <watzon> Lmao nice self pat on the back
<FromGitter> <watzon> But yes
<oprypin> and i havent progressed since then in 4 years 😢
<oprypin> i set one global callback and use it not only for all objects of that type but for all subclasses
<oprypin> but of course u can do that only if designing your own C wrapper
<oprypin> so it's not relevant to any other use case, don't mind me
<oprypin> let's see what GitHub Actions will say after i tell it to build the whole LLVM... https://github.com/oprypin/crystal/runs/590652247 30 minutes and going ..........
<FromGitter> <watzon> Oof lo
<FromGitter> <watzon> That did actually help a lot oprypin, this is what I ended up with
<FromGitter> <watzon> Just aiming for a thin wrapper around Papierkorb/cute
ur5us has quit [Ping timeout: 272 seconds]
zorp has quit [Ping timeout: 260 seconds]
<oprypin> watzon: I'm not sure how that will play with garbage collection. could be unsafe and that could be the whole point of Box 😬
<oprypin> like, something needs to keep `cb` referenced within Crystal land
<oprypin> maybe u can just use @cb||=
<oprypin> that'd be for the best
zorp has joined #crystal-lang
<FromGitter> <watzon> Is it possible to explicitly return void from a proc?
<FromGitter> <watzon> I'm trying to debug why the top one is working, but the bottom one gives me a sigfault https://hasteb.in/hamelike.rb
<FromGitter> <watzon> The only real difference here is the callback signature
ur5us has joined #crystal-lang
deavmi has quit [Ping timeout: 256 seconds]
<FromGitter> <Blacksmoke16> doesnt one need to return an int?
deavmi has joined #crystal-lang
deavmi has quit [Read error: Connection reset by peer]
<FromGitter> <watzon> The top one does
<FromGitter> <watzon> `cb = ->() { closing.emit; 0 }`
deavmi has joined #crystal-lang
deavmi has quit [Ping timeout: 250 seconds]
_whitelogger has joined #crystal-lang
deavmi has joined #crystal-lang
<FromGitter> <watzon> Ok I think GC is the issue, at least it seems to be with another closure I'm handling
<FromGitter> <watzon> Is there a way to prevent GC besides assigning the callback to a class variable?
ur5us has quit [Ping timeout: 252 seconds]
ur5us has joined #crystal-lang
<FromGitter> <grkek> @watzon I have something of an UI framework myself, it is utter garbage but you can check it out idk
<FromGitter> <grkek> https://github.com/grkek/iu
<FromGitter> <grkek> It's not one of the brightest out there but there are some examples if you want to take a quick look
ur5us has quit [Ping timeout: 252 seconds]
_whitelogger has joined #crystal-lang
early has quit [Quit: Leaving]
early has joined #crystal-lang
_ht has joined #crystal-lang
ur5us has joined #crystal-lang
return0e has quit [Read error: Connection reset by peer]
return0e has joined #crystal-lang
return0e has quit [Read error: Connection reset by peer]
return0e has joined #crystal-lang
ur5us has quit [Ping timeout: 256 seconds]
darkstar_13 has joined #crystal-lang
ur5us has joined #crystal-lang
<FromGitter> <naqvis> is there any way to find out how many bytes were read from an IO when an `IO::EOFError` is raised? Under normal conditions `read` does return the count, so my question applies to conditions when `EOFError` is raised
<FromGitter> <naqvis> assuming the count to 0 is invalid, as I've seen stdlib does read into slice, but raises when conditions applies, so some portion of data has been read into slice passed, but there is no way to know the count
<FromGitter> <naqvis> I tried to do pointer subtraction, but `to_unsafe` always returns the same pointer, so before and after pointer subtraction always yields 0
<FromGitter> <naqvis> also `IO::pos` is not reliable one, as default implementations raises and only `IO::FileDescriptor` and `IO::Memory` implements this
<FromGitter> <j8r> count manually?
<FromGitter> <j8r> each time you read a byte, increment a counter?
<FromGitter> <naqvis> yeah, that could be done if reading byte by byte
<FromGitter> <naqvis> but if you are going to read in chunk, there is no way to do that
<FromGitter> <j8r> yep :/
<FromGitter> <j8r> I don't think it is possible
<FromGitter> <j8r> *with the current stdlib
<FromGitter> <naqvis> another naive approach would be to fill the slice with some special value and once encountered EOF do a scan to find the first index of that special value 😆
<FromGitter> <j8r> good idea
<FromGitter> <naqvis> lol, then will need to find a globally unique value, which no data will ever contain
<FromGitter> <naqvis> or else this approach is out of luck
<FromGitter> <naqvis> lol
<FromGitter> <j8r> but it is already filled with `0`
<FromGitter> <naqvis> true, but there are null strings, especially in binaries
<FromGitter> <naqvis> so will it be safe bet to scan for next null value to figure out the count?
<FromGitter> <j8r> IO only accepts `Bytes`, which is `Slice(UInt8)` - not much choice
<FromGitter> <naqvis> yeah true
<FromGitter> <j8r> between 0 or 255, all can be used
<FromGitter> <j8r> what is your IO?
<FromGitter> <naqvis> could be any
<FromGitter> <naqvis> Network, File, Memory etc
<FromGitter> <naqvis> function accepting any implementation of `IO`
<FromGitter> <j8r> because each one has its own implementation of `#read(bytes)`
<FromGitter> <j8r> how does it helps to have a counter?
<FromGitter> <naqvis> don't think that will help, as it's the Reader::IO which is going to trigger the EOFError
<FromGitter> <naqvis> so implementing a Counter on reader side, will suffer from same implications
<FromGitter> <naqvis> my opinion would be to capture the count in EOF error, kind of modified `IO::EOFError` would look like this ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e98268274bfed5a1b3c44a4]
<FromGitter> <naqvis> in that way, implementation side, when raising this exception, will provide the count for user side to capture
<FromGitter> <grkek> Instead of changing the error code override the File read function and implement it in there no need to push that to std
<FromGitter> <naqvis> @grkek monkey patching require knowledge of underlying implementation
<FromGitter> <naqvis> my question applies at generic level, it should be the responsibility of the implementation side to provide the details to user side, not the otherway around
<FromGitter> <grkek> Interesting, suggest that on the crystal issues page
<FromGitter> <stronny> @naqvis IO#read says that "Returns the number of bytes read, which is 0 if and only if there is no more data to read (so checking for 0 is the way to detect end of file)."
<FromGitter> <stronny> it shouldn't raise on EOF
<FromGitter> <naqvis> `io.read_fully`
<FromGitter> <naqvis> and many other methods implemented by `IO` raises this exception
<FromGitter> <naqvis> `read` is the bare minimum method which implementor need to implement
<FromGitter> <stronny> so how would you use the count?
<FromGitter> <stronny> my point is that if you are okay with partial read why do you use read_fully?
<FromGitter> <naqvis> I agree, but question would be what's the use of raising an exception while not fully giving the information back to user side?
<FromGitter> <naqvis> there is no way to know how much bytes has been read, when you encounter this exception
<FromGitter> <stronny> the logic would be like this: "I need this exact number of bytes; if anything goes wrong then I have nothing useful to do with the result"
<FromGitter> <stronny> if your usecase is different, don't use read_fully
<FromGitter> <naqvis> i would argue against your logic here
<FromGitter> <naqvis> when reading IO, you get no clue on how much data is there
<FromGitter> <naqvis> simple example would be reading a network
<FromGitter> <stronny> of course
<FromGitter> <naqvis> in general, its always good practice to provide as much info back as possible, instead of simply saying "something bad happen" lol
<FromGitter> <stronny> use IO.read
<FromGitter> <naqvis> and that was the trigger for my this discussion
<FromGitter> <naqvis> yeah and I use IO.read only
<FromGitter> <stronny> I think you're misrepresenting stdlib here a little
<FromGitter> <naqvis> not stdlib, but this specific EOFError
<FromGitter> <stronny> many methods don't raise, there even is read_fully? if you prefer nil
<FromGitter> <naqvis> other than that, i'm good with stdlib
<FromGitter> <stronny> gets doesn't raise, read_line does
<FromGitter> <stronny> or do you see no utility in EOFError in general?
<FromGitter> <naqvis> point is, when action is performed (though not fully), what has been done, should be propagated back to user
<FromGitter> <naqvis> those methods in question does raise EOF even when they have read bunch of data
<FromGitter> <naqvis> but how much work was done? user is left in dark
<FromGitter> <stronny> exceptions don't work in the pattern you describe
<FromGitter> <naqvis> doesn't it make sense to provide the details of you asked 100 and there was only 10 left
<FromGitter> <naqvis> something like this
<FromGitter> <naqvis> Exceptions are a way to break
<FromGitter> <stronny> they contain the context of error, not other actions
<FromGitter> <naqvis> but that doesn't dictate on you can't capture details
<FromGitter> <naqvis> yes, context is there, but it is incomplete, that's my point
<FromGitter> <stronny> can you point out an example of the language/runtime that behaves like your proposal?
<FromGitter> <naqvis> and such context provide no useful info back to user
<FromGitter> <naqvis> I do that way
<FromGitter> <naqvis> every exception raised, provide meaning information back
<FromGitter> <stronny> where does EOFError contain the read count/data?
<FromGitter> <naqvis> it doesn't
<FromGitter> <stronny> any idea why it doesn't?
<FromGitter> <naqvis> that's my question
<FromGitter> <stronny> so here's the answer: it isn't helpful, it's unuseful information
<FromGitter> <stronny> if you think you will gain anything with it show some example code
<FromGitter> <stronny> chances are it could be made better with no such facilities
<FromGitter> <stronny> do you wish to stuff the entire execution context into every exception? presumably no, so you only include *relevant* data
<FromGitter> <stronny> what's been read isn't relevant to EOFError
<FromGitter> <naqvis> either I wasn't clear in my communication or you couldn't get my point
<FromGitter> <naqvis> i'm not taking about stack tracing here
<raz> i'll side with naqvis here and agree it would be nice if exceptions generally provide meaningful context (where possible, sensible and it of course shouldn't add runtime cost)
<FromGitter> <naqvis> my whole point was, when some data is read, there should be some way to report back
<FromGitter> <stronny> they do provide it already
<FromGitter> <stronny> there is a way, it's IO.read
<FromGitter> <naqvis> or if you can guide me to the direction, where I can capture such details from the slice which I pass
<FromGitter> <naqvis> if you read my initial question, that does convey the intention
<FromGitter> <stronny> so what you ask for is a method `read_fully_unless_there_is_not_enough_data_in_which_case_read_as_much_data_as_there_is`
<FromGitter> <grkek> kek
<FromGitter> <grkek> imagine that function name in the std
<raz> that's a nice method name
<FromGitter> <grkek> lib
* raz adds to clipboard
<FromGitter> <stronny> how would you use it and how it's different from `read`?
travis-ci has joined #crystal-lang
travis-ci has left #crystal-lang [#crystal-lang]
<travis-ci> crystal-lang/crystal#454f07e (master - Remove special handling for version tags in docs generator (#9083)): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/675659058
<raz> grkek, camelcase it and could me straight from the java stdlib :p
<FromGitter> <grkek> obligatory language bashing :D
<FromGitter> <stronny> no, java whould have a factory
<raz> couldn't let that opportunity pass :D
<raz> an abstract factory i hope
<FromGitter> <stronny> final private abstract factory
<FromGitter> <grkek> `private protected static delegate void`
<FromGitter> <naqvis> lol, I love final private
<FromGitter> <stronny> so to conclude my thoughts: ⏎ ⏎ 1) if you process data chunk-by-chunk all you need is bare `read` ⏎ 2) if you need the whole input you have `gets_to_end` ⏎ 3) read_fully is useful in all-or-nothing cases [https://gitter.im/crystal-lang/crystal?at=5e98321e2ff88975b422d484]
<FromGitter> <grkek> i dont like the weird naming scheme
<FromGitter> <grkek> gets
<FromGitter> <grkek> puts
<FromGitter> <grkek> thats from ruby right?
<FromGitter> <stronny> right
<FromGitter> <naqvis> Thanks @stronny , out of my experience with crystal, I've never used any other method than read on IO 😆
<FromGitter> <grkek> Crystal might be one greatest langs to work with IO
<FromGitter> <grkek> imo
<FromGitter> <naqvis> but question was, why is stdlib doing half-baked activity like reading IO and writing to populate the slice and then BOOM
<FromGitter> <naqvis> and don't give users any clue on how much data was read into slice before this big BOOM
<FromGitter> <grkek> which function do you mean/
<FromGitter> <stronny> because if you need this information you don't use thid method
<FromGitter> <grkek> ?
<FromGitter> <naqvis> yeah, so I don't
<FromGitter> <stronny> so no problem =)
<FromGitter> <naqvis> as I said, i only use IO.read and IO.write
<FromGitter> <stronny> what's wrong with that?
<FromGitter> <naqvis> nothing wrong
<FromGitter> <naqvis> works like a charm
Human_G33k has joined #crystal-lang
<FromGitter> <stronny> cool!
<FromGitter> <naqvis> mean read and write
HumanG33k has quit [Ping timeout: 260 seconds]
ur5us has quit [Ping timeout: 272 seconds]
travis-ci has joined #crystal-lang
travis-ci has left #crystal-lang [#crystal-lang]
<travis-ci> crystal-lang/crystal#47f3432 (master - Miscellaneous Windows-related fixes in the compiler (#9054)): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/675678285
<FromGitter> <aamir-s18> Hey I tried to build my crytsal app for windows and got this "Error can't find 'c/arpa/inet' is there any solution for this thank you :)
<FromGitter> <stronny> do you have a portable program or is it just windows?
<FromGitter> <aamir-s18> what do you mean?
<FromGitter> <stronny> is your program supposed to run on windows only or win/lin/mac?
<FromGitter> <aamir-s18> Ah on all three
<FromGitter> <stronny> what does it do? I'm just curious
<FromGitter> <aamir-s18> its just a little software project for an uni course. We have courses where we can submit our programming solution and it will check it automaticly. We wrote a CLI for this.
<FromGitter> <ImAHopelessDev_gitlab> @grkek missing abstract def 😆
<FromGitter> <stronny> so is it a requirement that it should run cross-platform?
<FromGitter> <grkek> @ImAHopelessDev_gitlab where?
<FromGitter> <aamir-s18> yeah but we are already done. We didnt checked if Crystal is able to do this
<FromGitter> <stronny> not at the moment
<FromGitter> <stronny> it should run somewhat fine in WSL, but not natively
<FromGitter> <ondreian> This seems a bit... weird: ⏎ https://play.crystal-lang.org/#/r/8wft ⏎ ⏎ In my example, if I cast to an intermediate variable binding, it compiles, if you swap the code to call `hydrate_err` it will no longer compile and complain that `@enum` is `Array(String) | Nil` even though I am clearly narrowing the type. [https://gitter.im/crystal-lang/crystal?at=5e984d0e74bfed5a1b3cc213]
<FromGitter> <stronny> `@ivar.is_a?` doesn't work
<FromGitter> <stronny> you should store it in a temp var
<FromGitter> <stronny> `if (var = @ivar).is_a?`
<FromGitter> <stronny> that's a known limitation
<FromGitter> <ondreian> interesting, missed it in the documentation. thanks
<FromGitter> <stronny> near the end
<FromGitter> <Afront> Woah, you can use Crystal in your uni?
<raz> some unis are smart <3
<FromGitter> <stellarpower> I'm hoping I can rework something I did in second year in python into Crystal and take it forward for projects in later years
<FromGitter> <stellarpower> Used a script to parse and spit out equivalent Ruby and then going form there, file by file
<raz> i never understood why they seem to use so much python in unis
<FromGitter> <stronny> someone decided it's good for learning
<FromGitter> <stronny> I disagree, but my opinion was not considered lol
<FromGitter> <stellarpower> So they told me (physics) that they used C a good while ago
<FromGitter> <stellarpower> But people couldn't handle pointers
<FromGitter> <stellarpower> And then went to Java
<FromGitter> <stellarpower> And finally gave up and chose python
<raz> well, it's not. not only is python ugly from an aesthetic pov but it's also hideously unpure. neither does it teach proper OOP nor any low-level stuff.
<FromGitter> <stronny> yep, I don't like python
<FromGitter> <stellarpower> I can see the argument that Python has a lot of libraries available and is widely used in the sciences so it's good to go out the box for many things
<FromGitter> <stellarpower> But as a language I hate it
<FromGitter> <stellarpower> I realised though it's a bit hard to complain
<raz> well yes, those math libraries seem to be the big draw
<raz> pity they had to be written in python of all things
<FromGitter> <stronny> good scientists are rarely also good programmers
<FromGitter> <stellarpower> I see people taking up programming for the first time and get quite into it with no idea how memory allocations, types, etc. work. To that end it has done the job of abstractinga virtual machine and expressing a program in domain-level concepts
<FromGitter> <stellarpower> But
<FromGitter> <stellarpower> Icky
<FromGitter> <tenebrousedge> list comprehensions are a really silly thing to choose over proper higher-order functions
<FromGitter> <stronny> in the good old days they didn't have to write programs themselves
<FromGitter> <stellarpower> I had to use numpy and matplotlib for said project
<raz> tenebrusedge++
<FromGitter> <stellarpower> Numpy was horrendous
<FromGitter> <stellarpower> It kept trying to infer dimensions incorrectly and it took forever to trace it down
<FromGitter> <stellarpower> Everything was fine and then suddenly broke because it collapsed an array to a scalar argument when previously it iterated over
<raz> every time a pythonista praises their "amazing" list comprehensions i throw up a little in my mouth. they are a nasty kludge to a problem that had long been solved properly elsewhere.
<FromGitter> <stellarpower> We had to do them in Haskell
<FromGitter> <stellarpower> Like
<FromGitter> <stellarpower> They aren't really necessary in Python
<FromGitter> <stellarpower> Haskell felt a lot like TMP in C++
<FromGitter> <stellarpower> But I'm really pleased Crystal exists. I've always preferred Ruby over Python but the main thing that annoys the hell out of me over time is just it's a pain to debug. It's fast to write and slow to debug, you by and large just turn what could be compile-time errors into the runtime domain and that's just very annoying.
<FromGitter> <stellarpower> So to be able to drop into my preferred scripting language and yet find it's got proper bigboy features and compiles down is great
<FromGitter> <stronny> yes, but
<FromGitter> <stronny> it takes 10x time to write
<FromGitter> <stellarpower> Which does?
<FromGitter> <stronny> crystal vs ruby
<FromGitter> <stellarpower> Ruby takes 10x to run and debug
<FromGitter> <stellarpower> I find
<FromGitter> <stronny> yep, that's the choice
<FromGitter> <stellarpower> I'd rather think than run a really slow webdriver script that keeps breaking and takes forever to initialise cause the website is broken and then realise I made a typo and it crashes and can;t output my results.
<FromGitter> <stellarpower> Plus, thinking about your code overall is probably a good thing
<FromGitter> <stellarpower> If it takes long to write hopefully I've thought about it carefully
<FromGitter> <stronny> if you can afford it
<FromGitter> <tenebrousedge> I think Ruby's debugging tools are stronger at the moment: `icr` is no `pry`. But many categories of error in Ruby are not possible in Crystal
<FromGitter> <stellarpower> I mean different strokes for different folks
<FromGitter> <stellarpower> But I am trying to port or write as much new stuff in Crystal as I can to get used to it and I think for the way I work it will speed me up
<FromGitter> <stronny> I'm not saying crystal is worse than ruby
<FromGitter> <stellarpower> I've not really set up a proper debugger yet but it should be possible to step through it properly and watch what's happening if compiled with debugging symbols, right?
<FromGitter> <stronny> just keeping perspectives
<FromGitter> <stellarpower> Oh no, I didn't think you are
<FromGitter> <stellarpower> It just suits me
<FromGitter> <stellarpower> Well in theory
<FromGitter> <stellarpower> I've not managed o write much recently where I can choose the language
<FromGitter> <stronny> hobby projects?
<FromGitter> <stellarpower> Yeah, not had much time to work on them properly
<FromGitter> <stellarpower> Plus am getting my feet with Illumos, a lot of tidying up is stacking up until I can clear some of the bottlenecks
<FromGitter> <stellarpower> So e.g. the webscraper, there are shards for webdriver but I think still relatively new
<FromGitter> <stellarpower> It's a shame but I think for some things it may be a matter of putting them on the pile so hopefully more libraries are available or are more mature in say 6 months' time
<FromGitter> <stronny> pity we can't use C libs without any code
<FromGitter> <stronny> you still need to write/generate a wrapper
<FromGitter> <stellarpower> Yeah, that's often the catch
<FromGitter> <stellarpower> Some moves may be made in automating more of it I guess
<FromGitter> <stellarpower> Also a shame one can't just hook into an existing gem. I know they are separate and distinct languages and not at all the same under the hood, but some small ruby libraries are a nice layer over the top of e.g. a C library that expose a minimal API that is enough like Crystal it would be nice if that could work in the meantime
<FromGitter> <stronny> no, that is probably impossible
<FromGitter> <stellarpower> Yeah
<FromGitter> <stellarpower> Or at least not worth the effort
<FromGitter> <stellarpower> I was wondering whether or not it'd be possible at all to marshall across things like hashes, arrays, etc. using the C implementation parts
<FromGitter> <tenebrousedge> it would probably be easier to rewrite, especially if it's just a translation layer
<FromGitter> <stronny> there are no arrays/hashes in C
<FromGitter> <stellarpower> Just conceptually because they're semantically close in the respective languages, if you relax type restrictions for a second
<FromGitter> <stellarpower> As in the c libraries of the ruby implementation
<FromGitter> <stronny> ruby ext? native extensions in gems?
<FromGitter> <stronny> no, that code is useless in crystal
<FromGitter> <tenebrousedge> well, you could embed a Ruby interpreter in Crystal 😬
<FromGitter> <stronny> mruby yes
<FromGitter> <stellarpower> As in Matz's ruby is written in C and so it exposes the data structures that represent objects in memory as C structs. I don't know that much but much of what specifies fundamental types is built into the C, sometimes because the types are so fundamental and sometimes for speed on very common methods.
<FromGitter> <stronny> hm? what data structure are build in c?
<FromGitter> <stellarpower> As a thought experiment I was wondering how far one could go before the wheels fell off if you e.g. wanted to hook into a function in ruby
<FromGitter> <stronny> it probs could be done, but with a great effort
<FromGitter> <stronny> yes, you need to integrate mri into your program
<FromGitter> <j8r> Wow, I just cut by half generating a 3 matrix using preview_mt
<FromGitter> <j8r> 1minute on 1thread, 30seconds on 4threads
<FromGitter> <j8r> Generating the X row on a first pass, then spawn to generate Y and Z rows
<FromGitter> <parshua_gitlab> I have a visibility question developing shards: ⏎ if I have a file `a.cr` with following contents: ⏎ ⏎ ```code paste, see link``` ⏎ ... [https://gitter.im/crystal-lang/crystal?at=5e985887c38aa05a1a77b9d8]
<FromGitter> <j8r> `require "./a.cr"`?
<FromGitter> <parshua_gitlab> in reality, there are more files, and requiring the file doesn't work for some reason
<FromGitter> <Blacksmoke16> what if you do `Core::A`
<FromGitter> <parshua_gitlab> same error: `Error: undefined constant Core::Toplevel`
<FromGitter> <Blacksmoke16> well thats not the same error?
<FromGitter> <Blacksmoke16> used to be undefined constant A
<FromGitter> <Blacksmoke16> try without `extend self`
<FromGitter> <parshua_gitlab> error again, with or without `Core`
<FromGitter> <tenebrousedge> also note that this doesn't work: https://play.crystal-lang.org/#/r/8wg0
<FromGitter> <parshua_gitlab> this works though: https://play.crystal-lang.org/#/r/8wg3
<FromGitter> <tenebrousedge> right
<FromGitter> <j8r> As a little side project I'm building a voxel worl. ⏎ Godot would be the client and Crystal the server. ⏎ ⏎ For now the game map matrix is a `Array(Array(Array(T))).` [https://gitter.im/crystal-lang/crystal?at=5e985cd8e920022432aaf3ff]
<FromGitter> <j8r> I think the map would be progressively load by chunks. Any ideas?
<FromGitter> <j8r> I experimented with `StaticArray`, but cannot compile. ⏎ Array is a good first step
<FromGitter> <tenebrousedge> a graph sounds like maybe a better idea than an array?
<FromGitter> <tenebrousedge> I mean, not that you can't represent one using the other
<FromGitter> <j8r> a graph?
<FromGitter> <j8r> how can I do?
<FromGitter> <Blacksmoke16> y = mx + b
<FromGitter> <j8r> The idea is to have something similar to Minecraft
<FromGitter> <j8r> (but with a lot more voxels and better physics)
<FromGitter> <j8r> OK for the graph, but how I store and manipulate it?
<FromGitter> <tenebrousedge> do like an array of nodes, where a node has a reference to other nodes that are reachable from that one
<FromGitter> <j8r> Maybe Minetest do this
<FromGitter> <j8r> Interesting, thnaks
<FromGitter> <j8r> Most of the world will be random, even blocks
<FromGitter> <j8r> I will do my best to separate the store to the other logic, so future refactorings would be simpler
<FromGitter> <sam0x17> @j8r love to see you making a crystal fork of the open-simplex-noise rust crate. I've actually used that one before
_ht has quit [Remote host closed the connection]
_ht has joined #crystal-lang
<FromGitter> <grkek> @j8r have you ever dealt with timeouts of sockets?
<FromGitter> <grkek> websockets*
<FromGitter> <stronny> there were some topics on the forum
<FromGitter> <j8r> @grkek no, I didn't use them much
<FromGitter> <j8r> for now. I hope I won't have them :/
<FromGitter> <j8r> I believe I have to use Hash to have sparse arrays
<FromGitter> <kinxer> @j8r Are you open-sourcing this or writing it just for yourself (not that the latter is bad). If you're open-sourcing it, I'll be very interested to see how you implement the server.
<FromGitter> <j8r> @kinxer Ho, yes. I don't know how all of this will go, for now I am doing this because it is fun :) ⏎ I'll open source it if it end up being working, by luck haha
<FromGitter> <j8r> I don't know if girng is still around - too bad he was a pro on this topic
<FromGitter> <j8r> For now, one open source lib I use: https://github.com/j8r/crystal-open-simplex-noise
<FromGitter> <tenebrousedge> do you want any help with this game?
<FromGitter> <watzon> I saw girng around not too long ago
<FromGitter> <j8r> @watzon he have probably changed his name
<FromGitter> <j8r> @girng returns a ghost account
<FromGitter> <j8r> ha um, sorry a Gitter autocompletion bug probably
<FromGitter> <j8r> @tenebrousedge Thanks. More or less done, I asked for the map matrix
<FromGitter> <Blacksmoke16> its @ImAHopelessDev_gitlab now
<FromGitter> <j8r> @Blacksmoke16 Right 👍
<FromGitter> <Blacksmoke16> at least on gitter
<FromGitter> <j8r> changing Array to Hash, since I need spare arrays -- quite obviously
travis-ci has joined #crystal-lang
travis-ci has left #crystal-lang [#crystal-lang]
<travis-ci> crystal-lang/crystal#965afe2 (master - Remove obsolete CrystalPath#make_relative_unless_absolute method (#9095)): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/675814840
<FromGitter> <ImAHopelessDev_gitlab> Good morning!!!!!!
<FromGitter> <j8r> Hello @ImAHopelessDev_gitlab , good night!
<FromGitter> <ImAHopelessDev_gitlab> 😆
<FromGitter> <j8r> I plan to use Godot - finally :)
<FromGitter> <j8r> what do you use for communication between client <=> server?
<FromGitter> <ImAHopelessDev_gitlab> StreamPeerTCP class
<FromGitter> <j8r> exactly what I want, thx
<FromGitter> <j8r> And the protocol?
<FromGitter> <j8r> You just send raw data, or use a more advanced format like msgpack/JSON?
<FromGitter> <j8r> Ho there is also PacketPeer https://docs.godotengine.org/en/stable/classes/class_packetpeer.html
<FromGitter> <j8r> I note both for the future
<FromGitter> <tenebrousedge> msgpack seems like a good idea
<FromGitter> <Blacksmoke16> pretty sure he just sends an array of data and uses enum/constants in gotdot to point to correct index
<FromGitter> <Blacksmoke16> array of arrays*
<FromGitter> <tenebrousedge> that seems like a less good idea
<FromGitter> <ImAHopelessDev_gitlab> i do `masterclient.get_utf8_string(masterclient.get_32())` and it returns a string (which i parse into a gdscript dictionary). i don't know if this classifies as raw data, i just use whatever works lol
<FromGitter> <ImAHopelessDev_gitlab> @j8r what are you creating?
<FromGitter> <ImAHopelessDev_gitlab> nvm I scrolled up
<FromGitter> <j8r> noice, I'll problably ask you some other things in the future :)
<FromGitter> <randiaz95> guys.. When will we have Crystal for Windows?
<FromGitter> <randiaz95> I hate oracle more than windows...
<FromGitter> <ImAHopelessDev_gitlab> :D
<FromGitter> <randiaz95> can't be on a virtualbox
<FromGitter> <j8r> Use VMWare or Citrix... lol
<FromGitter> <randiaz95> plus.. If I have to put another curly brace.. I feel like I will throw up lol
<FromGitter> <j8r> or HyperV
<FromGitter> <randiaz95> which do you recommend?
<FromGitter> <randiaz95> lol
<FromGitter> <randiaz95> You gave me 3 hours of researching here buddy.
<FromGitter> <ImAHopelessDev_gitlab> rofl
<FromGitter> <j8r> haha
<FromGitter> <randiaz95> Wait.. Hyper v is a software product that helps people leave windows?
<FromGitter> <randiaz95> Lol!
<FromGitter> <randiaz95> made by windows?!
<FromGitter> <j8r> You could use WSL or Docker (no kidding) if you don't like VirtualBox
<FromGitter> <j8r> or even DualBoot
<FromGitter> <ImAHopelessDev_gitlab> haven't used hyper v since cis class
<FromGitter> <randiaz95> i mean.. I have to configure my screen size every time I start a new virtual box project..
<FromGitter> <ImAHopelessDev_gitlab> i heard WSL2 is a thing and apparently faster file accessing. i wanna try crystal on it but i don't want to break anything that's not broken right now. i got a perfect dev setup
<FromGitter> <randiaz95> interesting..
<FromGitter> <randiaz95> Is this why we haven't created web 3.0?
<FromGitter> <randiaz95> virtualizations of os are too slow?
<FromGitter> <ImAHopelessDev_gitlab> the slower the os experience, slower dev time needed to create something faster. *taps head*
<FromGitter> <Afront> I used to use WSL for Crystal, but it broke for me. Now, I use VirtualBox if I need SSL ⏎ How about QEMU?
<FromGitter> <tenebrousedge> I like docker
<FromGitter> <ImAHopelessDev_gitlab> https://i.gyazo.com/064ec830aa981869d79450fe4fa5ffcd.png :laugh:
<FromGitter> <j8r> haha
<FromGitter> <ImAHopelessDev_gitlab> reminds me of googling crystal shards. and i get that dumb kirby game ROFL
<FromGitter> <randiaz95> where everyone shares a small chunk of data
<FromGitter> <randiaz95> right.. but I mean specifically using client computers as servers for all other computers
<FromGitter> <j8r> virt-manager is pretty good - but Linux only
<FromGitter> <randiaz95> Lol
<FromGitter> <ImAHopelessDev_gitlab> oh sht, it's an actual game https://en.wikipedia.org/wiki/Kirby_64:_The_Crystal_Shards
<FromGitter> <ImAHopelessDev_gitlab> LOOOOOOOL
<FromGitter> <randiaz95> Yup, I am going to push 25 gigs of ram on this virtual box and pray it works.
<FromGitter> <randiaz95> is that a copywrite infringement?
<FromGitter> <randiaz95> lol
<FromGitter> <tenebrousedge> it's even a decent game
<FromGitter> <ImAHopelessDev_gitlab> @randiaz95 HAHAHA
<FromGitter> <randiaz95> I don't know why words, sounds from a human mouth can be owned..
<FromGitter> <ImAHopelessDev_gitlab> @randiaz95 man you always got me dying, i love it
<FromGitter> <tenebrousedge> words can't be owned, but in certain contexts they can be trademarked
<FromGitter> <randiaz95> It's like saying because I built a house with lumber i must give Old Abe a fee.
<FromGitter> <kinxer> Yeah, IP is tricky. I certainly wouldn't want to say that all software (or books or journalism or poetry or word art...) should be totally free because it's composed of the symbols in our writing system(s) (alphabet or otherwise), which shouldn't be owned.
<FromGitter> <kinxer> I know that's an extreme example, but my point is just that there's not a clear line between using words fairly and authentically infringing on intellectual property.
<FromGitter> <kinxer> If people couldn't just lie about their intentions, it'd be easier. :P
<FromGitter> <ImAHopelessDev_gitlab> https://github.com/crystal-lang/crystal/pull/8886 :D
<FromGitter> <ImAHopelessDev_gitlab> Good read for this morning
<FromGitter> <randiaz95> I think its just hipocritical... Human capital doesn't work the same for all instances.
<FromGitter> <tenebrousedge> https://founders.archives.gov/documents/Jefferson/03-06-02-0322 ⏎ good read, starting from "it has been pretended by some"
<FromGitter> <kinxer> Thanks for sharing, @tenebrousedge. I'll admit I've lost a lost of respect for Jefferson over the last few years as I've learned more about him, but he was undoubtedly an excellent writer and provoking thinker. His insistence on declarations of the rights of citizens in the nascent US (and his home state of Virginia, where I'm from) was, I think, one of his greatest contributions to the long-term health of the
<FromGitter> ... nation.
<FromGitter> <randiaz95> Does anyone know a github repo with an example of basic session auth in crystal?
<FromGitter> <randiaz95> I feel like my implementation has many copies of strings that are not good,.
Deuns has joined #crystal-lang
<Deuns> hey!
<FromGitter> <randiaz95> hi
<FromGitter> <ImAHopelessDev_gitlab> hi
<FromGitter> <j8r> @randiaz95 You are using cookies?
<FromGitter> <j8r> I implemented one
<FromGitter> <j8r> the cookie store a random ID
<FromGitter> <j8r> the back-end has a Hash, with the ID as a key and sensitive info as value
<FromGitter> <Blacksmoke16> in the db?
<FromGitter> <j8r> no, in memory
<FromGitter> <j8r> it could be on a DB like Redis
<FromGitter> <randiaz95> Session cookies
<FromGitter> <ImAHopelessDev_gitlab> yum
<FromGitter> <watzon> Chocolate chip session cookies?
<FromGitter> <Blacksmoke16> server rendered site i assume?
<FromGitter> <ImAHopelessDev_gitlab> i love hijacking cookies with js, wait, eating
<FromGitter> <j8r> How can we create session cookie in Crystal? https://crystal-lang.org/api/master/HTTP/Cookie.html
<FromGitter> <Blacksmoke16> wouldnt you just create and return one with the response from the signin request?
<FromGitter> <j8r> I wish to have a generic session store library
<FromGitter> <j8r> (Not a pro on cookies)
<FromGitter> <j8r> haa ok ⏎ ⏎ > Unlike other cookies, session cookies do not have an expiration date assigned to them, which is how the browser knows to treat them as session cookies.
<FromGitter> <Blacksmoke16> eya
<FromGitter> <Blacksmoke16> yea
<FromGitter> <j8r> So, I can just not set a expiration date :)
<FromGitter> <ImAHopelessDev_gitlab> In 2025. TCPServer.new will be accessed by NetworkManagementFactory::TCPServer
<FromGitter> <ImAHopelessDev_gitlab> the end is nigh
<FromGitter> <randiaz95> Have you guys heard of super cookies?
<FromGitter> <randiaz95> all fang companies partnered with OS to hide data.
<FromGitter> <randiaz95> kind of like localstorage/localforage
<FromGitter> <ImAHopelessDev_gitlab> nope
<FromGitter> <randiaz95> playing kanye west Amber song while writing scaffolds in amber is a special experience...
<FromGitter> <ImAHopelessDev_gitlab> that it is
<FromGitter> <randiaz95> Ambuuuurrr
<FromGitter> <randiaz95> Ambiiirrr
<FromGitter> <randiaz95> I wish I used ruby when I first started coding... Never knew these command line tools were so powerful
<FromGitter> <randiaz95> WHY DO THEY TEACH JAVA?!?!?!
<FromGitter> <randiaz95> in school!!
<FromGitter> <Daniel-Worrall> because it's more employable
<FromGitter> <j8r> I forgot, i think it was a Math method - how to have the difference between two numbers (negative or positive)
<FromGitter> <randiaz95> lol... We teach Java because it is more employable, and we employ java because it's well taught.
<FromGitter> <randiaz95> circle of life
<FromGitter> <j8r> there is also PHP - we are saved!
<FromGitter> <ImAHopelessDev_gitlab> i never coded java before
<FromGitter> <randiaz95> 1) o
<FromGitter> <tenebrousedge> Java is too ew for me to ever have touched it
<FromGitter> <randiaz95> What turned me off was the three statically typed objects within themselves.
<FromGitter> <randiaz95> it was like a russian doll of monstrosities
<FromGitter> <ImAHopelessDev_gitlab> i saw a tutorial by thechernoproject on youtube, of him doing some user interface with java code, that's about it tho
_ht has quit [Remote host closed the connection]
_ht has joined #crystal-lang
<FromGitter> <randiaz95> buffers should always I MEAN ALWAYS be a parameter of the function.. Not buffer objects or structs.
<FromGitter> <randiaz95> Freaking sadists.
<FromGitter> <j8r> @ImAHopelessDev_gitlab to be host, not sure it is a good idea to write the game in 2 languages
<FromGitter> <j8r> I won't be able to share code
<FromGitter> <ImAHopelessDev_gitlab> i always remember way back when i was younger, i hated installing java to run an app. i think that acted a deterrent throughout my life to not touch it
<FromGitter> <kinxer> I don't particularly love Java, but I think it's unfair to dismiss it as terrible without having used it. I mean, it's fine.
<FromGitter> <kinxer> Not really better than fine, but fine.
<FromGitter> <randiaz95> I used it to write an interpreter for a simpler language
<FromGitter> <randiaz95> it used tons of arrows
<FromGitter> <randiaz95> for data flow and buffers
<FromGitter> <kinxer> The simpler language did?
<FromGitter> <randiaz95> Then i just used python cause life is easier over there.
<FromGitter> <randiaz95> Yep took me 1 minute to create the gui and 1 year to make the interpreter lol
<FromGitter> <randiaz95> Java/C# is useful for Desktop gui apps with their drag and drop functionalities.
<FromGitter> <ImAHopelessDev_gitlab> i'm in m yhappy space now. gdscript and crystal. i don't think i'll ever find something more enjoyable to use
<FromGitter> <stronny> java for desktop apps? oh hell no
<FromGitter> <kinxer> I mean, Java is portable, right? Isn't that its main strength?
<FromGitter> <randiaz95> Portable until you get to ios apps
<FromGitter> <randiaz95> lol
<FromGitter> <j8r> @ImAHopelessDev_gitlab glad to use Crystal at the end https://github.com/godotengine/godot/issues/36060
<FromGitter> <stronny> I work at a place that has a "portable" java desktop app
<FromGitter> <randiaz95> dart is more portable than java
<FromGitter> <stronny> I mean it works, but at what cost
<FromGitter> <stronny> even unity is probably better
<FromGitter> <randiaz95> Also, the reason why I got so good at python was because of the fast bootup time for small scripts and programs.
<FromGitter> <randiaz95> i could trial and error. and also didnt feel like my computer was taking a crap
<FromGitter> <kinxer> I think it probably has the best combination of portability and wide adoption (i.e. inertia and corporate support), with the possible exception of C#.
<FromGitter> <ImAHopelessDev_gitlab> @j8r yeah
<FromGitter> <kinxer> But I've not used C# personally, so I can't say much about that.
<FromGitter> <stronny> where do I even start
<FromGitter> <randiaz95> Sure, C# has better syntax
<FromGitter> <randiaz95> and better package manager
<FromGitter> <kinxer> Lol. I'll prepare myself to be educated.
<FromGitter> <stronny> we package our own jdk with our app
<FromGitter> <ImAHopelessDev_gitlab> i just started watching c# tutorials with winforms last night cause was bored and winforms give me that ui nostalgia
<FromGitter> <ImAHopelessDev_gitlab> c# looks interesting to me
<FromGitter> <stronny> it's by no means openjdk 11 mind you
<FromGitter> <Afront> Welp at first glance, I thought you meant Godot is considering using Crystal over GDScript
<FromGitter> <randiaz95> The premium libraries from microsoft are fire though..
<FromGitter> <randiaz95> like emotion recognition from images within 2 lines of code.
<FromGitter> <ImAHopelessDev_gitlab> @Afront hahah
<FromGitter> <stronny> I am of strong opinion that portable programs are not worth the cost
<FromGitter> <randiaz95> @stronny what do you think about dart?
<FromGitter> <randiaz95> compiles to JS -> native ios & driod
<FromGitter> <stronny> I don't like its syntax
<FromGitter> <randiaz95> droid*
<FromGitter> <stronny> beyond that no idea
<FromGitter> <randiaz95> its syntax is very similar to that of Java
<FromGitter> <stronny> well that's not a good thing =)
<FromGitter> <ImAHopelessDev_gitlab> LOL
<skrzyp> Which service provides pastebin with Crystal highlighting?
<FromGitter> <stronny> carc.in
<skrzyp> good, thanks
<FromGitter> <randiaz95> I like java/ruby/dart because they use intellectually stimulating patterns.
<FromGitter> <stronny> github gists probs
<FromGitter> <randiaz95> oh and scala too
<FromGitter> <ImAHopelessDev_gitlab> "intellectually stimulating"? sounds hot
<FromGitter> <stronny> go full haskell
<FromGitter> <randiaz95> i tried.. and died
<FromGitter> <randiaz95> Haskill
<skrzyp> stronny: oh, but it's meant to running the code, not pasting
<FromGitter> <ImAHopelessDev_gitlab> asterite went to haskell for us
<FromGitter> <ImAHopelessDev_gitlab> we'll be ok
<FromGitter> <stronny> well it does both
<skrzyp> and I clearly don't want to run that code on their machines, for their own good :D
<FromGitter> <kinxer> @stronny What's the better solution for deploying products on different platforms, then? "Robust" build scripts?
<FromGitter> <stronny> factor out common code into a library and write several programs
<FromGitter> <randiaz95> Right.
<FromGitter> <Afront> @randiaz95 what do you think of languages "built on Java" like Groovy and Kotlin?
<FromGitter> <ImAHopelessDev_gitlab> why not just use winforms for cross platform apps? *taps head*
<FromGitter> <randiaz95> I prefer Scala.
<FromGitter> <ImAHopelessDev_gitlab> I prefer Rust.
<FromGitter> <randiaz95> not in general lol.. I prefer Crystal right now
<FromGitter> <randiaz95> much more than Go for internet systemd services
<FromGitter> <ImAHopelessDev_gitlab> haha
<FromGitter> <randiaz95> and I thought GO was going to be the best IOT play of 20s
<FromGitter> <Afront> lol I see
<FromGitter> <Afront> It might be Rust
<FromGitter> <randiaz95> But at the end of the day; scripting syntax allows you to gather complex thoughts in a quicker manner
<FromGitter> <ImAHopelessDev_gitlab> YES
<FromGitter> <stronny> if you need it fast
<FromGitter> <randiaz95> c styled syntax forces you to think of i:=0;i<len(x);i++
<FromGitter> <stronny> if you need it correct go static
<FromGitter> <randiaz95> Well, Crystal does all that work
<FromGitter> <randiaz95> Without being a douche
<FromGitter> <randiaz95> and has map/filter/reduce built in
<FromGitter> <randiaz95> to iterables.
<FromGitter> <randiaz95> Crystal is like that hot girl that also has a great positive attitude
<FromGitter> <randiaz95> Go is like that hot girl with a mean attitude that asks what you want to eat but she really only eats keto
<FromGitter> <stronny> just don't bring her down to trenches
<FromGitter> <stronny> both of them
<FromGitter> <ImAHopelessDev_gitlab> i'll take things i'll never experience irl for $500, alex
<FromGitter> <randiaz95> Wut u mean undeaD?
<FromGitter> <randiaz95> 100k requests per second?
<FromGitter> <stronny> more like months of uptime
<FromGitter> <randiaz95> ah.. True..
<skrzyp> sp finally I used gists for that and their highlighting works well
<skrzyp> so*
<FromGitter> <randiaz95> Java would likely work
<FromGitter> <randiaz95> 2 years from now
<skrzyp> ok, anyways
<FromGitter> <randiaz95> unless Oracle starts charging
<FromGitter> <randiaz95> I might just rewrite my etl pipeline for work in crystal... Too damn slow.
<skrzyp> Can I somehow embed other files during building a Crystal binary? Like, embedding ECR templates stored in other files
<FromGitter> <randiaz95> Do you mean other crystal files or folders/text files?
<FromGitter> <stronny> like "resources"?
<FromGitter> <randiaz95> Just have resources created in a folder somewhre
<skrzyp> yes, something like that
<FromGitter> <stronny> I think forum has a topic
<FromGitter> <randiaz95> like /Documents/appname/characters.sqlite
<FromGitter> <randiaz95> for your mmorpg
<FromGitter> <stronny> but I would advise against
<FromGitter> <randiaz95> Shouldn't it go in Programs folder?
<FromGitter> <randiaz95> for windows?
<skrzyp> in this case it's just only for ECR templates for my tiny backend, so I could deploy it by single binary
<FromGitter> <kinxer> @ImAHopelessDev_gitlab @j8r How would y'all feel about a project with the goal of creating GDNative bindings in Crystal? So you could write client game logic in Crystal?
<FromGitter> <stronny> why do you avoid packaging?
<FromGitter> <stronny> it's not that hard
<FromGitter> <randiaz95> Just failed to linuxbrew install crystal-lang :'(
<FromGitter> <randiaz95> Crystal is like an immature Naruto
<FromGitter> <randiaz95> I want hokage Naruto already.
<FromGitter> <kinxer> You have a way with unlikely metaphors, @randiaz95.
<skrzyp> because I want it for my personal use for now, and in general I don't think I need a package for single binary which doesn't do anything within the system state
<FromGitter> <stronny> you already need templates
<skrzyp> only a few
<skrzyp> hm
<FromGitter> <stronny> probs gonna need js later
<FromGitter> <stronny> and the like
<skrzyp> of course not
<FromGitter> <j8r> @kinxer I thought about it, good idea but not yet: ⏎ ⏎ 1) waiting for Windows support ⏎ 2) maybe simpler way to generate bindings (https://github.com/crystal-lang/crystal/pull/8336) [https://gitter.im/crystal-lang/crystal?at=5e98a84aa1284c4f209428bf]
<skrzyp> I mean, I try to avoid clientside js at all costs
<skrzyp> and it's not needed in this particular applicant
<FromGitter> <j8r> I'll give C# a try
<FromGitter> <stronny> what's the target distro? debian?
<FromGitter> <randiaz95> Ubuntu
<FromGitter> <randiaz95> I may need to use the curl
<FromGitter> <randiaz95> command instead
<FromGitter> <kinxer> @j8r That makes sense. I was waiting for multithreading before even thinking about an attempt, but we sort of have that now.
<skrzyp> hm, that might sound weird, but creating a macro which will render ECRs as variables with heredocs might be some way of doing this
<FromGitter> <randiaz95> I have learned so much from simply creating an http server in like every language
<FromGitter> <stronny> basically define a constant with your static content inside
<FromGitter> <randiaz95> because every language has different perespectives.
<FromGitter> <stronny> instead of reading from a file
<skrzyp> yeah, that's what I was thinking
<skrzyp> and let macro fill that constant with file contents at build time
<FromGitter> <stronny> `ECR = {% read_file tpl.ecr %}` or something
<FromGitter> <j8r> Indeed, C# is more mature on this side @kinxer ⏎ mature Windows and multi-threading for a game is very good to have
<skrzyp> just like that, thanks for confirming my thoughts anyways :)
<FromGitter> <kinxer> For Godot, I think the other big option is Rust.
<FromGitter> <j8r> maybe, not sure
<FromGitter> <j8r> Not sure if predictive performance and low level is as important in games
<FromGitter> <j8r> even safety
<FromGitter> <ImAHopelessDev_gitlab> i tried Rust i just cannto for the life of me wrap my head around that syntax. i don't know what it is
<FromGitter> <randiaz95> yep
<FromGitter> <randiaz95> the !@#$
<FromGitter> <kinxer> Yeah, I found it difficult, too.
<FromGitter> <randiaz95> like in ruby too
<FromGitter> <randiaz95> Symbols have to be explained.
<FromGitter> <randiaz95> Otherwise us didacts will not understand.
<FromGitter> <randiaz95> << and method? are intuitive I guess..
<FromGitter> <ImAHopelessDev_gitlab> nty
<FromGitter> <Afront> I don't know... I found the syntax of Ruby (and I guess Crystal) to be very intuitive compared to a lot of languages
<oprypin> why is there all this talk about 1.0 - i'm actually getting worried
<hightower2> Hey folks, I just compared running String#index in a long file with the argument being both a string and regex. For some reason, the regex search is 5 times faster... what explanation for this am I missing?
<oprypin> hightower2, well libpcre is pretty epic, i dont know.
<skrzyp> oprypin: I quite don't know, it's just a number
<oprypin> "ok we are officially boring now"
<skrzyp> but I really don't know what's left on todolist to add into Crystal in terms of language specs, from what I read in the docs it has everything it need to have
<skrzyp> maybe I'm missing something
<FromGitter> <stronny> string search is pure crystal, regex is probably libpcre
<hightower2> stronny: yes probably, but I was expecting that a literal comparison would always be faster
<FromGitter> <stronny> always? no
<oprypin> pcre ends up being a literal comparison
<FromGitter> <naqvis> For String replace/retrieve https://arxiv.org/abs/1711.00046 states its faster than RegEx
<FromGitter> <naqvis> this is O(N) while RegEx is O(MxN)
<FromGitter> <naqvis> haven't done any tests
<FromGitter> <naqvis> there is reference implementation in Python and few other languages has reference implementation
<FromGitter> <ImAHopelessDev_gitlab> > haven't done any tests ⏎ ⏎ /has entered the chat
<FromGitter> <naqvis> welcome back girng lol
<FromGitter> <ImAHopelessDev_gitlab> :laugh;
travis-ci has joined #crystal-lang
<travis-ci> crystal-lang/crystal#642ae96 (master - Improve debugging support (#8538)): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/675884091
travis-ci has left #crystal-lang [#crystal-lang]
<hightower2> Hey folks, how can I create a string which points to a substring of another string, without actually copying the content
<FromGitter> <stronny> hmmm
<hightower2> Like, string2 to be range [0...1000] of string1
<FromGitter> <stronny> doesn't seem so
<FromGitter> <stronny> monkey patch String
<FromGitter> <tenebrousedge> can you just pass around a lambda that returns that?
<FromGitter> <tenebrousedge> or a pointer?
<FromGitter> <stronny> you can get a subslice without copying, String.new always makes a copy
<hightower2> I mean the reason why I need is is while searching functions have starting offset they don't have end offset
<hightower2> So I am thinking the best way to limit the end would be by pointing a string to a portion of original string data
<FromGitter> <stronny> why not `strstr`?
<FromGitter> <stronny> or `wcsstr` even
<oprypin> hightower2, no it's not possible for a Crystal string
<oprypin> u probably could pull it off *with* damage to the larger string
<oprypin> let me test my skill by guessing
<hightower2> oprypin, do try please. I could live with flipping individual bytes to zero and back to their original value if that's what it entails.
<oprypin> `s = "foo bar"; s.as(Int32*).value = 3; p! s.includes?("a") #=> false`
<oprypin> ayy invalid memory access
<FromGitter> <stronny> what do you mean `= 3` ?
<oprypin> hold on..
<oprypin> there we go
<oprypin> `s = "foo bar".chars.join; (s.as(Int32*) + 1).value = 3; p! s.includes?("a") #=> false`
<FromGitter> <stronny> ooh, `str_header = str.as({Int32, Int32, Int32}*)`
<oprypin> yes thanks, i couldnt find that myself
<oprypin> forgout about type id
<oprypin> also string literals go into read0only memory so i had to make a dynamic dup
<FromGitter> <stronny> anyway, I'd just go with `LibC.strstr`
<oprypin> what does that solve
<FromGitter> <stronny> a quick substring search
<hightower2> Yes no the need I have is to do a search within a limited region of the string, and also based on my tests for searching within strings up to 103 chars the substring search is faster, while for those longer regex search is faster.
<hightower2> so I probably couldn't help myself with strstr for both of those reasons
<FromGitter> <tenebrousedge> is performance pretty critical here?
<oprypin> hightower2, well it's possible that strstr faster than both, im not sure how that refutes it
<oprypin> i wouldnt use strstr for *other* reasons but whatever
<FromGitter> <stronny> well you can easily have a start offset with strstr
<hightower2> tenebrousedge yes, that's the point of the task. well, both performance of search itself as well as not unnecessarily using more memory just to contain subsets of other strings
<FromGitter> <stronny> and ig you don't mind flipping bytes to/from \0 end offset as well
<hightower2> oprypin, oh you think? I thought String#index with string argument boiled down to something like that in itself... but maybe... good suggestion, I'll do a comparison just to see
<hightower2> ok... great, good ideas, thanks for the discussion as always
<FromGitter> <stronny> anytime
<oprypin> hightower2, u can flip a byte to 0 for strstr the same way that i showed but with `+3+n` instead of `+1` that i used
<FromGitter> <stronny> but not as (Int32*)
<oprypin> oh ye nvm
<oprypin> hightower2, much better to start with https://crystal-lang.org/api/0.34.0/String.html#to_unsafe:Pointer(UInt8)-instance-method though
<oprypin> (it could still be pointing to readonly memory though if it's from a string literal)
<FromGitter> <stronny> or maybe to_slice
<oprypin> yea. well same stuff
<FromGitter> <stronny> yeah, subtle diffs
_ht has quit [Remote host closed the connection]
_ht has joined #crystal-lang
<hightower2> docs say slice is read-only so would have to change the byte beforehand. Also maybe its description could be improved as it says "Returns the underlying bytes" with no indication if it's done with a pointer or copy
<FromGitter> <stronny> look at the source =)
<oprypin> hightower2, well no, i think "underlying" quite strongly implies no copy
<FromGitter> <stronny> read-only is a problem if you modify through slice
<oprypin> hightower2, but indeed look at the source code
<FromGitter> <stronny> if you then use slice's pointer it's no longer r/o iiuc
<oprypin> `Slice.new(to_unsafe, bytesize, read_only: true)`
<oprypin> just drop the readonly part
<FromGitter> <stronny> probs the easiest way, yes
<oprypin> but this is done for important safety reasons. as i said, the memory *can* actually be readonly, you'll get a segfault then
<FromGitter> <stronny> get a custom SIGSEGV trap!
<hightower2> haha
<oprypin> it's important that the string you're modifying is not directly from a string literal
<hightower2> oprypin, yes, it's not
<oprypin> well good then. to_unsafe, strstr and off u go
<oprypin> post benchmarks :>
17WAA10OT has joined #crystal-lang
17WAA10OT has left #crystal-lang [#crystal-lang]
<17WAA10OT> crystal-lang/crystal#3702a55 (master - Drop top-level parallel macro (#9097)): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/675900897
<hightower2> will do. The results I have now is that String#index(String) is faster up to original string of size 103 if regex object is already created. If Regex.new is called as part of every String#index(regex), then the break point is at around 550 chars
<oprypin> aaaaaaaa why is github search so garbage
<FromGitter> <naqvis> reason is simple, because their search service is not written in Crystal 😆
<oprypin> sigh
<hightower2> maybe the values differ though... something like this: https://play.crystal-lang.org/#/r/8whw
<sorcus> naqvis: :-D
<hightower2> Is this test representative? https://play.crystal-lang.org/#/r/8wi0
<oprypin> hightower2, s/UInt8/Char/
<oprypin> hightower2, wait why does this have warmup and calculation set to 1, does it mean it does it only once/???
<hightower2> no it's in seconds
<oprypin> oh ok
<oprypin> should be 1.seconfs
<oprypin> really owrrisome for thatcrystal implenentation
<hightower2> no luck with Char, it tells me... argument #1 of 'C#strstr' must be Pointer(..type that I put..), not String (nor Pointer(UInt8) returned by 'String#to_unsafe')
<oprypin> hightower2, ooh. should be `lib LibC` for that to work (or `LibC::Char`) https://play.crystal-lang.org/#/r/8wi6
<hightower2> ah indeed, thanks
<hightower2> ok, nice... so, now I have some ballpark figures and comparisons to work with... thanks folks, the discussion was insightful
<FromGitter> <tenebrousedge> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e98c4512ff88975b4251055]
ur5us has joined #crystal-lang
_ht has quit [Quit: _ht]
<hightower2> supercool
sagax has quit [Remote host closed the connection]
zorp has quit [Ping timeout: 265 seconds]
<FromGitter> <j8r> StaticArray is too slow too compile, horrible :(
<FromGitter> <Blacksmoke16> @paulcsmith I could handle those PRs in https://github.com/crystal-lang/crystal/pull/9092 if you'd like
<FromGitter> <Blacksmoke16> nil one would probably want to be considered empty
sagax has joined #crystal-lang
zorp has joined #crystal-lang
renich has joined #crystal-lang
<FromGitter> <paulcsmith> Oh my bad! I did not see yours. I will close to the `to_json` one I did. Thanks for the heads up @Blacksmoke16
<FromGitter> <Blacksmoke16> Np, I'll add nil to the empty method but leave the rest to your PR
<FromGitter> <paulcsmith> Sounds good. Good teamwork
renich has quit [Quit: renich]
renich has joined #crystal-lang
<hightower2> Hey I see Time.parse() requires the format to be specified. Are there any methods or shards you know of which can autodetect the format?
<FromGitter> <Blacksmoke16> are you not getting a standardized format?
<FromGitter> <Blacksmoke16> parsing an arbitrary string into time is prob not trivial
<hightower2> yes, I'm aware. But I think I recall Ruby having a method which figures out the format on its own to some extent.
<hightower2> (but yes, I am getting dates in arbitrary format)
<FromGitter> <Blacksmoke16> ouch
<FromGitter> <Blacksmoke16> where are they coming from?
<hightower2> web pages and such
<hightower2> (the pinnacle of free-form input :)
<FromGitter> <Blacksmoke16> rip
<FromGitter> <straight-shoota> oprypin, I'm not sure you can view my response, I have hidden both our comments because they're resolved. I mean `C:\crystal`
<hightower2> Blacksmoke16 but as I recall, https://docs.ruby-lang.org/en/master/Date.html#method-c-parse does have a Ruby algo for auto-determining the input format
<oprypin> straight-shoota, yes i can view them and also by email notification. and yes, i think this is the perfect way to handle that interaction.
<oprypin> reply, edit, then hide both
<oprypin> also i suppose you're right. there's one big mention of it at the beginning that should apply to the rest. but it's *too* implicit
<FromGitter> <straight-shoota> great :P
<FromGitter> <straight-shoota> hightower2 ⏎ ⏎ > Are there any methods or shards you know of which can autodetect the format? ⏎ ⏎ Not that I'm aware of. Would be great to have, though. And I'd expect this can be implemented with a very high success rate. [https://gitter.im/crystal-lang/crystal?at=5e98eefae920022432ad5401]
<oprypin> ah yes good luck determining "09/09/09"
<oprypin> umm i should rather say "07/08/09"
<oprypin> cuz that previous one is indeed easy 😂