Don't worry, I'm not re-opening the currently debated issue . It occurred 
to me a while ago that it should be possible to support this feature 
without any changes to the language itself. 

Instead I've created the macros `@_abstract`, `@_type`, and `@_immutable`. 
The idea is that `@_abstract` does two things:

   1. It adds the fields to a global registry and creates an abstract class 
   with the given name
   2. When a @_type or @_immutable is created, it copies the fields from 
   the abstract registry and adds its own


The current working code can be found at: 
https://github.com/abeschneider/AbstractFields.jl

A quick example:

@_abstract Point begin
  x::Float64
  y::Float64
end

@_type 3DPoint Point begin
  z::Float64
end

# create a 3DPoint (abstract's values get filled first)
point = 3DPoint(1.0, 1.0, 1.0)


One of the main advantages of using these macros is that you know if you 
have a function that takes a `Point`, it will have `x` and `y` defined. As 
has been pointed out, this isn't strictly necessary, as you could provide 
an interface with `getx`, `gety`, `setx`, `sety` for each subclass of 
`Point`. However, this can result in a lot of extra boilerplate code.


Anyways, I'm not sure if this is useful/interesting to anyone else, but 
it's something I've wanted for my own code.

Reply via email to