Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 06:22
    HertzDevil synchronize #10711
  • 05:25
    HertzDevil synchronize #10711
  • 04:50
    HertzDevil labeled #11377
  • 04:50
    HertzDevil labeled #11377
  • 04:50
    HertzDevil opened #11377
  • 02:24
    caspiano labeled #11376
  • 02:24
    caspiano opened #11376
  • Oct 27 23:00
    darkstego synchronize #11370
  • Oct 27 20:36
    straight-shoota milestoned #11369
  • Oct 27 20:36
    straight-shoota milestoned #11349
  • Oct 27 20:35
    straight-shoota milestoned #11139
  • Oct 27 20:34
    straight-shoota milestoned #10590
  • Oct 27 20:33
    straight-shoota milestoned #11363
  • Oct 27 20:21
    darkstego reopened #11370
  • Oct 27 19:46
    oprypin synchronize #11352
  • Oct 27 19:43
    oprypin closed #11357
  • Oct 27 17:36
    straight-shoota closed #11364
  • Oct 27 17:30
    darkstego closed #11370
  • Oct 27 15:20
    darkstego synchronize #11370
  • Oct 27 14:30
    HertzDevil edited #11218
George Dietrich
@Blacksmoke16
mfiano
@mjfiano:matrix.org
[m]
Oh that issue surprised me...
In Lisp a macro can evaluate at compile time arbitrary pieces of code, even methods that are shared with other macros or runtime code.
I did not know Crystal couldn't do that
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