Skip to content

Macro to import all variant names except the listed.  #64

@weinbe58

Description

@weinbe58

Typically there should only be a small number of name collisions when defining multiple ADT's hence a better semantic for the import macros would be to import all except a list which you specify.

Take the Scalar and Waveform ADT's I am using.

@adt ScalarLang begin
    Scalar(::RealLang)
    Negative(::ScalarLang)

    struct Default
        var::RealLang
        value::Float64
    end

    struct Reduce
        head::Symbol
        literal::Float64
        args::Dict{ScalarLang,Int}
    end

    struct Slice
        duration::ScalarLang
        Interval::ScalarLang
    end

    struct Interval
        first::ScalarLang
        last::ScalarLang
    end
end


@adt WaveformLang begin
    Negative(::WaveformLang) # Always try to move outside of over operations
    Append(::Vector{WaveformLang})

    # throw error when composing with this variant type
    struct Pad
        waveform::WaveformLang
        alignment::AlignmentOption
        value::PaddingValue
    end

    struct Name
        waveform::WaveformLang
        name::String
    end

    struct Add
        lhs::WaveformLang
        rhs::WaveformLang
    end

    struct Scale
        waveform::WaveformLang
        scale::ScalarLang
    end

    struct Slice
        waveform::WaveformLang
        interval::ScalarLang
    end

    struct Smooth
        waveform::WaveformLang
        kernel::KernelType
    end

    struct Instruction
        shape::ShapeType
        duration::ScalarLang
    end
end

The only collisions I have are Slice and Negative Hence a semantic like:

@use_all_except WaveformLang: Slice, Negative
@use_all_except ScalarLang: Slice, Negative

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions