# \[ANN\] BlockEnums another enums package

**URL:** <https://discourse.julialang.org/t/ann-blockenums-another-enums-package/98591>\
**Category:** General Usage\
**Tags:** announcement\
**Created:** [May 10, 2023, 3:28am UTC](https://discourse.julialang.org/t/ann-blockenums-another-enums-package/98591 "2023-05-10T03:28:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jlapeyre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jlapeyre/32/4514_2.png) [@jlapeyre](https://discourse.julialang.org/u/jlapeyre)\
**Post date:** [May 10, 2023, 3:28am UTC](https://discourse.julialang.org/t/ann-blockenums-another-enums-package/98591/1 "2023-05-10T03:28:03Z")

</div>

[BlockEnums.jl](https://github.com/jlapeyre/BlockEnums.jl) is in the general registry.

I started this before I knew about `EnumsX.jl`, which has some overlap in features. A couple of useful features of `BlockEnums` are

- You can define additional instances of an enum after defining the enum itself. For example you can do `@blockenum MyEnum x1 x2` and then later `@add MyEnum x3 x4`.
- You can define “blocks” of integers (these can be named) and add instances in a specified block. This allows you to group instance of your enum that share a property in the same block. This is meant to mimic subtyping in some way.

---

<div class="post-metadata">

**Author:** ![jlapeyre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jlapeyre/32/4514_2.png) [@jlapeyre](https://discourse.julialang.org/u/jlapeyre)\
**Post date:** [May 10, 2023, 3:25pm UTC](https://discourse.julialang.org/t/ann-blockenums-another-enums-package/98591/2 "2023-05-10T15:25:31Z")

</div>

I should motivate the features. `BlockEnums` is supposed to supply some functionality of julia types and subtypes. I am using them in cases where you pull heterogeneous items out of a container and want to handle them without paying the cost of run-time dispatch.

```julia
julia> using BlockEnums

julia> @blockenum (Myenum, mod=MyenumMod, blocklength=10^6, numblocks=10)

# Following could also be `Base.Enum`
julia> @blockenum Myblockname Frobnosticating=1 NonFrobnosticating

julia> @addinblock Myenum Frobnosticating var1 var2
var2::Myenum = 2

julia> @addinblock Myenum NonFrobnosticating var3 var4
var4::Myenum = 1000002

julia> inblock(var3, NonFrobnosticating)
ERROR: UndefVarError: `var3` not defined

julia> inblock(MyenumMod.var3, NonFrobnosticating)
true

julia> inblock(MyenumMod.var1, NonFrobnosticating)
false

```
