Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 19:53
    straight-shoota synchronize #11207
  • 17:04
    straight-shoota synchronize #11139
  • 17:04
    straight-shoota synchronize #11207
  • 17:02
    straight-shoota synchronize #11297
  • 17:02
    straight-shoota synchronize #11207
  • 12:49
    straight-shoota closed #10889
  • 12:49
    straight-shoota closed #6498
  • 12:44
    straight-shoota closed #10377
  • 12:43
    straight-shoota closed #11265
  • 12:43
    straight-shoota closed #4704
  • 12:43
    straight-shoota closed #11262
  • 12:43
    straight-shoota closed #11253
  • 08:06
    straight-shoota synchronize #11343
  • 07:58
    straight-shoota closed #11344
  • 07:58
    straight-shoota closed #9519
  • 07:57
    straight-shoota synchronize #11289
  • 07:57
    straight-shoota synchronize #11325
  • 07:56
    straight-shoota synchronize #11321
  • 07:55
    straight-shoota synchronize #11288
  • 07:55
    straight-shoota synchronize #10889
Ary Borenszweig
@asterite
Makes sense. Yeah, maybe you get decent fps in debug builds
mfiano
@mjfiano:matrix.org
[m]
Rust's compiler is pretty slow and their gamedev community seems to be really ramping up since the last couple years, and the compiler was about 3x slower a few years ago when it first started picking up.
Though I hear they are trying to leverage dynamic runtime dispatch more to account for all the monomorphism eating compile times.
Does crystal use boehm?
Ary Borenszweig
@asterite
Interesting. But I know that Rust has modular compilation, so maybe it's slow the first time? No idea how well that's optimized
Yes, it uses boehm, but just because it works out of the box without us having to do much work. Crystal could use a different GC, eventually
mfiano
@mjfiano:matrix.org
[m]
I hear it's slow because the transitive dependency graph often contains many different versions of the same libraries, and all their functions are monomorphized. I'm not sure if it does DCE or not for this though.
1 reply
Think it's more a case of, the language has a large library ecosystem and encourages lots of re-use, plus fundamental monomorphic behavior, over a slow compiler. Can't really compare it to Crystal in either regard.
yet, anyway
Ary Borenszweig
@asterite
I know oprypin has written some games, also I think in Windows
mfiano
@mjfiano:matrix.org
[m]
Does Crystal have concurrent hash tables?
Benjamin Wade
@RespiteSage
Someone may have implemented them, but I don't know.
mfiano
@mjfiano:matrix.org
[m]
Would like to see a lockless one with CAS or something
That has been a huge complaint with my Lisp work anyway
Benjamin Wade
@RespiteSage
I feel like I constantly have this question, but is there a way to access the actual, compile-time type of a generic type within a class instantiation but not in a method?
Like
class Indigent(T)
  {% puts T %}
end

a = Indigent(Int32).new
Except it actually works.
George Dietrich
@Blacksmoke16
idt because T is only specific to an instance
Benjamin Wade
@RespiteSage
Hm... Okay.
I was wanting to set constants based on what type it is (specifically, MIN/MAX).
I bet I could do those as getters and set them in the initializer, though.
Ary Borenszweig
@asterite
Constants will be inside Indigent, not Indigent(Int32)
That is, you can't have constants have different values depending on T
1 reply
Plus you can't do Indigent(Int32)::MAX (I think that doesn't even parse)
Andrius Chamentauskas
@andriusch

Hello, I have this code:

class Animal
end

class Cat < Animal
  def meow
    puts "meow!"
  end
end

class Dog < Animal
  def woof
    puts "woof!"
  end
end

animals = Hash(Animal.class, Hash(Int32, Animal)).new { |h, k| h[k] = Hash(Int32, Animal).new }
animals[Cat][1] = Cat.new
animals[Dog][1] = Dog.new

animals[Dog][1].as(Dog).woof
animals[Cat][1].as(Cat).meow

dogs = animals[Dog].as(Hash(Int32, Dog))

and I'm getting an error on the last line:

 23 | dogs = animals[Dog].as(Hash(Int32, Dog))
             ^
Error: can't cast Hash(Int32, Animal) to Hash(Int32, Dog)

I don't understand why casting an element in the hash works, but casting the whole hash doesn't? Are there alternatives to what I'm trying to achieve (essentially index objects by type & by id)?

mfiano
@mjfiano:matrix.org
[m]
straight-shoota: Why does Shardbox have roughly 1/6 of the shards as some of the other databases? Yours is my favorite still though
George Dietrich
@Blacksmoke16
@mjfiano:matrix.org shardbox is manually curated, the others scrape github/gitlab and stuff
mfiano
@mjfiano:matrix.org
[m]
Ah I see.
George Dietrich
@Blacksmoke16
@andriusch because how would that work if the hash also contained a cat?
and because is typed as Animal that would be possible
Benjamin Wade
@RespiteSage
@andriusch It has to do with how generic types are implemented in Crystal. Other people are more able to explain why, but the basic idea is that even if T "inherits" from U, A(T) does not inherit from A(U).
In this particular case, you could use dogs = animals[Dog].transform_values &.as(Dog) on your last line.
George Dietrich
@Blacksmoke16
whats the end goal of this? what are you wanting to do?
Andrius Chamentauskas
@andriusch
ah got it, makes sense that Hash(Int32, Dog) < Hash(Int32, Cat) is not true
I want to store objects based on their type & id in a hash
all objects would inherit from some class, so it made sense to me to use Hash(Animal.class, Hash(Int32, Animal)) as type definition
From IRC (bridge bot)
@FromIRC
<riza> if you're using ints as keys, why not an array?
<riza> Hash(Animal.class, Array(Animal))
George Dietrich
@Blacksmoke16
and do what with this hash? like whats the end goal?
Andrius Chamentauskas
@andriusch
I don't want to use array since ids are not sequential, I don't think array would solve my problem though
George Dietrich
@Blacksmoke16
are the ids not related to the instance?
like cat.id
Andrius Chamentauskas
@andriusch
not exactly, more like each id can have multiple types of objects associated to it
e.g. an object with id = 1 can have a cat & a dog associated to it
object with id = 2 only has a cat
while object with id = 3 has an opposum
George Dietrich
@Blacksmoke16
would it be easier to use a struct instead of a hash, then you could give a name to these IDs, with getters to get the related animals?
Andrius Chamentauskas
@andriusch
once the objects are stored I want to be able to retrieve:
an object based on type & id
all objects based on type
there could potentially be >100 type of objects, I don't really want to define 100 properties on struct
and same for ids