It is also possible to use @type and @immutable, although the macros are
slightly harder to define.
macro lit_str(s); Symbol(s); end
macro lit"type"(x)
...
end
macro lit"immutable"(x)
...
end
@type ...
@immutable ...
On Saturday, October 29, 2016 at 6:16:37 PM UTC-4, Jake Rosoman wrote:
>
> Or even @Type and @Immutable
>
> On Sunday, October 30, 2016 at 11:12:47 AM UTC+13, Jake Rosoman wrote:
>>
>> Good idea! I think more self explanatory naming would be @deftype and
>> @defimmutable though
>>
>> On Wednesday, October 26, 2016 at 4:00:13 AM UTC+13, Cedric St-Jean wrote:
>>>
>>> Types are central to Julia programming, but the built-in `type` and
>>> `immutable` definitions can be cumbersome to write. QuickTypes.jl
>>> <https://github.com/cstjean/QuickTypes.jl> provides two alternative
>>> macros, *@qtype* and *@qimmutable, *with a more convenient syntax:
>>>
>>> Pkg.add("QuickTypes") # to install
>>> using QuickTypes
>>>
>>> @qtype Wall(width, height)
>>>
>>> # Optional and keyword-arguments
>>> @qtype Cat(name, age::Int, nlegs=4; species="Siamese")
>>>
>>> # Parametric type
>>> @qtype Pack{T}(animals::Vector{T})
>>>
>>> # Inheritance
>>> abstract Tree
>>> @qtype Maple(qty_syrup::Float64) <: Tree
>>>
>>> # Immutables work the same way
>>> @qimmutable SquaredNumber(x2::Number)
>>>
>>>