jhass changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | Crystal 0.35.1 | 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
<FromGitter> <3n-k1> just some custom analysis for enforcing code quality
<FromGitter> <3n-k1> something like isort, black, or flake8
<FromGitter> <3n-k1> i know there's ameba
<FromGitter> <j8r> I have a math problem
<FromGitter> <j8r> I have succeeded to find a way to have a random point on a circle
<FromGitter> <j8r> but, I would like to have N number of points in this circle, which are equidistant to each others
<FromGitter> <j8r> on the circle of course.
<FromGitter> <Blacksmoke16> my brain hurts already
<FromGitter> <3n-k1> select a random point, place the next one C/n units away, where C=circumference?
<FromGitter> <3n-k1> i think i'm right, but i'm bad at geometry tho so don't take my word for it
<FromGitter> <j8r> yeah, I got this idea too
<FromGitter> <j8r> but I'm struggling to "warp" the line on the circle circumference, and get the coordinates
<FromGitter> <3n-k1> oh yeah, no idea
<FromGitter> <j8r> with 2 and 4 points that's easy, at least
<FromGitter> <3n-k1> divide 360 by n, use that as your angle?
<FromGitter> <j8r> ha yeah, good idea!
<FromGitter> <3n-k1> if we take n=4, we have angles of 90 degrees, which would lead to the correct spacing
<FromGitter> <3n-k1> don't ask me about radians tho, i still don't understand them xd
<FromGitter> <j8r> ha snap I found a way to get a point inside the circle, not in...
<FromGitter> <3n-k1> same thing, just scale the vector to the length of the radius, right?
<FromGitter> <j8r> oh yes, I get a random number
<FromGitter> <j8r> between 0 and 360
<FromGitter> <3n-k1> make sure to use a float or float64 for better granularity
<FromGitter> <j8r> then I can use cos and sin
<FromGitter> <j8r> got it, thanks you very much :)
<FromGitter> <3n-k1> np!
<FromGitter> <j8r> I will use radians, sound to be better because being a SI unit
<FromGitter> <j8r> 2 PI = 360°
<FromGitter> <j8r> Heeyyy... `Random.rand(1_f32)` returns a Float64 :/
<FromGitter> <Blacksmoke16> is there no way to know an annotation is of a specific annotation type?
<FromGitter> <Blacksmoke16> nvm i found a work around :/
* FromGitter * Blacksmoke16 wants his better annotation support, this is a pita
<FromGitter> <3n-k1> alright y'all, time to introduce a metacompiler
<FromGitter> <3n-k1> compile a superset of crystal into regular crystal xd
<FromGitter> <Blacksmoke16> oh boy
<FromGitter> <Blacksmoke16> gl
<FromGitter> <3n-k1> yo dawg, we heard you like macros, so we put macros in your macros so you can macro while you macro
<FromGitter> <3n-k1> oh no
<FromGitter> <Blacksmoke16> thats my #2 most wanted feature ha
<FromGitter> <3n-k1> honestly i love and hate that
<FromGitter> <3n-k1> like i'd love to be able to write a compile-time yaml parser, but also i don't want this to be c++ with its compile-time raytracers
<FromGitter> <Blacksmoke16> i just want a way to be able to reuse macro code
<FromGitter> <3n-k1> m4
<FromGitter> <3n-k1> like i know that's a horrible, awful thing, but
<straight-shoota> maybe that could be a way to implement a proper REPL in Crystal :P
f1refly has joined #crystal-lang
f1reflyylmao has quit [Ping timeout: 260 seconds]
avane has quit [Quit: ZNC - https://znc.in]
avane has joined #crystal-lang
<FromGitter> <HertzDevil> we should just follow ruby and use `?` for char literals
_whitelogger has joined #crystal-lang
<FromGitter> <HertzDevil> ruby uses them for single-character strings, but if we redefine their single quotes we could redefine their `?` too
<erdnaxeli> hi, are annotations suposed to work on structs?
<FromGitter> <naqvis> yes
<FromGitter> <naqvis> You can apply annotations to ⏎ ⏎ 1) Instance and class methods ⏎ 2) Instance variables ⏎ 3) Classes, structs, enums, and modules [https://gitter.im/crystal-lang/crystal?at=5fb78137b03a464f081fc135]
<erdnaxeli> ok thanks, so I am missing something else
f1refly has quit [Ping timeout: 272 seconds]
f1refly has joined #crystal-lang
<FromGitter> <HertzDevil> i don't understand why `@[Flags]` and `@[Packed]` have to be flags instead of annotations
<FromGitter> <HertzDevil> *attributes instead of annotations
<FromGitter> <naqvis> @HertzDevil aren't they built-in annotations?
<FromGitter> <HertzDevil> or rather, why these two are the only "attributes" and the other built-in annotations aren't
<FromGitter> <asterite> attributes and annotations are the same thing, we probably meant to use the term annotation everywhere
<FromGitter> <HertzDevil> it was about `TypeNode#has_attribute?` and the corresponding internal method in `Crystal::Type`
<FromGitter> <HertzDevil> i replaced that with something else that checks for annotations instead and it didn't break the specs
<straight-shoota> Oh yeah
<straight-shoota> I suppose that `#has_attribute?` is a relic that's probably not necessary anymore
<straight-shoota> You can just use `#annotation` instead
<FromGitter> <HertzDevil> it's apparently really old, introduced in 0.6.1
tsujp has quit [Read error: Connection reset by peer]
<FromGitter> <j8r> @3n-k1 Done with your idea with angle, quite simple and works great ;)
<FromGitter> <j8r> Using Radians is as simple as Degree, sometimes even more... Don't know why we still learn degrees in school
<straight-shoota> j8r in daily use degrees is much easier to understand
<straight-shoota> b/c you're talking about whole numbers
<straight-shoota> 90° vs 1,57 rad
<straight-shoota> for scientific calculations, radians is obviously more epedient
<straight-shoota> *expedient
<FromGitter> <j8r> not sure we can consider school trigonometry as "daily use"
ua has quit [Ping timeout: 240 seconds]
ua has joined #crystal-lang
<FromGitter> <anthonyshull> is there a way to do optional named arguments?
<FromGitter> <anthonyshull> i have something like
<FromGitter> <anthonyshull> ```def foo(one : String, two : String?) ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5fb801926a738b71d352d8e7]
<FromGitter> <anthonyshull> and i want to call
<FromGitter> <Blacksmoke16> `, two : String? = nil`?
<FromGitter> <anthonyshull> ```foo(one: 1)```
<FromGitter> <Blacksmoke16> or could just have do diff overloads
<FromGitter> <Blacksmoke16> :shrug:
<FromGitter> <Blacksmoke16> and i assume you know you dont have to use named args all the time?
<FromGitter> <Blacksmoke16> `foo 1` is equivilent
<FromGitter> <anthonyshull> yeah, there are 5-6 arguments in my real function
<FromGitter> <Blacksmoke16> 👍 fair enough
<FromGitter> <anthonyshull> it's just a way of giving the user a convenience method
<FromGitter> <anthonyshull> so they don't have to construct an object
<FromGitter> <Blacksmoke16> its also possible to make it so you can *only* use named arguments
<FromGitter> <Blacksmoke16> something to keep in mind
<FromGitter> <anthonyshull> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5fb8026ca5ab47590d0ef52d]
<FromGitter> <anthonyshull> here the user doesn't pass in the postal_code
<FromGitter> <anthonyshull> but it's complaining of not having an overload that matches that func sig
<FromGitter> <Blacksmoke16> give them default values
<FromGitter> <anthonyshull> of nil, ok
andremedeiros has quit [Quit: ZNC 1.8.2 - https://znc.in]
<FromGitter> <Blacksmoke16> like i assume postal code is actually optional?
<FromGitter> <anthonyshull> yeah, the idea is that you're constructing a query that is a partial address
<FromGitter> <anthonyshull> so, two types: AddressQuery and Address
<FromGitter> <Blacksmoke16> 👍
<FromGitter> <anthonyshull> that worked, thanks!
<FromGitter> <Blacksmoke16> np
<FromGitter> <anthonyshull> we're going to be writing a CLI in 2021 and i'm angling for writing it in crystal
<FromGitter> <Blacksmoke16> nice, gl :P
f1reflyylmao has joined #crystal-lang
f1refly has quit [Ping timeout: 260 seconds]
<FromGitter> <j8r> Unrelated, I find the `en_IE.UTF-8` quite more practical than `en_US.UTF-8` for non-US folks, especially in Europe
<FromGitter> <j8r> Euro money, 24 hour, metric system :)
<FromGitter> <3n-k1> is there @j8r i'm glad it worked! that's the first time i've ever had a good idea with geometry haha
<raz> j8r: welcome to the civilized world!
<FromGitter> <j8r> raz: you use this locale too?
<raz> where we actually measure things in units of ten, rather than feet and washing machines
<raz> nah i don't, on servers it's plain old C or en_US.UTF-8 to avoid compat funkyness
<raz> and on desktop it's osx, no idea what that even uses
<raz> cupertino.UTF-8 probably
<FromGitter> <3n-k1> any chance crystal has list comprehensions?
<FromGitter> <Blacksmoke16> hm?
<FromGitter> <j8r> no need, really
<FromGitter> <j8r> use `#map`
<FromGitter> <j8r> "list incomprehensions"
<FromGitter> <3n-k1> is there a `#map` on `Hash`?
<FromGitter> <3n-k1> i should probably just rtfc on that
<FromGitter> <Blacksmoke16> `hash.each_value.map ...`
<FromGitter> <Blacksmoke16> assuming you dont need both key and value
<FromGitter> <3n-k1> `{"foo"=>"bar"}.map do |k, v|` works
<FromGitter> <Blacksmoke16> and it returns an array?
<FromGitter> <3n-k1> ```{"foo"=>"bar"}.map do |k, v| ⏎ puts "#{k}, #{v}" ⏎ end ⏎ # prints foo, bar ⏎ => [nil]``` [https://gitter.im/crystal-lang/crystal?at=5fb8314533d7764bde804953]
<FromGitter> <3n-k1> yup
<FromGitter> <Blacksmoke16> well there you go
<FromGitter> <3n-k1> time to make horrible macros
<FromGitter> <Blacksmoke16> oh boy, now what are you doing? :p
<FromGitter> <3n-k1> is there a macro method for generating a new (unused) variable name?
<FromGitter> <Blacksmoke16> oo i made something like that before
<FromGitter> <3n-k1> i'm mostly joking. i could write a list comp macro but i think that would just make it too hard to grok the code
<FromGitter> <Blacksmoke16> super hack but it worked :D
f1reflyylmao is now known as f1refly
<FromGitter> <3n-k1> honestly i think that should be part of the macro top-level. i've used languages that had something similar, was great for temp variables
<FromGitter> <Blacksmoke16> i think i did like 3 groups of like `["a","b",...].shuffle.join` LS
<FromGitter> <Blacksmoke16> and maybe one of numbers separated by `_`
<FromGitter> <3n-k1> could do a horrible c hack and use `macro_temp_index` where `index` is some macro global that you increment every time xd
<FromGitter> <Blacksmoke16> prob could also use https://crystal-lang.org/api/master/Crystal/Macros.html#run(filename,*args):MacroId-instance-method
<FromGitter> <Blacksmoke16> the calls into a crystal problem using proper stdlib random methods
<FromGitter> <3n-k1> noooooooo
<FromGitter> <3n-k1> that's too hacky for me lol
<oprypin> @3n-k1what do you mean "is there a macro method for generating a new (unused) variable name?" isn't there a direct feature for that https://crystal-lang.org/reference/syntax_and_semantics/macros/fresh_variables.html
<oprypin> Blacksmoke16, why didnt you suggest that onee 👀
<FromGitter> <3n-k1> oh hey, that's awesome, thanks!
<FromGitter> <Blacksmoke16> oh
<FromGitter> <Blacksmoke16> well shit
<FromGitter> <Blacksmoke16> i guess "globally unique" is even better than "random" :P
<oprypin> what, you gotta go and rewrite many of your macros now? 😅
<FromGitter> <3n-k1> brb using compile-time uuid generation for my variable names lmao
<FromGitter> <Blacksmoke16> ha naw, never really needed it
<oprypin> you'd think, but actually it's quite common
<FromGitter> <Blacksmoke16> only case i ran into where it would be nice is like making a mocking lib
<oprypin> when your macro generates code like `somevar = something`, that's almost always wrong and should've been `%somevar`
<oprypin> do you never generate code that happens to use a temporary variable for something?
<FromGitter> <Blacksmoke16> sorry i meant i never had a need to use fresh vars as methods names
<oprypin> for method names yea maybe it's not such an amazing idea 👀
<FromGitter> <Blacksmoke16> indeed
<straight-shoota> great for code obfuscation ^^
DeBot has quit [Quit: Crystal IRC]
asterite has quit [Quit: Bye]
jhass has quit [Quit: Bye]
straight-shoota has quit [Quit: ZNC 1.7.5 - https://znc.in]
DeBot has joined #crystal-lang
asterite has joined #crystal-lang
straight-shoota has joined #crystal-lang
jhass has joined #crystal-lang
<erdnaxeli> is it possible from a a tuple to get a new one without the first element?
<erdnaxeli> actually I just want to iterate over it but skip the first element
<erdnaxeli> I could store a flag…
<FromGitter> <3n-k1> `#map_with_index`?
<FromGitter> <Nicolab> @FromIRC oprypin `%somevar` is useful if a variable into a macro may collide with another variable (when we don't know in advance the variables defined where the macro will be called).
<jhass> It's Enumerable :)
<jhass> >> {1, 2, 3}.skip(1).to_a
<DeBot> jhass: # => [2, 3] - https://carc.in/#/r/9zb5
<FromGitter> <3n-k1> skip is handy
<erdnaxeli> jhass: thanks!
<erdnaxeli> bonus question: can I do that in a macro? (with a TupleLiteral)
<jhass> doubt it
<erdnaxeli> ok
<FromGitter> <j8r> It would be great to be able to validate docs code with the `crystal docs` cli, like `crystal docs --validate`
<FromGitter> <j8r> I know there is a lib out there
<FromGitter> <j8r> Ha yes that's it
<FromGitter> <j8r> I'll look quickly in the documentation compiler