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