ChanServ changed the topic of #crystal-lang to: The Crystal programming language | | Fund Crystal's development: | GH: | Docs: | Gitter:
mfiano has joined #crystal-lang
<mfiano> Hello
<FromGitter> <Blacksmoke16> o/
<mfiano> What kind of GC does Crystal have?
<oprypin> mfiano, boehm / bdwgc
<oprypin> i think they call it "conservative"?
<mfiano> Ah, so possibly suitable for soft real-time applications, then.
<hightower3> Can a file being compiled somehow reference the directory where it is located? I have and it needs to load "../something.json" relative to the directory where it itself is located.
<oprypin> hightower3, yea just __DIR__
<hightower3> I did so and thought it worked, but it's giving me errors now... I thought it worked previously because I happened to run the compile from the right dir... let me review the error in more detail now
<hightower3> ah it works of course, I've overriden the value later... thanks for pointing it out
<mfiano> Are there any other published books other than "Programming Crystal"?
<oprypin> i dont think so.
<FromGitter> <Blacksmoke16> I'd read the reference material if you haven't already
<FromGitter> <> straight-shoota: we'll need another Debian repository change haha
<FromGitter> <> I didn't see an SaaS solution, only on-premise
<FromGitter> <> That's interesting, that's the opposite of what Atlassian did
<straight-shoota> yeah, I've seen that yesterday
<straight-shoota> I'm not involved in the package release process, though
richbridger has joined #crystal-lang
aquijoule__ has quit [Ping timeout: 264 seconds]
<FromGitter> <> Yes that's Brian, I pinged him here – should be busy
<FromGitter> <> I will look to alternatives, I used it too in the past
<FromGitter> <> Of course: ⏎ cc @bcardiff
f1refly has joined #crystal-lang
f1reflyylmao has quit [Ping timeout: 258 seconds]
<FromGitter> <mattrberry> @asterite In case you're ever curious, here's a branch that segfaults for me before the first frame when running Pokemon Emerald. Updating the two instances of `Proc(Void)` to `Proc(Nil)` in prevents this segfault from happening
avane has quit [Quit: ZNC -]
avane has joined #crystal-lang
<FromGitter> <mfiano> Just wanted to say I'm new here, and really enjoying the simplicity of the language.
mfiano has left #crystal-lang ["WeeChat 2.9"]
<FromGitter> <mfiano> I've been married to a complicated (yet powerful and expressive) language for a couple decades. Currently evaluating whether Crystal is a good fit for my domain, and worth porting hundreds of thousands of lines. Even if not, I will probably end up using it for other tasks.
<FromGitter> <Blacksmoke16> Good to hear. We'd be happy to help with any questions and such
<FromGitter> <mfiano> Not really a question, but in playing around with the compiler any program compiled with `--lto=thin` fails with a ton of `Invalid memory access (signal 11)`. Is this expected?
<FromGitter> <Blacksmoke16> probably not
<FromGitter> <mfiano> Also another oddity I discovered is compiling any program that doesn't use concurrency at all with `-Dpreview_mt` performs better. I wish I knew why :)
<FromGitter> <Blacksmoke16> is it possible it's using it under the hood
<FromGitter> <mfiano> it's a single recursive fibonacci function
<FromGitter> <Blacksmoke16> ah, wonder if its some LLVM optimization? :shrug:
<FromGitter> <mfiano> Eh, I'm not complaining, just exploring.
* FromGitter * mfiano is not used to LLVM or ALGOL-derived languages at all.
<FromGitter> <djberg96> a class type can't be scoped?
<FromGitter> <djberg96> seems I can do `SomeClass(A)` but not `SomeClass(A::B)`
<FromGitter> <Blacksmoke16> correct, the former is just defining a generic arg named `A`, there are some issues regarding expanding upon it, i.e. to restrict the types that *could* be used, but its not a thing yet
<FromGitter> <Blacksmoke16> currently can do something like that by using a macro in the `initialize` method
<FromGitter> <Blacksmoke16> but not as clean as it would be on the lang level ofc
<FromGitter> <djberg96> ok, thanks
<FromGitter> <Blacksmoke16> minor but you naming convention is usually `lib LibC`
<FromGitter> <djberg96> ah, i think i was just using an example from the book, but i'll use that if that's the convention
<FromGitter> <Blacksmoke16> and could define the array like `StaticArray(LibC::Char, 256)`,
<FromGitter> <Blacksmoke16> or looks like `LibC::Char[256]` would also work
aquijoule_ has joined #crystal-lang
<FromGitter> <djberg96> `undefined constant LibC::Char`
<FromGitter> <Blacksmoke16> oh, try moving it out of your custom namespace
<FromGitter> <Blacksmoke16> or try `::LibC::Char`
<FromGitter> <djberg96> yep, that works
<FromGitter> <Blacksmoke16> 👍
f1refly has quit [Ping timeout: 276 seconds]
richbridger has quit [Ping timeout: 276 seconds]
f1refly has joined #crystal-lang
<FromGitter> <djberg96> i don't suppose there's an easier way to convert a `LibC::Char[256]` to a string, is there?
<FromGitter> <djberg96> i was hoping `.to_s`, but that doesn't do what i hoped
<FromGitter> <Blacksmoke16> uhh
<FromGitter> <Blacksmoke16> ` cstruct.char_arr.to_unsafe`
<FromGitter> <Blacksmoke16> something like that?
<FromGitter> <Blacksmoke16> uses the overload
<FromGitter> <djberg96> cool, thanks
<FromGitter> <Blacksmoke16> nice
<FromGitter> <djberg96> thanks, might have to start converting some of my ruby libs :)
<FromGitter> <djberg96> (or maybe get you to bake this stuff into the `System` class)
_whitelogger has joined #crystal-lang
<FromGitter> <mattrberry> My code has gotten significantly grosser looking, but it's worth it for the speed.. Templating a bunch of functions at compile-time... ⏎ ⏎ ```code paste, see link``` []
<FromGitter> <mattrberry> Does the Crystal formatter have any support for formatting inside of macros, or is that left out intentionally?
<FromGitter> <mattrberry> Oops, minor copy-paste error on the rd check
<FromGitter> <mfiano> Does Crystal have syntax for sealing a class?
postmodern has joined #crystal-lang
_ht has joined #crystal-lang
<FromGitter> <> What would it mean?
<FromGitter> <mfiano> Some languages allow "sealing" a class or method, which means that they can only be extended in the same source file only. Extended meaning sub-classing or adding new type-restricted methods of the same name.
MasterdonX has joined #crystal-lang
<FromGitter> <mfiano> It's like "finalizing" a class, but only applying to code external to the current file.
<FromGitter> <> Hmm ok, I don't know anything similar for Crystal
MasterdonX has quit [K-Lined]
<FromGitter> <asterite> Michael Fiano: what complicated yet powerful and expressive language? Just curious
<FromGitter> <asterite> Matthew: macros just operate at the text level, that's why they don't get formatted
<FromGitter> <asterite> Michael Fiano: I proposed Sealed classes like ten times in the past. I would like to have such a feature but others seem to lot find it useful or understand the purpose. In the meantime many other languages support that.
<FromGitter> <asterite> I'm guessing now that other language is Scala. Haskell is also a possibility but less probable.
postmodern has quit [Quit: Leaving]
<FromGitter> <asterite> Ah, no, Haskell doesn't have a Sealed thing
<FromGitter> <naqvis> yeah Scala, Kotlin have this feature and now Java15 also introduce sealed class/interface feature
<FromGitter> <mfiano> @asterite Common Lisp
deavmi has quit [Quit: Eish! Load shedding.]
<FromGitter> <mfiano> I have used it exclusively for the last 20 years or so, but I got the idea from Scala and Kotlin (I'm familiar with them and thought it was a pretty useful feature, but haven't really used them).
<FromGitter> <mfiano> Doubt there are any other Lispers around here; we seem to be a rare breed :) I am currently evaluating Crystal as a target to switch to for professional game engine development in our small studio. We have lots of code, and while Lisp is a great language with near C performance and flexibility, sometimes it gets in the way of game development, sacrificing performance and code clarity. It also suffers from us
<FromGitter> ... having to implement lots of things ourselves, because of the lack of community and existing libraries being somewhat poor. ⏎ ⏎ Crystal seems very nice so far, but still experimenting to see if it sticks with me. I will say it is much more pleasant to work with than Nim, which is highly unstable and tries to do too much (I t ... []
deavmi has joined #crystal-lang
<FromGitter> <> @mfiano: what do you use for broad phase collision detection?
<FromGitter> <mfiano> Currently, just a BVH of spheres and OBBs, created automatically from an octree. Collision detection is one thing we have that works, but needs a lot more work.
<FromGitter> <> It is a complex topic for sure
<FromGitter> <> For now I did only a basic one based on a grid
aquijoule_ has quit [Ping timeout: 256 seconds]
<FromGitter> <> Did you Game Engine has an UI like Godot?
<FromGitter> <> Or it is focused on pure server side
<FromGitter> <mfiano> The thing with Lisp, is you don't need a UI, since it is all interactive already. You can compile individual functions, variables, and DSLs and see changes on the fly. For example, we have a DSL for shader functions, so we can just tell our editor to update them as the game is running. I sent you a message on Matrix though, as to keep this channel more on-topic :)
<FromGitter> <> Thanks, sure
<FromGitter> <> Because UI on Crystal for Windows may be not ideal
deavmi has quit [Quit: Eish! Load shedding.]
deavmi has joined #crystal-lang
<FromGitter> <> why would that be? ui is actually in a better state that anything else
<FromGitter> <> Maybe, but I doubt it is production-ready
<FromGitter> <> At least with no ui, it could run on Docker for Windows or WSL
ua_ has joined #crystal-lang
ua has quit [Ping timeout: 264 seconds]
richbridger has joined #crystal-lang
hightower3 has quit [Ping timeout: 276 seconds]
<FromGitter> <szTheory_gitlab> How do you do dynamic dispatch like Ruby's Object#public_send ? I'm trying to port this code: `receiver.__send__(method, *extract_params(scanner))`
<FromGitter> <Blacksmoke16> `#send` doesn't exist in Crystal. You'd prob be best off refactoring things so you dont need that
<FromGitter> <szTheory_gitlab> I see, thanks. So you have to know the method names at compile time, can't do dynamic dispatch?
<FromGitter> <Blacksmoke16> there are some workarounds, but in the end it would have to call the actual method
<FromGitter> <Blacksmoke16> like could do something like ⏎ ⏎ `````` []
<FromGitter> <Blacksmoke16> ```case method_name ⏎ when "foo" then ⏎ when "bar" then ⏎ end``` []
<FromGitter> <szTheory_gitlab> OK yup that's what I was thinking too with a case statement
<straight-shoota> it would help if you could tell us about your use case
<FromGitter> <Blacksmoke16> or something along those lines, but ofc there isnt any compile time saftey on if you pass an invalid method name, and the return type would be a big union of every method
<straight-shoota> not just how to do X in Crystal, when X is just a solution that works in Ruby
<FromGitter> <Blacksmoke16> ^
<FromGitter> <> Well, it *is* possible:
<FromGitter> <> but you're really better off using a case/when
<FromGitter> <> it is even possible to generate when conditions with a macro
<FromGitter> <Blacksmoke16> prob yea, why wouldnt it?
<FromGitter> <szTheory_gitlab> Makes sense. I'm porting htmlbeautifier to Crystal, and the specs have code like this ⏎ ⏎ ```code paste, see link``` []
<FromGitter> <Blacksmoke16> sounds like you could use an enum
<FromGitter> <szTheory_gitlab> That is in ⏎ ⏎ ```module HtmlBeautifier ⏎ class HtmlParser < Parser``` []
<FromGitter> <Blacksmoke16> with a method called `def regex` when does `case/in` on each member
<straight-shoota> Or just use procs
<FromGitter> <> it is all possible, with macro, to iterate over methods of a given object
<FromGitter> <> if what you want is to test all methods of an object
<FromGitter> <szTheory_gitlab> I'm thinking that instead of having these blocks in the specs that assign to `@maps`: ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ Read from `def regex` like George is saying. Then make a subclass of `HtmlBeautifier::Parser` that overrides `#regex` as needed for each spec []
<straight-shoota> seems way too complex to me
<straight-shoota> specs are supposed to be simple :D
<FromGitter> <Blacksmoke16> oh this is a spec
<FromGitter> <Blacksmoke16> yea id go with something simple, not really worth the effort
<FromGitter> <> not sure why there are regexes?
<FromGitter> <HertzDevil> tbf i don't think there are any real use cases for `send` in ruby either
<straight-shoota> +1
<FromGitter> <HertzDevil> seems like a consequence of its extremely dynamic nature rather than an intrinsically desirable feature
<FromGitter> <> like eval?
<straight-shoota> yep
<FromGitter> <HertzDevil> `send` makes more sense in lua for example where no language-level oop exists and you have to roll your own
<FromGitter> <szTheory_gitlab> Well I am trying to port this library from Ruby to Crystal without altering it's behavior. I'm also still learning Crystal. I was thinking the easiest way is to just port it 1:1 as much as possible from Ruby to Crystal with the specs still passing. Then I can start refactoring to clean up the code and make it more Crystal like. This is still my first pass so I'm hoping to alter things as little as
<FromGitter> ... possible while still keeping the specs passing
<straight-shoota> that's definitely a good idea and should work for the most part
<FromGitter> <Blacksmoke16> i means as long as you make it so the specs are the same the design aspect of that doesnt really matter as much
<FromGitter> <> ok, so you could try my library then - which is not recommended but could help in your refactoring
<FromGitter> <Blacksmoke16> compared to the actual lib code
<straight-shoota> Can you give a linkt to the Ruby code?
<FromGitter> <szTheory_gitlab>
<FromGitter> <szTheory_gitlab> Thanks some great suggestions. One last thing- is there already an opinionated HTML formatted for erb/eex/ecr written in Crystal? The Ruby version is too slow and I couldn't find any existing solution which is why I'm porting this
<FromGitter> <szTheory_gitlab> formatter*
<FromGitter> <szTheory_gitlab> My ultimate goal is to hook this up to a VS Code extension so people in Ruby/Elixir/Crystal can all take advantage of it in the editor on save
<FromGitter> <> @szTheory_gitlab:
<FromGitter> <> the thing to remember is the macro for loop to emulate the #send feature
<FromGitter> <szTheory_gitlab> Awesome thanks!
deavmi has quit [Ping timeout: 272 seconds]
deavmi has joined #crystal-lang
DeBot has quit [Quit: Crystal IRC]
asterite has quit [Quit: Bye]
jhass has quit [Quit: Bye]
straight-shoota has quit [Quit: ZNC 1.8.2 -]
DeBot has joined #crystal-lang
asterite has joined #crystal-lang
straight-shoota has joined #crystal-lang
jhass has joined #crystal-lang
<FromGitter> <Daniel-Worrall> @szTheory_gitlab FWIW if you were porting it to use, I have js-beautify working through duktape here
alexherbo2 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 272 seconds]
<FromGitter> <djberg96> I made a thing:
<FromGitter> <djberg96> (For now I just created a branch on an existing repo that was originally for Ruby)
<FromGitter> <djberg96> how do i get a site like to pick it up?
<FromGitter> <> @djberg96 main branch should contain shard.yml, then everything picks it up. other branches are not used for anything
<FromGitter> <djberg96> ah, can't do that, it's a repurposed repo
<FromGitter> <djberg96> i have too many already, i was trying to avoid making more
<FromGitter> <> don't repurpose
<FromGitter> <> No need to, many branches is not better
<FromGitter> <> yea actually there's 0 advantage to many branches over many repos
<oprypin> funny thing is, you can even have it as one repo locally but many repos on github
<oprypin> how did i just type this over 2 different chat methods 😩
<FromGitter> <djberg96> there's no advantage one way or another
<FromGitter> <djberg96> it's just a workflow
<oprypin> umm i think we see one advantage
<oprypin> that is you can actually publish a library for crystal
<FromGitter> <> It confuse people, I look at the readme. Plus, no history shared
<FromGitter> <> Better having a monorepo then
<FromGitter> <> Or use GitLab, you can group repository in one
<oprypin> every instance where i had multiple unrelated branches in one repo eventually i ended up merging
<FromGitter> <> And, how would you handle tags in the multi-branch way?
<FromGitter> <> oprypin: except gh-pages ;)
<FromGitter> <Blacksmoke16> you can have tags based on diff branches fwiw
<FromGitter> <djberg96> as for shared history, you can always create an orphan branch (which I didn't do, oops)
<oprypin> djberg96, of course you can but we're saying that there's no advantage then even more so
<FromGitter> <> @Blacksmoke16: I know, but you can't have a same tag
<FromGitter> <> Say, I wan't to release the Ruby lib in 1.0, and same for Crystal
<FromGitter> <Blacksmoke16> ah yea fair point
<FromGitter> <> @djberg96: note that you're monkey patching the stdlib – `System` already exists
<FromGitter> <djberg96> yes. i know.
<FromGitter> <> If I use your lib in my code, people may think I use the stdlib
<FromGitter> <> (If not careful)
<FromGitter> <djberg96> i didn't see anything like Ruby refinements, so here we are
<FromGitter> <djberg96> @Blacksmoke16 yeah, it's probably a bad idea, i never really tried one repo/multiple languages, was partly curious to see if/how git could handle it
<FromGitter> <djberg96> just googling about, it seems the argument for monorepos is mainly aimed at large organizations and/or large code bases
<raz> monorepo is the way to go unless you like pain. lots of pain.
_ht has quit [Remote host closed the connection]
alexherbo2 has joined #crystal-lang
sorcus has quit [Quit: WeeChat 3.0]
sorcus has joined #crystal-lang
alexherbo26 has joined #crystal-lang
alexherbo2 has quit [Read error: Connection reset by peer]
alexherbo26 is now known as alexherbo2
hamoko[m] has joined #crystal-lang
<FromGitter> <wyhaines> @djberg96 You were, I think , the first person that I really had conversations with about Ruby back in those early days when we were both learning it, and here you are now! The world is small. :)
alexherbo28 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 246 seconds]
alexherbo28 is now known as alexherbo2
alexherbo2 has quit [Ping timeout: 256 seconds]
<FromGitter> <djberg96> howdy Kirk!
<FromGitter> <djberg96> I'm like a bad penny ;)