Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 07:55
    Tamnac opened #13026
  • Jan 28 21:02
    Blacksmoke16 labeled #13025
  • Jan 28 21:02
    Blacksmoke16 labeled #13025
  • Jan 28 21:02
    Blacksmoke16 labeled #13024
  • Jan 28 21:02
    Blacksmoke16 labeled #13024
  • Jan 28 18:45
    asterite opened #13025
  • Jan 28 16:23
    meatball133 synchronize #13024
  • Jan 28 15:53
    meatball133 edited #13024
  • Jan 28 15:51
    meatball133 opened #13024
  • Jan 28 15:10
    meatball133 ready_for_review #13008
  • Jan 28 13:24
    straight-shoota closed #13014
  • Jan 28 02:34
    Blacksmoke16 labeled #13023
  • Jan 28 02:19
    cyangle labeled #13023
  • Jan 28 02:19
    cyangle opened #13023
  • Jan 28 00:41
    devnote-dev labeled #13022
  • Jan 28 00:41
    devnote-dev opened #13022
  • Jan 27 23:05
    straight-shoota labeled #13021
  • Jan 27 23:05
    straight-shoota labeled #13021
  • Jan 27 23:05
    straight-shoota labeled #13021
  • Jan 27 23:05
    straight-shoota labeled #13021
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