Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 03:58
    darkstego opened #11353
  • 02:41
    darkstego synchronize #11352
  • 01:02
    HertzDevil synchronize #11350
  • Oct 23 20:42
    darkstego opened #11352
  • Oct 23 18:43
    straight-shoota labeled #11351
  • Oct 23 18:43
    straight-shoota labeled #11351
  • Oct 23 18:07
    FnControlOption opened #11351
  • Oct 23 13:26
    HertzDevil edited #11350
  • Oct 23 12:16
    HertzDevil labeled #11350
  • Oct 23 12:16
    HertzDevil labeled #11350
  • Oct 23 12:16
    HertzDevil labeled #11350
  • Oct 23 12:16
    HertzDevil opened #11350
  • Oct 23 09:52
    HertzDevil synchronize #11298
  • Oct 23 09:49
    HertzDevil synchronize #11298
  • Oct 23 09:37
    HertzDevil synchronize #11298
  • Oct 23 09:30
    HertzDevil synchronize #11298
  • Oct 23 09:27
    HertzDevil synchronize #11298
  • Oct 23 08:50
    HertzDevil edited #11348
  • Oct 23 08:34
    HertzDevil edited #11348
  • Oct 23 08:33
    HertzDevil labeled #11349
George Dietrich
@Blacksmoke16
its a pita
because of that missing piece that you cant define reusable macro code
i.e. that you could use in two separate macros
From IRC (bridge bot)
@FromIRC
<riza> ^
George Dietrich
@Blacksmoke16
you can call a macro from a macro, but that just is moreso nested expansion, which doens't help in this case
From IRC (bridge bot)
@FromIRC
<riza> @Blacksmoke16 what do you mean fresh variables can be "keyed like a hash"
From IRC (bridge bot)
@FromIRC
<riza> hm, I'm not instantly sure how that would be useful, but it's neat to see regardless
George Dietrich
@Blacksmoke16
main use case afaik is if you want to create them in a loop
otherwise if you just did %key, it would be overridden on each iteration
mfiano
@mjfiano:matrix.org
[m]
I see. Also I really like Crystal and I don't mean to sound like a Lisp snob, because there are plenty of them. Lisp is nice, but it's too dynamic for some tasks...which is one thing that makes its macro system powerful. Every phase of the compiler can be invoked by any other phase by the user, which means macros can be expanded at runtime and all that. It's a mind!@#$, really.
From IRC (bridge bot)
@FromIRC
<riza> Yeah I suppose that could be a useful way to replace https://github.com/mosquito-cr/mosquito/blob/master/src/mosquito/base.cr#L10-L12
<riza> or several places where the finished macro is used
George Dietrich
@Blacksmoke16
use an annotation and iterate over types that have it
then could build a hash literal at build time or whatever you need
or what's that method doing actually?
cant just build a hash of Mosquito::Job.class => Mosquito::Job?
From IRC (bridge bot)
@FromIRC
<riza> Mosquito::Job.class.to_s => Mosquito::Job.class
George Dietrich
@Blacksmoke16
it's been a while since i been in the code, what's this do again?
From IRC (bridge bot)
@FromIRC
<riza> when a job is popped out of redis, it allows the runner to do a lookup in that hash to convert the job name in redis to a reference to the job class
George Dietrich
@Blacksmoke16
can you just use the FQN of the job class as the key?
oh wait
this is so that you can go from a string from redis to an actual type
should feature request Foo::Bar.class.from_json %("Foo::Bar") :P
mfiano
@mjfiano:matrix.org
[m]
Anyway, I have to try to erase my complicated Lisp macro memory to learn the basics of Crystal, else I'm going to be violating DRY a lot in this practice project.
George Dietrich
@Blacksmoke16
most of the time you dont need them either
mfiano
@mjfiano:matrix.org
[m]
(which I hope to evolve into more than a practice project as the basis for what I want to use Crystal for)
The alternative is I just DRY without care and figure out if a macro will make it more maintainable later when I'm more accustomed.
🤷‍♂️
From IRC (bridge bot)
@FromIRC
<riza> my honest advice is to avoid macros where possible (in both lisp and crystal). they're an amazing toolset when you need it but most problems can be solved elegantly without.
<riza> over-macro-ing makes code hard to maintain
mfiano
@mjfiano:matrix.org
[m]
I am torn. While I do agree, what has kept Lisp a viable language since the 50's is that new language features and are just a macro away. There's only so much you can do without creating new compiler extensions (macros).
From IRC (bridge bot)
@FromIRC
<riza> Can these fresh variable hashes be iterated, or do you have to keep the list of keys around
<riza> keep/pass
George Dietrich
@Blacksmoke16
hash was maybe the wrong work
its more of just a means of allowing the same fresh var name to hold multiple values based on another unique identifier
so you would need to keep the "keys" around in order to access the same value, which could just be the idx of something as that can't change
From IRC (bridge bot)
@FromIRC
<riza> yeah makes sense
<riza> it looks like it's probably just a substitution layer where %var{name} when name="test" just gets fresh'd to %var-test or something
George Dietrich
@Blacksmoke16
yea prob something along those lines
mfiano
@mjfiano:matrix.org
[m]
I am feeling dumb that I can't figure this out, but can someone show me an example of defining an == method that takes 2 Float64's at the module level? For some reason the compiler thinks I'm trying to define a setter method and yells about syntax...
From IRC (bridge bot)
@FromIRC
<riza> @mjfiano can you post what you've got?
mfiano
@mjfiano:matrix.org
[m]
module MyModule
  def ==(x : Float64, y : Float64) # setter method '==' cannot have more than one argument
    ...
  end
end
George Dietrich
@Blacksmoke16
i this module included into a custom type?
mfiano
@mjfiano:matrix.org
[m]
No
George Dietrich
@Blacksmoke16
oh, got an example of how this is to be used then?
From IRC (bridge bot)
@FromIRC
<riza> I don't know if the == operator can be overloaded that way
George Dietrich
@Blacksmoke16
it cant
normally it would be 1 argument that you compare with self