ChanServ changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | Fund Crystal's development: https://crystal-lang.org/sponsors | GH: https://github.com/crystal-lang/crystal | Docs: https://crystal-lang.org/docs | Gitter: https://gitter.im/crystal-lang/crystal
ur5us has quit [Ping timeout: 245 seconds]
ur5us has joined #crystal-lang
<FromGitter> <respitesage:matrix.org> Ah, so that's the problem in your code. Mine is just a language semantics thing, I guess.
<FromGitter> <Blacksmoke16> are class methods not inherited?
<FromGitter> <Blacksmoke16> > A class inherits all instance variables and all instance and class methods of a superclass, including its constructors (new and initialize). ⏎ ⏎ seems they should
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/bjrw nice
<FromGitter> <Blacksmoke16> that doesn't seem right...
<FromGitter> <Blacksmoke16> duplicate of https://github.com/crystal-lang/crystal/issues/8093 prob
ur5us has quit [Remote host closed the connection]
ur5us has joined #crystal-lang
<FromGitter> <didactic-drunk> I can't delete `*`. It's valid crystal and lets you require named arguments.
<FromGitter> <didactic-drunk> Shouldn't there be a way to easily generate either the method definition or arguments as is for use in macro redefinition? Maybe `def.def` `def.redef` `def.args.def`
ua_ has quit [Ping timeout: 255 seconds]
ua_ has joined #crystal-lang
ur5us has quit [Ping timeout: 255 seconds]
<FromGitter> <HertzDevil> https://carc.in/#/r/bjtk
<FromGitter> <HertzDevil> `InnerClass` must also be a generic
notzmv has quit [Ping timeout: 265 seconds]
ur5us has joined #crystal-lang
Guest9910 has joined #crystal-lang
Guest9910 has quit [Client Quit]
ur5us has quit [Ping timeout: 255 seconds]
<FromGitter> <alexherbo2> how about adding `path.match?(pattern)` to wrap around `File.match?(pattern, path)`? https://crystal-lang.org/api/1.0.0/File.html#match?(pattern:String,path:Path%7CString)-class-method
notzmv has joined #crystal-lang
<FromGitter> <asterite> Yes, I thought many times of adding a `signature` method to the `Def` AST node
elf_fortrez has joined #crystal-lang
<mfiano> Hi again. I spent the last couple days reading the language reference and stdlib api docs. I think I could really become comfortable with this as a secondary language.
<FromGitter> <alexherbo2> how to get the mime type from a file content?
<FromGitter> <Blacksmoke16> mfiano glad to hear
<FromGitter> <Blacksmoke16> @alexherbo2 there's a `MIME` module you can use to get it from the filename/ext
<FromGitter> <Blacksmoke16> but there isn't a method to do that based on content
<mfiano> Thanks, it really is nice, and seems to borrow a lot from my primary language, yet seems to check off the items I'm looking for
<FromGitter> <Blacksmoke16> primary lang being Ruby?
<FromGitter> <alexherbo2> I'm having issues with file without extensions, like bash scripts, using shebangs.
<mfiano> No, Lisp :)
<FromGitter> <Blacksmoke16> (()ah i see)()()
<mfiano> I tried Nim a couple years ago, but the compiler was very buggy for a 1.0 release, and the community was quite toxic.
<FromGitter> <Blacksmoke16> @alexherbo2 is a method that you can specify a default for those cases
<FromGitter> <Blacksmoke16> if that helps
<FromGitter> <alexherbo2> how to return from a capturing block?, I'm using `next` in my block, but would like to allow `return`
<FromGitter> <Blacksmoke16> did you try `break`?
<mfiano> I thought break and return cant be used
<FromGitter> <Blacksmoke16> https://github.com/crystal-lang/crystal/issues/10546 related
<FromGitter> <Blacksmoke16> yea, `next` is the thing to return from a block
<FromGitter> <alexherbo2> I implemented a `filter` iterator, taking a block for filtering, but it looks odd that I can't use return in it
<FromGitter> <emanzx> Hi guys..
<FromGitter> <emanzx> today Im trying to learn about crystal Process
<FromGitter> <emanzx> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=60f0594d7b5a415e65e9ad58]
<FromGitter> <emanzx> it seem like the inotifywait does not run.. maybe exited
<FromGitter> <emanzx> but it works ok if I used backtick
<FromGitter> <emanzx> try to use Process.new as it will not wait for the process to finish.. I do this as sometimes.. inotifywait just freeze.. and I would force kill it with kill -9
<FromGitter> <Blacksmoke16> might be worth trying like `"-e", "create"`, not sure if that would make a diff tho
<FromGitter> <Blacksmoke16> versus `"-e create"`
<FromGitter> <emanzx> oh.. so I need to split all the args?
<FromGitter> <emanzx> ok I test first
<FromGitter> <Blacksmoke16> maybe? could also define the output/error IOs to be the parent process which might give a clue
<FromGitter> <Blacksmoke16> `Process.new("inotifywait", args: args, output: :inherit, error: :inherit)`
<FromGitter> <emanzx> deng it works.. hahaha
<FromGitter> <emanzx> thanks @Blacksmoke16 I will add the extra for error checking
<FromGitter> <Blacksmoke16> 👍 can also pass any `IO` for them
<FromGitter> <Blacksmoke16> like if you wanted to capture it in an `IO::Memory` or something
<FromGitter> <emanzx> noted. for now I just read the process output from file. I think its okay for now..
<FromGitter> <emanzx> but I will keep in mind about the IO::Memory
<FromGitter> <RespiteSage> What's up with 1.1.0? It looks like there's a GitHub release, but no blog post or forum thread.
elf_fortrez has quit [Quit: Client closed]
elf_fortrez has joined #crystal-lang
elf_fortrez has quit [Ping timeout: 246 seconds]
<mfiano> I'm confused about "require" and the default directory structure of "crystal init"
<FromGitter> <RespiteSage> What about it?
<mfiano> The language reference says the typical project layout is to have project/src/file.cr with: require "mylib", and project/lib/mylib/mylib.cr would get loaded. Why then, is lib/ added to the git ignore file? Also why can't I just resolve my own code in the src directory?
<FromGitter> <Blacksmoke16> `lib` directory is for dependencies
<FromGitter> <RespiteSage> ^
<FromGitter> <RespiteSage> Your own code should go in `src/`, just like you want to.
<FromGitter> <Blacksmoke16> like external shards/libraires you depend on. e.g. `vendor` in PHP/bundler
<FromGitter> <RespiteSage> When resolving your own code, you just need to use relative paths.
<mfiano> So I must use the relative designator for require in src/file.cr, like: require "./mylib", and it should find src/mylib/mylib.cr ?
<FromGitter> <RespiteSage> Close, but you would need `require "./mylib/mylib"` in that case.
<FromGitter> <Blacksmoke16> i usually skip that extra directory under src
<FromGitter> <Blacksmoke16> i dont really see the benefit of it
<FromGitter> <Blacksmoke16> https://github.com/Blacksmoke16/oq/tree/master/src :shrug:
<mfiano> I like having a directory with the entry point file alone, which imports anything else needed, and usually only does that
<FromGitter> <RespiteSage> I usually use directories under src, but I break them up by module.
<FromGitter> <Blacksmoke16> fair enough
<mfiano> I'll take a look at your repo. I am very new at this coming from a 60 year old language :)
<FromGitter> <Blacksmoke16> https://github.com/athena-framework/athena/tree/master/src would be a larger repo
<FromGitter> <RespiteSage> It's not really that different from how you do it in oq. I just tend to put a little more of the logic in the subdirectories.
<FromGitter> <RespiteSage> Oh? Fortran?
<FromGitter> <RespiteSage> Or something else?
<FromGitter> <Blacksmoke16> Lisp ^
<mfiano> Yep
<mfiano> Lisp
<FromGitter> <RespiteSage> Oh, I missed that.
<mfiano> What is oq?
<FromGitter> <Blacksmoke16> but thats how i do it, only diff is my main "entrypoint" file just lives with the rest of the files
<FromGitter> <Blacksmoke16> are you familiar with `jq`?
<mfiano> No
<FromGitter> <RespiteSage> Well, no questions are stupid questions. :)
<FromGitter> <Blacksmoke16> > A performant, and portable jq wrapper to facilitate the consumption and output of formats other than JSON; using jq filters to transform the data.
<FromGitter> <Blacksmoke16> https://stedolan.github.io/jq/tutorial/
<mfiano> Ah, I missed that your repo is oq. I was reading RespiteSage's message out of context
<mfiano> Well thanks for the tips. I'll study some projects and see what would work best for me
<FromGitter> <Blacksmoke16> np
<FromGitter> <Blacksmoke16> fwiw crystal itself doesnt use that extra dir
<FromGitter> <Blacksmoke16> nor does shards https://github.com/crystal-lang/shards/tree/master/src
<FromGitter> <Blacksmoke16> so :shrug:
<mfiano> btw which shards database/search website do you recommend. I noticed there are like 4 or 5 after the one i used has been down for some time
<mfiano> ?
<FromGitter> <RespiteSage> You can't go wrong looking through @Blacksmoke16's projects, though maybe don't worry too much about understanding the macros yet (stuff in `{{ }}` or `{% %}`, usually).
<mfiano> Crystal macros are very understandable, being a small subset of Lisp macros
<FromGitter> <RespiteSage> To be honest, I'm not sure. I tend to prefer shardbox.org, but it often doesn't have stuff I'm looking for.
<FromGitter> <RespiteSage> awesome-crystal (https://github.com/veelenga/awesome-crystal) is a good starting point for quality applications and libraries of various kinds, but it's far from comprehensive.
<mfiano> Ok yeah I noticed shardbox tracks ~1k, and the (now down) crystalshards.xyz had ~6k
<FromGitter> <RespiteSage> Yeah. And for whatever reason the language-constrained search on GitHub also rarely works for me.
<FromGitter> <Blacksmoke16> shardbox is curated as is awesome-crystal, others just scrape GH
<mfiano> the * search on github rarely works good ;)
<FromGitter> <RespiteSage> Lol.
<FromGitter> <RespiteSage> Also, @Blacksmoke16, my usual pattern for applications was initially inspired by the scry entry point file (https://github.com/crystal-lang-tools/scry/blob/master/src/scry.cr).
<FromGitter> <Blacksmoke16> only for the reason to make it more obs what the entrypoint file is?
<FromGitter> <RespiteSage> Yeah, basically. I also like splitting out the driver and configuration logic from the rest of the application logic. Though that does make it hard to test the driver and configuration logic.
<FromGitter> <RespiteSage> My discryb src/ (https://github.com/RespiteSage/discryb/tree/master/src) might be the only example of my own that's publicly-available.
<mfiano> to be fair, my first project was actually going to be a library, so maybe i should have clarified before asking :)
<FromGitter> <Blacksmoke16> @RespiteSage take a look at `oq_cli.cr`
<FromGitter> <Blacksmoke16> might be easier to test
<FromGitter> <RespiteSage> Yeah, libraries bypass those considerations.
<FromGitter> <Blacksmoke16> i.e. use option parser to process the args and create an instance of the actual type, passing in those args
<mfiano> Doubtful, as all the new kids seem to prefer vscode, but anyone using vim/nvim for crystal?
<FromGitter> <RespiteSage> I am one of those new kids, but I know I've seen people talk about using vim/nvim (and at least one or two other terminal editors) when writing Crystal.
<mfiano> I guess one of the questions I have is editor agnostic...is crystalline the preferred LSP server?
<FromGitter> <Blacksmoke16> thats what i hear yes
<FromGitter> <RespiteSage> Yeah, Scry has been around longer, but Crystalline seems to have more features and be more actively maintained.
<mfiano> Great thanks
<mfiano> I'm happy to see vim-based does take a nice second place on that pie chart :)
<FromGitter> <RespiteSage> You may already have this info, but there was a thread (https://forum.crystal-lang.org/t/vim-tags-support/3371) that includes some links to a vim plugin.
<FromGitter> <Blacksmoke16> https://spacevim.org/layers/lang/crystal/
<mfiano> crystalline seems to support jumping to definition just fine. keeping a tags database seems un-needed just yet
<FromGitter> <RespiteSage> @Blacksmoke16 Just looked at `oq_cli.cr`. That's a solid pattern. It reminds me of factories in Java, just with less bloat.
<FromGitter> <Blacksmoke16> kinda yea, works quite well as the lib itself is decoupled from the CLI context
<mfiano> That project seems to be structured well and very easy to read
<mfiano> (and nicely documented)
<FromGitter> <Blacksmoke16> i try 😃
<mfiano> at least as a first real project I've seen
<FromGitter> <jwaldrip> Getting some weird behavior... ⏎ ⏎ `````` [https://gitter.im/crystal-lang/crystal?at=60f08c68ce199275eff4c4f2]
<FromGitter> <jwaldrip> given that... I am getting a strange error
<FromGitter> <Blacksmoke16> `manifest.type` should be an enum :)
<FromGitter> <Blacksmoke16> got a link to the code?
<FromGitter> <jwaldrip> ya, let me push
f1refly has quit [Read error: Connection reset by peer]
f1refly has joined #crystal-lang
<FromGitter> <Blacksmoke16> does that `spec` method exist on all those types in the union?
<FromGitter> <jwaldrip> Let me double check
<FromGitter> <Blacksmoke16> it seems the type of that union is being collapsed into their parent `Pyrite::Kubernetes::Object+` type which doesn't have that method
<FromGitter> <Blacksmoke16> https://github.com/crystal-lang/crystal/issues/2661#issuecomment-877286921 is prob similar to what's going on ^ if i had to guess
<FromGitter> <jwaldrip> Which is strange... the result method ensures the proper type is returned
<FromGitter> <jwaldrip> or at least it should
<FromGitter> <Blacksmoke16> but you're doing a `.as(Psykube::Generator::Podable::Resource)`
<FromGitter> <Blacksmoke16> where `Resource` is an alias to a union of other types
<FromGitter> <jwaldrip> so really I would have to case over each type in the union to get what I want
<FromGitter> <Blacksmoke16> or make use of overloads for specific types
<FromGitter> <jwaldrip> ya, let me see what I can do
<FromGitter> <alex-kampa> Now here's a bit of a surprise:
<FromGitter> <alex-kampa> ```puts [1, 2, 3, 4, 5].reduce(0) { |acc, i| acc = acc + 1 if i.to_s =~ /3/ }``` ⏎ ⏎ Error: undefined method '+' for Nil (compile-time type is (Int32 | Nil)) [https://gitter.im/crystal-lang/crystal?at=60f095a9951c58084edee033]
<FromGitter> <Blacksmoke16> i think you need some parans
<FromGitter> <Blacksmoke16> parens*
<FromGitter> <Blacksmoke16> i think the `if` is making the type of `acc` possibly `nil`, because the return value of the block is used to set the acc
<FromGitter> <Blacksmoke16> `.reduce(0) { |acc, i| i.to_s =~ /3/ ? acc + i : acc }`
<FromGitter> <Blacksmoke16> is 3 the expected value here?
<mfiano> Can someone ELI5 the ~> version operator?
<mfiano> I read that
<mfiano> Maybe I'm dumb
<FromGitter> <Blacksmoke16> afaik its the same as the `^` in other langs
<riza> mfiano: the idea with ~> is that it allows for upgrades within the specified point but no higher
<FromGitter> <Blacksmoke16> just a shortcut to say allow versions within this range
<riza> so if you ~> x.y.z, you leave room for z to increment but not y
<FromGitter> <Blacksmoke16> ^
<riza> and if you ~> x.y, y can increment, z can be anythnig and x cannot change
<mfiano> Oh very good. I don't see why you would want to leave room for y or x to upgrade...how can you know anything other than a patch won't break your code?
<riza> its used under the assumption that the project you're referencing follow SemVer
<FromGitter> <alex-kampa> Thanks @Blacksmoke16 your solution works, even though ⏎ ⏎ ```puts [1, 2, 3, 4, 5].reduce(0) { |acc, i| acc = acc + 1 if i.to_s =~ /3/ }``` ⏎ ⏎ but ok I guess that's the price to pay for a complied language ... and shows that the transition from Ruby to Crystal is not always easy. [https://gitter.im/crystal-lang/crystal?at=60f097b938da567d82a15aa9]
<riza> mfiano: if the project is following SemVer, then you know that anything which is a breaking change is a major version increment
<mfiano> Ok I see
<FromGitter> <Blacksmoke16> @alex-kampa whats the end goal of this code?
<FromGitter> <Blacksmoke16> i noticed i had `acc + i` instead of `acc + 1`, so are all you wanting to do is count the number of time `3` is in the array?
<FromGitter> <alex-kampa> counting elements in an array that match a certain regex
<FromGitter> <alex-kampa> at this stage just playing around with various ways to achieve that
<FromGitter> <Blacksmoke16> `puts [1, 2, 3, 4, 5].count { |i| i.to_s.matches? /3/ }`
<FromGitter> <Blacksmoke16> or in this specific case `puts [1, 2, 3, 4, 5].count 3`
<FromGitter> <alex-kampa> thanks, the ".matches?" looks good, short and idiomatic. I know, RTFD :-)
<FromGitter> <alex-kampa> .count not enough in the general case
<FromGitter> <alex-kampa> Thanks @Blacksmoke16
<mfiano> Is there a way I can run ameba automatically when I "run" or "spec"?
<FromGitter> <Blacksmoke16> setup a `Makefile`
<mfiano> Fair enough
<FromGitter> <Blacksmoke16> dont think youd want to run it every time you go to run the program tho
<mfiano> Probably whenever I spec though
<FromGitter> <Blacksmoke16> yea
<FromGitter> <jwaldrip> alright, solved that one... next Q
<FromGitter> <jwaldrip> how is is possible to call .from_json on an abstract class and have it resolve to one of its children?
<mfiano> Ah cool, no Makefile required
<FromGitter> <Blacksmoke16> `crystal spec && ./bin/ameba`?
<mfiano> on save, vim-crystal seems to annotate the margin and with error icons, and when cursor is on one of those lines, message in status bar
<FromGitter> <Blacksmoke16> ah nice, i know sublime runs the formatter on save as wel, is super nice
<mfiano> Yeah vim-crystal seems to run the formatter (optionally [disabled by default for some reason]), and ameba if available, though no mention of that or switch for it
<mfiano> Day 1 actually getting the tooling set up and writing a small amount of code, and I must say, Crystal was easier to get comfortable with than most of the few dozen or so languages I've tried.
<FromGitter> <Blacksmoke16> 👍
elf_fortrez has joined #crystal-lang
<mfiano> development_dependencies are included when not building with --release, right, or is there some other criteria that classifies what "development" means?
<FromGitter> <Blacksmoke16> they're dependencies not used in the final build of the code
<FromGitter> <Blacksmoke16> i.e. ameba, and testing stuff
<mfiano> Right, I'm looking at debug.cr right now...they say you can call Debug.enabled = true if you don't want to set an env var, so I'm wondering if I can check some flag as to not call that in release builds
<FromGitter> <Blacksmoke16> ```{% unless flag? :release %} ⏎ Debug.enabled = true ⏎ {% end %}``` [https://gitter.im/crystal-lang/crystal?at=60f0a35d0853e41c0d5d0a5c]
<FromGitter> <Blacksmoke16> would be true whenever its built without `--release`
<mfiano> You mean the inverse ;)
<mfiano> But, thanks
ur5us has joined #crystal-lang
<FromGitter> <Blacksmoke16> i mean `Debug.enabled` would be true w/o `--release`
<mfiano> Oh yes you're right, I read your description wrong.
<mfiano> It might be about time for bed :/
<FromGitter> <Blacksmoke16> but to answer your earlier question doing like `shards build --release` would also technically install dev dependencies, but is likely you're not requiring those in your main code anyway.
<FromGitter> <Blacksmoke16> would want to use `--production` or `--without-development`, can do `shards --help` for more info
<mfiano> Where is a good place to put such meta-code as the above?
<FromGitter> <Blacksmoke16> would need to go in your main entrypoint file, or some other file that requires it
<FromGitter> <Blacksmoke16> oh i have an idea
<FromGitter> <Blacksmoke16> have a `debug.cr` file that you put this stuff in
<mfiano> Does it matter that it's before the main entry point's "require"s?
<FromGitter> <Blacksmoke16> then you can add a `{% skip_file if flag?(:release) %}` so that the code isn't processed in release mode
<mfiano> Oh hmm...and where would that macro form go?
<FromGitter> <Blacksmoke16> first line of `debug.cr`
<mfiano> Aha!
<mfiano> I like that better. It probably means I have to explicitly require debug.cr before other requires for this to work properly, rather than an arbitrary *...or I could be wrong
<FromGitter> <Blacksmoke16> i would advise against using like `require "./**"`
<mfiano> Yeah I would too
<mfiano> Though I must be doing something wrong here.
<mfiano> i did shards install, but get undefined constant Debug
<FromGitter> <Blacksmoke16> oh well you need to require the lib
<FromGitter> <Blacksmoke16> `require "debug"` or whatever it's called
<mfiano> Yeah I suppose that would help a tiny bit
<mfiano> Well there may be a problem with my crystalline setup or something
<FromGitter> <Blacksmoke16> i never used it so :shrug:
<mfiano> I get editor error, saying it can't find file 'debug' on the line with require "debug", however, 'crystal run' works fine
<FromGitter> <Blacksmoke16> wonder if its conflicting with that file you just made
<FromGitter> <Blacksmoke16> oh, or maybe it just doesnt know how to resolve deps like that? i never used it so ill defer to someone else
<mfiano> That's out of the require path, in src. without a relative path it should only be looking in the stdlib or "lib"
<mfiano> so hmm
<mfiano> Ha you're right
<FromGitter> <Blacksmoke16> 👌
<mfiano> and shards install makes a lib/debug/...
<mfiano> Renaming the above gist to debug2.cr and it works
<mfiano> how odd
<mfiano> I just have to keep in mind that I shouldn't have local files with the same name as 3rd party library directories or something
<FromGitter> <Blacksmoke16> pretty much yea
elf_fortrez has quit [Ping timeout: 246 seconds]
lucf117 has joined #crystal-lang
<mfiano> nah that actually works fine. it seems to be a bug in that the errors in nvim's LSP are cached and not properly invalidated, even across restarts...
<FromGitter> <jwaldrip> Why would `@type.subclasses` return an empty list?
<FromGitter> <jwaldrip> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=60f0b4e961accd7e782af824]
<FromGitter> <jwaldrip> is there a point in compilation where I have access to the subclasses?
<FromGitter> <Blacksmoke16> Try adding a \
<FromGitter> <Blacksmoke16> `\{% puts @type.subclasses %}`
<FromGitter> <jwaldrip> there we go
<FromGitter> <jwaldrip> ya, i am very familiar... just been awile
<FromGitter> <jwaldrip> too much time in elixir lately
<FromGitter> <jwaldrip> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=60f0b67cd11e1655605b07fb]
<FromGitter> <jwaldrip> there we go
<FromGitter> <jwaldrip> Are there good examples of how the `with` syntax works with blocks
<FromGitter> <jwaldrip> the docs are pretty bare on it
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=60f0bed1f1274d5e504ef60f]
<FromGitter> <Blacksmoke16> which is similar to
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=60f0bee7049a0c3e5376ae3b]
<FromGitter> <jwaldrip> Whats the ETA on 1.1.0 docker containers?
<FromGitter> <Blacksmoke16> technically you could prob just use nightly in the meantime
<FromGitter> <Blacksmoke16> if you'd be ok with it being rebuilt every night ofc
<FromGitter> <jwaldrip> what about the 1.1-dev?
<FromGitter> <Blacksmoke16> mm that might be the pre-release? id go with that
elf_fortrez has joined #crystal-lang