Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 08:23
    caspiano edited #10531
  • Dec 08 23:04
    HertzDevil edited #12623
  • Dec 08 22:57
    Blacksmoke16 edited #9745
  • Dec 08 22:57
    Blacksmoke16 labeled #9745
  • Dec 08 22:57
    Blacksmoke16 labeled #9745
  • Dec 08 22:54
    HertzDevil labeled #12828
  • Dec 08 22:54
    HertzDevil labeled #12828
  • Dec 08 22:54
    HertzDevil opened #12828
  • Dec 08 22:34
    straight-shoota edited #12827
  • Dec 08 22:32
    straight-shoota edited #12827
  • Dec 08 22:29
    straight-shoota labeled #12827
  • Dec 08 22:29
    straight-shoota labeled #12827
  • Dec 08 22:29
    straight-shoota opened #12827
  • Dec 08 22:15
    straight-shoota closed #12814
  • Dec 08 17:12
    straight-shoota assigned #12814
  • Dec 08 17:12
    straight-shoota assigned #12813
  • Dec 08 17:12
    straight-shoota assigned #12809
  • Dec 08 17:12
    straight-shoota assigned #12802
  • Dec 08 17:12
    straight-shoota assigned #12797
  • Dec 08 17:12
    straight-shoota assigned #12664
azurelmao
@azurelmao
So in order to skip past indexes I first have to fill the array with some value?
George Dietrich
@Blacksmoke16
there's another overload that allows you to initialize each index to some value if you want
azurelmao
@azurelmao
Yeah ik, I had just hoped there would be a more convienent way to do it
George Dietrich
@Blacksmoke16
more convenient how?
or backing up, what end result are you wanting?
azurelmao
@azurelmao
It's just that I have a class which adds itself to a class var on init
def initialize(@id)
    if id > 0
      @@item_list.insert(@id, self)
    end
  end
so now I have to check whether the id is 0
in order to fill the array
George Dietrich
@Blacksmoke16
are they instantiated in order? i.e. is it possible the first instance has an @id of 10 and the next 1 or is it always going to go in order?
0, 1, 3, ...
0, 1, 2, ...*
azurelmao
@azurelmao
they won't be in order
George Dietrich
@Blacksmoke16
Hash(Int32, self).new then?
azurelmao
@azurelmao
Oh, I haven't thought of that
I'll try it
George Dietrich
@Blacksmoke16
seems like a more reasonable data model if you just want to store objects with a numerical key
azurelmao
@azurelmao

btw, this is unrelated to my previous question I'm just curious, but is there a literal for object instantiation? Something like:

foo = Foo{id: 1}

Which would bypass the initialize method and let you assign the properties by hand

George Dietrich
@Blacksmoke16
no
azurelmao
@azurelmao
I see
George Dietrich
@Blacksmoke16
unless you make everything nilable and do something like:
foo = Foo.new
foo.id = 1
...
but ofc, having a proper constructor is usually the better way
i.e. Foo.new 1 or Foo.new id: 1
azurelmao
@azurelmao
I usually avoid Nilable types, because of the trouble they cause
Anyways, thank you for helping me!
George Dietrich
@Blacksmoke16
np
From IRC (bridge bot)
@FromIRC
<SamantazFox> For anyone interested: I've been doing my Advent of Code in Crystal this year ^^ https://github.com/SamantazFox/AoC-2022
From IRC (bridge bot)
@FromIRC
<riza> SamantazFox: there are a bunch of us, the Discord server has an aoc channel. But I'm over here at github.com/robacarp/advent_of_code/
<riza> a couple more links from the discord https://github.com/hovsater/aoc-crystal
<riza> there are probably many others
<riza> oh we have a leaderboard too....uuuummm
re:fi.64 🏳️‍🌈
@refi64:linuxcafe.chat
[m]
Note that mine is not actually in Crystal 😅
From IRC (bridge bot)
@FromIRC
<riza> oh whoops
<riza> i like that they're on sr.ht
<riza> i keep meaning to set up a gittea or something but ...
re:fi.64 🏳️‍🌈
@refi64:linuxcafe.chat
[m]
sr.ht is definitely pretty nice
Hasnep
@hasnep:matrix.org
[m]
Hi, does anyone know if there's a shard or some stdlib functionality to replicate Python's pydantic library? i.e. parsing JSON to a class
Hasnep
@hasnep:matrix.org
[m]
Perfect, thanks!
Maurizio De Santis
@mdesantis
hello! I'm confused by type aliases. I can't see why this works:
alias DeviceName = String
alias DeviceFile = Int32
alias DeviceDir = Hash(DeviceName, DeviceFile | DeviceDir)

pp Hash(DeviceName, DeviceDir).new
pp Hash(DeviceName, DeviceFile).new
#=> {}
#=> {}
but this doesn't:
alias DeviceName = String
alias DeviceFile = Int32
alias DeviceDir = Hash(DeviceName, DeviceFile | DeviceDir)

pp Hash(DeviceName, DeviceDir).new
pp Hash(DeviceName, DeviceFile).new
pp DeviceDir.new
#=>  21 | pp DeviceDir.new
#=>                    ^--
#=> Error: undefined method 'new' for DeviceDir.class
if DeviceDir is an alias of Hash(DeviceName, DeviceFile | DeviceDir), why can't I call .new on it?
ShalokShalom
@ShalokShalom
hi there
is there somebody who has tried to run Crystal on the GraalVM?
It has support
George Dietrich
@Blacksmoke16

related: crystal-lang/crystal#5155

recursive aliases are usually frowned upon, so might want to go to plan b

1 reply