JuliaArrays / JuliaArrays/ReadOnlyArrays.jl

Easy-to-use macro?

Open
#10 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
33
Forks
5
PR merge metrics
No merged PRs in 30d

Description

Just wondering if anybody would be interested in the following macro @bkamins @markmbaum?

A function would be fine too of course; it just feels a bit more appropriate as a macro due to the behavior as both an operation on types and on instances.

macro readonly(expr)
    esc(:($(_readonly)($expr)))
end
_readonly(::Type{A}) where {T,N,A<:AbstractArray{T,N}} = ReadOnlyArray{T,N,A}
_readonly(ar::AbstractArray) = ReadOnlyArray(ar)

The use-cases are as follows:

julia> @readonly Vector{UInt8}
ReadOnlyArray{UInt8, 1, Vector{UInt8}}

julia> @readonly Array{Float32, 3}
ReadOnlyArray{Float32, 3, Array{Float32, 3}}

julia> @readonly [1, 2, 3]
3-element ReadOnlyArray{Int64, 1, Vector{Int64}}:
 1
 2
 3

I've got it as an internal macro but I could just upstream it here if interested.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the proposed Julia @readonly macro and its _readonly dispatches. Check the existing ReadOnlyArray API and examples for type and array inputs, then add coverage showing both forms produce the demonstrated results.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
data
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.