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
<straight-shoota> @franciscoadasme: https://github.com/crystal-lang/crystal/pull/10329
<FromGitter> <asterite> Yes, but ruby works the same way
<FromGitter> <asterite> it would be a bit strange if every Enumerable was flattened
<FromGitter> <asterite> For example a Dir is Enumerable, but you probably don't want to flatten that
<FromGitter> <asterite> Http headers are also Enumerable. Apparently uri params too
<FromGitter> <asterite> Also flatten is defined on Array, that's why it only flattens arrays
<FromGitter> <asterite> Flatten is usually used in conjuncion with map, which returns array in most cases, so thats another reason... Well
<FromGitter> <franciscoadasme> @straight-shoota thanks but it's not that same I'm talking about
teardown_ has joined #crystal-lang
<FromGitter> <franciscoadasme> @asterite I understand what you say, but I don't entirely agree... Flattening is supposed to be used on a collection of collections, so sure, using flatten on Dir or any "one-dimensional" collection is kind of odd, but flattening an array of Dir's may make sense
teardown has quit [Ping timeout: 268 seconds]
teardown_ has quit [Remote host closed the connection]
<FromGitter> <franciscoadasme> anyways, I stumble upon this issue by returning a tuple in the block, and it was surprising to get `Array(Tuple(...))` but perhaps it was a misunderstanding on my part
teardown has joined #crystal-lang
teardown has quit [Remote host closed the connection]
teardown has joined #crystal-lang
teardown_ has joined #crystal-lang
teardown has quit [Ping timeout: 268 seconds]
teardown has joined #crystal-lang
teardown_ has quit [Ping timeout: 268 seconds]
teardown_ has joined #crystal-lang
hightower3 has quit [Ping timeout: 246 seconds]
teardown has quit [Ping timeout: 268 seconds]
teardown has joined #crystal-lang
teardown_ has quit [Ping timeout: 268 seconds]
teardown_ has joined #crystal-lang
teardown has quit [Ping timeout: 268 seconds]
teardown has joined #crystal-lang
teardown_ has quit [Ping timeout: 268 seconds]
deavmi has quit [Read error: Connection reset by peer]
deavmi has joined #crystal-lang
teardown_ has joined #crystal-lang
teardown has quit [Ping timeout: 268 seconds]
Flipez has quit [Ping timeout: 260 seconds]
teardown has joined #crystal-lang
teardown_ has quit [Ping timeout: 268 seconds]
teardown_ has joined #crystal-lang
teardown has quit [Ping timeout: 268 seconds]
teardown has joined #crystal-lang
Flipez has joined #crystal-lang
teardown_ has quit [Ping timeout: 268 seconds]
teardown_ has joined #crystal-lang
teardown has quit [Ping timeout: 268 seconds]
Flipez has quit [Ping timeout: 240 seconds]
teardown has joined #crystal-lang
teardown_ has quit [Ping timeout: 268 seconds]
teardown_ has joined #crystal-lang
teardown has quit [Ping timeout: 268 seconds]
f1reflyylmao has joined #crystal-lang
f1refly has quit [Ping timeout: 258 seconds]
teardown has joined #crystal-lang
teardown_ has quit [Ping timeout: 268 seconds]
teardown_ has joined #crystal-lang
Flipez has joined #crystal-lang
teardown has quit [Ping timeout: 268 seconds]
teardown has joined #crystal-lang
teardown_ has quit [Ping timeout: 268 seconds]
teardown_ has joined #crystal-lang
teardown has quit [Ping timeout: 268 seconds]
teardown has joined #crystal-lang
teardown_ has quit [Ping timeout: 268 seconds]
avane has quit [Quit: ZNC - https://znc.in]
teardown_ has joined #crystal-lang
avane has joined #crystal-lang
teardown has quit [Ping timeout: 268 seconds]
teardown has joined #crystal-lang
teardown_ has quit [Ping timeout: 268 seconds]
teardown_ has joined #crystal-lang
teardown has quit [Ping timeout: 268 seconds]
teardown has joined #crystal-lang
teardown_ has quit [Ping timeout: 268 seconds]
teardown_ has joined #crystal-lang
teardown has quit [Ping timeout: 268 seconds]
teardown has joined #crystal-lang
teardown has quit [Remote host closed the connection]
teardown_ has quit [Ping timeout: 268 seconds]
teardown has joined #crystal-lang
teardown_ has joined #crystal-lang
teardown has quit [Ping timeout: 268 seconds]
teardown has joined #crystal-lang
teardown_ has quit [Ping timeout: 268 seconds]
_whitelogger has joined #crystal-lang
teardown_ has joined #crystal-lang
teardown has quit [Ping timeout: 268 seconds]
teardown has joined #crystal-lang
teardown_ has quit [Ping timeout: 268 seconds]
teardown_ has joined #crystal-lang
teardown has quit [Ping timeout: 268 seconds]
teardown has joined #crystal-lang
teardown_ has quit [Ping timeout: 268 seconds]
teardown has quit [Ping timeout: 268 seconds]
_ht has joined #crystal-lang
f1reflyylmao is now known as f1refly
alexherbo2 has joined #crystal-lang
yxhuvud has quit [Ping timeout: 268 seconds]
yxhuvud has joined #crystal-lang
<FromGitter> <asterite> Oh, I see
<FromGitter> <asterite> I think the issue is that we copied the functionality from Ruby, but in Ruby the only collection type is Array. In Crystal we also have Tuple, StaticArray, etc.
<FromGitter> <asterite> So maybe we should also do it for more collections... But for example tuples are sometimes used to represent a pair of related objects, to be considered a single object. So flattenning that would sometimes be confusing. In the end, I think we should document this and say that only Arrays get flattened
<yxhuvud> in general flatten(1) is more common than flatten(all the levels), so I doubt that is a problem in practice.
<yxhuvud> (at least for me. YMMV)
<FromGitter> <HertzDevil> the doc change in 10329 makes it clear only arrays and iterators are flattened
<FromGitter> <HertzDevil> (previously `Iterator` didn't even appear on `Enumerable#flat_map`)
<FromGitter> <HertzDevil> ('s doc)
<FromGitter> <HertzDevil> every enumerable of enumerables can be flattened by calling `.map(&.each)` first even if that's not very efficient
<FromGitter> <HertzDevil> or by calling `.each` after everything else in the block
<Andriamanitra> that's cool, i had no idea flatten worked on iterators too
<FromGitter> <HertzDevil> oh yeah, flatten too
<FromGitter> <HertzDevil> however 10329 doesn't cover flatten
alexherbo2 has quit [Ping timeout: 265 seconds]
<FromGitter> <asterite> To be honest I'm not sure flatten should work on iterators
<FromGitter> <asterite> maybe since it's a call on Iterator it makes sense, I don't know
<straight-shoota> an iterator type is mainly a collection
<straight-shoota> so I guess it would make sense.
<straight-shoota> There are types that can either be a collection of items or an individual entity as a whole. But those usually implement Iterable, not Iterator
alexherbo2 has joined #crystal-lang
<FromGitter> <jrei:matrix.org> @bcardiff will https://jfrog.com/blog/into-the-sunset-bintray-jcenter-gocenter-and-chartcenter/ impact Crystal distribution?
<FromGitter> <bcardiff> Most likely @j8r i read that yesterday. Great timing...
<FromGitter> <bcardiff> This didn’t age well 😅 https://gitter.im/crystal-lang/crystal?at=6019a55684e66b7f7ec97fc1
<FromGitter> <djberg96> noob here, what am I doing wrong?
<FromGitter> <djberg96> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=601c05845500a97f82e6c3b1]
<FromGitter> <djberg96> doesn't seem to give me the full trace
<FromGitter> <Blacksmoke16> doesnt seem to give you *any* trace?
<FromGitter> <djberg96> just gives me the "regular" output
<FromGitter> <djberg96> (p. 93 of Programming Crystal btw)
<FromGitter> <djberg96> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=601c0634063b6c68d53b1c9c]
<FromGitter> <djberg96> But, according to the book, I should see a lot more with --error-trace
<FromGitter> <Blacksmoke16> i mean its possible that *all* there is
<FromGitter> <djberg96> ze code in question: https://gist.github.com/djberg96/f4f6b697c85da709eee277e1dbcedb7d
<FromGitter> <Blacksmoke16> yea thats prob the only frame, as there are no method calls etc
<FromGitter> <Blacksmoke16> because the error doesnt happen in a method call, as its on the top leve*
<FromGitter> <Blacksmoke16> level
<FromGitter> <djberg96> maybe it changed between 0.2.x and 0.3.x, or maybe the book just has a bad example
<FromGitter> <djberg96> (the book was written during 0.2.x i believe)
<FromGitter> <djberg96> any, no worries, soldiering on
<FromGitter> <Blacksmoke16> 👍 and i assume you understand why the error is happening? :p
<FromGitter> <djberg96> yes
<FromGitter> <Blacksmoke16> perfect
<FromGitter> <djberg96> really i just wanted to see how a backtrace looked :)
hightower3 has joined #crystal-lang
<yxhuvud> djberg96: wow, yet another oldie from #ruby-lang before rails :)
<FromGitter> <djberg96> :)
<FromGitter> <asterite> no
<FromGitter> <asterite> crystal run --error-trace mineral.cr
<FromGitter> <asterite> run that, you'll see more frames
<FromGitter> <asterite> @djberg96 ^
<FromGitter> <asterite> when you do `crystal foo.cr --error-trace`, `--error-trace` is passed as an argument to the program, not the compiler
<FromGitter> <Blacksmoke16> :0
<FromGitter> <Blacksmoke16> good to know
<FromGitter> <asterite> unfortunately someone thought that was a good idea and everyone else except me liked that
<FromGitter> <erdnaxeli:cervoi.se> oh, I always thought you pass params too the program using `--`
<FromGitter> <erdnaxeli:cervoi.se> so `crystal foo.cr -- --error-trace`
<FromGitter> <naqvis> this behavior is different from common cli arg passing, technically speaking any arguments passed should be considered to be passed to command which is being invoked
<FromGitter> <asterite> yes, that was in the past... it changed a few versions before
<FromGitter> <asterite> @erdnaxeli:cervoi.se nope, that would still not work
<FromGitter> <asterite> oh, nevermind
<FromGitter> <naqvis> i remember previously one had to use `--` to pass the arguments to program being invoked via `crystal run`
<FromGitter> <naqvis> don't know why that get changed
<FromGitter> <asterite> it's so you can use shebang with crystal
<FromGitter> <asterite> like if crystal were a scripting language (which is not)
<FromGitter> <erdnaxeli:cervoi.se> ah, kind of make sens
<FromGitter> <erdnaxeli:cervoi.se> supposing you want to use it like that
<FromGitter> <asterite> if I want a tool I want to execute multiple times, I compile it once
<FromGitter> <asterite> then it runs faster
<FromGitter> <asterite> shebang for crystal is useless for me
<FromGitter> <naqvis> true, crystal ain't scripting language and it shouldn't be treated that way
<FromGitter> <djberg96> @asterite aha, thanks!
<FromGitter> <naqvis> @djberg96 also you needn't to use separate arguments to assign values to ivars. you can simplify your sample initialize method by ⏎ ⏎ ```def initialize(@name, @hardness, @crystal_struct) ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=601c2dbe9238c531ad2449e0]
<FromGitter> <jrei:matrix.org> any reason not to use for quick scripts
<FromGitter> <jrei:matrix.org> even core members use it like this @asterite : https://github.com/crystal-lang/crystal-infrastructure/blob/main/gha-runner-arm/collect_keys.cr
<FromGitter> <naqvis> no one is against that, but against treating it as interpreted language. as no matter you do `crystal run` its still going to compile the code before that get executed
<FromGitter> <naqvis> so giving this illusion of interpreted doesn't make sense
<FromGitter> <asterite> j8r what do you mean, where's the shebang there?
<FromGitter> <jrei:matrix.org> no shebang, but it is used as a script
<FromGitter> <jrei:matrix.org> a shebang would perfectly fit there, `crystal collect_keys.cr` vs `./collect_keys.cr`
<FromGitter> <asterite> how do you know it's used as a script? did you see jhass running it? maybe he compiles it first
<FromGitter> <jrei:matrix.org> my point is: performance does not matter at all for such scripts, really
<FromGitter> <jrei:matrix.org> it could execute in 10 seconds it won't change anything
<FromGitter> <asterite> how do you know?
<FromGitter> <jrei:matrix.org> because it collect keys only once. After you have it, no need to run again
<FromGitter> <asterite> also, that's your preference, not mine
<FromGitter> <jrei:matrix.org> there are danger, like becoming out of sync with the actual code
<FromGitter> <djberg96> @naqvis yep, that's a very handy shortcut, thanks
<FromGitter> <oprypin:matrix.org> how can i create a regex literal from a macro?
<FromGitter> <oprypin:matrix.org> i have its source as a string, i just worry about messing up the escapes
<FromGitter> <Blacksmoke16> pass the string to `Regex.new`?
<FromGitter> <oprypin:matrix.org> i want a cached one
<FromGitter> <oprypin:matrix.org> for now doing `%r({{ regex }})` - "what could go wrong"
<FromGitter> <oprypin:matrix.org> for now doing `%r({{ regex.id }})` - "what could go wrong" *
<FromGitter> <Daniel-Worrall> `raise if Regex.needs_escape?({{ regex }})`
<FromGitter> <asterite> I think a macro method that turns a string or id into a regex literal would be good to have
<FromGitter> <Daniel-Worrall> mhm
<oprypin> >> {{ " " * 5 }} # :(
<DeBot> oprypin: Error: undefined macro method 'StringLiteral#*' - https://carc.in/#/r/acun
<FromGitter> <Blacksmoke16> could do it with a for loop and `+=` 😆
<oprypin> yes..
<FromGitter> <Daniel-Worrall> The differences between macro classes and their equivalent classes is confusing a lot of the time
duane has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 240 seconds]
postmodern has quit [Quit: Leaving]
<repo> hey Blacksmoke16 o/ quick question about cors: is it possible that allowing something like http://localhost:3000 isn't possible?
<repo> (in athena)
<hightower3> Remind me please, how do I retrieve the filename (or ideally, directory name) of the .cr file currently being compiled?
<hightower3> oh, seems to be just __DIR__
<repo> Blacksmoke16: never mind, my bad
<FromGitter> <Blacksmoke16> 👍
<FromGitter> <Blacksmoke16> repo: going to be releasing new version tonight, so if you want to update to master to get a jump start on things you can
alexherbo2 has joined #crystal-lang
<FromGitter> <djberg96> what's the typical time between a release and a brew package update? or do they happen simultaneously?
<FromGitter> <Blacksmoke16> PR is opened around the time when the release is tagged in GH
<FromGitter> <Blacksmoke16> so prob within a day or so?
<FromGitter> <djberg96> thanks
hightower3 has quit [Ping timeout: 276 seconds]
hightower3 has joined #crystal-lang
<FromGitter> <erdnaxeli:cervoi.se> Hi, I should I format a very long condition?
<FromGitter> <erdnaxeli:cervoi.se> I am writting a method returning a bool, and I got an very long line with `a == b && c == d && …`
<FromGitter> <oprypin:matrix.org> erdnaxeli (https://matrix.to/#/@erdnaxeli:cervoi.se): put it into brackets and do whatever
<FromGitter> <oprypin:matrix.org> `if (` ⏎ `...`
<FromGitter> <jrei:matrix.org> you can use `\`
<FromGitter> <erdnaxeli:cervoi.se> ok thanks
<FromGitter> <erdnaxeli:cervoi.se> I think `crystal tool format` should have a line max length, and should do that itself
<FromGitter> <Blacksmoke16> ehhhh
<FromGitter> <erdnaxeli:cervoi.se> yeah… currently if I use `\` `crystal tool format` just put it back on one line
<FromGitter> <erdnaxeli:cervoi.se> Ah ! so `\<new line>&&` is put back on one line, but not `&& \<new line>`
<FromGitter> <erdnaxeli:cervoi.se> it does have preferences :p
<oprypin> in all of my projects i literally have 1 instance of a trailing backslash
<FromGitter> <erdnaxeli:cervoi.se> wow I just discovered you can access another instance ivars 🤯
<FromGitter> <erdnaxeli:cervoi.se> https://carc.in/#/r/acvn
<FromGitter> <erdnaxeli:cervoi.se> that's not a if here, I am just returning a bool
<oprypin> no difference
<FromGitter> <erdnaxeli:cervoi.se> https://carc.in/#/r/acvt is `getter` useless?
<oprypin> erdnaxeli:cervoi.se, dont access like that. variables are always private.
<oprypin> i mean, you found a way to access a private variable. doesn't mean that it *should* be done
<FromGitter> <erdnaxeli:cervoi.se> that's what I was thinking, but this code works, so actually they are not private?
<FromGitter> <Blacksmoke16> its a secret shh
<oprypin> erdnaxeli:cervoi.se, it's accessing a variable of an instance of the same type
<oprypin> such accesses are the only ones that are not frowned upon. no better alternative was found so this syntax was kept.
<FromGitter> <erdnaxeli:cervoi.se> which is weird too
<FromGitter> <erdnaxeli:cervoi.se> so actually ivars are public, wow :D
<FromGitter> <Blacksmoke16> please dont go using this everywhere in your code tho
<FromGitter> <oprypin:matrix.org> erdnaxeli (https://matrix.to/#/@erdnaxeli:cervoi.se): i don't know what you'd say if you were using Python
<FromGitter> <erdnaxeli:cervoi.se> I won't ^^
<FromGitter> <oprypin:matrix.org> ahhahaha i can access everything zomg
<FromGitter> <erdnaxeli:cervoi.se> oprypin (https://matrix.to/#/@oprypin:matrix.org): I am actually payed to be a python dev :p
<oprypin> then you see my point :>
_ht has quit [Remote host closed the connection]
<FromGitter> <jrei:matrix.org> in essence a program is mutable at runtime, so...
<FromGitter> <jrei:matrix.org> In most languages we can do this kind of unsafe things
<FromGitter> <jrei:matrix.org> please tell me those we can't, I only know a bunch of them
<FromGitter> <asterite> if ivars weren't publics, you can reopen a type and add a getter for them. So there's really no way to prevent someone from accessing ivars. The same is true in Ruby and you can do `instance_var_get(...)`, so in Crystal we have the same but embedded in the syntax
<FromGitter> <asterite> also, there's no need to use `\` after `&&` or `||`, just write a newline and let the formatter format it. It aligns things pretty nicely (I think)
<FromGitter> <mattrberry> Is there a nice way to accomplish something like this? https://carc.in/#/r/acwh
<FromGitter> <Blacksmoke16> https://carc.in/#/r/acwl
<FromGitter> <mattrberry> Ty <3
<FromGitter> <mattrberry> Is the only way to enforce types in macros to put a check at the top of the macro?
<FromGitter> <Blacksmoke16> pretty much yea
<FromGitter> <Blacksmoke16> or just let the compiler yell at you
<FromGitter> <mattrberry> Pretty much all of my cases will be just checking equality with `==`, so the compiler wouldn't yell. I'll definitely put some guards at the top of the macros to make sure I don't waste tons of time finding some stupid bug haha
<FromGitter> <Blacksmoke16> its also possible to unit test macro code somewhat
<FromGitter> <Blacksmoke16> at least the errors
<FromGitter> <mattrberry> How would I go about checking the type in a macro? Like this ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=601c7e4d9fa6765ef8fb7af3]
<FromGitter> <Blacksmoke16> did you try `e.is_a? Enum`?
<FromGitter> <mattrberry> I did not
<FromGitter> <oprypin:matrix.org> it's a runtime construct, it will not work
<FromGitter> <oprypin:matrix.org> i think there is no way
<FromGitter> <Blacksmoke16> `.is_a?` works in macros too, but wont for this context
<FromGitter> <Blacksmoke16> e.g. `foo.is_a? StringLiteral`
<FromGitter> <oprypin:matrix.org> it can detect being called as `mac(enum E; X; Y; end)` but not as `mac(E)`
<FromGitter> <oprypin:matrix.org> `E` is_a `Path`
<FromGitter> <Blacksmoke16> sec
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/acxh
<FromGitter> <Blacksmoke16> that does it
<oprypin> oh im out of date then
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/master/Crystal/Macros/TypeNode.html#%3C=(other:TypeNode):BoolLiteral-instance-method
<FromGitter> <Blacksmoke16> is a nice method ^
<FromGitter> <mattrberry> I'll take it. Any guards there are helpful so that I don't shoot myself in the foot :p Thanks!
<FromGitter> <mattrberry> There's no way to check that the input is that *specific* enum, though, right?
<FromGitter> <Blacksmoke16> try changing `e <= MyEnum`?
<FromGitter> <Blacksmoke16> `e.resolve == E` works too i think
<FromGitter> <mattrberry> Oh I see my confusion
<FromGitter> <mattrberry> I wanted to do something like this https://play.crystal-lang.org/#/r/acxu
<FromGitter> <mattrberry> Where I pass it a specific field from the enum, like `E::FOO`
<FromGitter> <mattrberry> Whereas your example had just `E`
<FromGitter> <Blacksmoke16> oh
<FromGitter> <Blacksmoke16> and what, you want to ensure its a member of `E`?
<FromGitter> <mattrberry> Yeah exactly
<FromGitter> <mattrberry> Sorry yeah I wasn't clear about that
<FromGitter> <Blacksmoke16> whats the use case for this? doesnt the compiler do that for you?
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/acya this works but are prob some edgecases
<FromGitter> <Blacksmoke16> as im ignoring the rest of the path
<FromGitter> <mattrberry> I'd want the compiler to catch the `table[4] =` so that I don't shoot myself in the foot with a stupid copy-paste mistake at some point down the road https://carc.in/#/r/acyd
<FromGitter> <mattrberry> But since the only things I use those for is to check `==`, the compiler won't complain unless I specifically add guards for those types
<FromGitter> <mattrberry> Ideally I’d be able to specify types on the macro as I would on any function, but I’m guessing that since that doesn’t exist already, it’s probably a challenging problem to solve
<FromGitter> <Blacksmoke16> not sure i entirely follow but 👍
<FromGitter> <mattrberry> I just want to limit the types of the args that I’m calling the macro with. Since the macro only emits code that calls `==` on its args, the compiler won’t complain. If I want a macro to only work on integers, for example, I’d want it to throw an exception if I try to call the macro with “1” instead of 1, which it currently won’t do. I’m just trying to find a way to guard the types since we
<FromGitter> ... don’t have syntax like `macro foo(num : Int32)`