Skip to content
Bruce Mitchener edited this page Jan 6, 2014 · 1 revision

ISSUE: ISA PROTOCOL

REVISION HISTORY:

STATUS: open

RELATED ISSUES:

CATEGORY: change

PROBLEM DESCRIPTION:

Users are forced to create their own factory protocol for each class.

PRINCIPLES:

  • make refactoring easy.
  • make interface changes minimally affect client code.
  • make things convenient.
  • make things simple.
  • support incremental development.
  • features should be orthogonal as possible.
  • pay as you go.

PROPOSAL:

change ISA to be a generic function. the default ISA method allocates the object and then calls init with the ISA arguments:

(dm isa (c|<class> args|... => <any>)
  (let x (alloc c))
  (apply init x args)
  x)

isa is required to return a general instance of its first parameter's specializer.

introduce an initialization protocol based around an INIT generic function. the default init method does nothing:

(dm init (x args|...))

users can override the default INIT and are responsible for first calling next-method.

EXAMPLES:

isa

(isa <vec> len: 10)

isa delegation

(dc <seq> (<col>)) ...
(dm isa (c|<seq> len:0|<int> fill:#f => <seq>)
  (isa <lst> len: len fill: fill))

init

(dc <buf> (<flat>))
  (dp buf-data (x|<buf> => <vec>))
(dm init (x|<buf> len:0|<int> capacity:#f|(false-or <int>) fill:#f => <buf>)
  (next-method)
  (let cap (or capacity (if len (next-power-of-two len) 0)))
  (set (buf-data x) (isa <vec> len: cap fill: fill)))

QUESTIONS:

should keys be allowed to be any objects? if not, then properties must be given optional keys.

is this too complicated to implement?

does this reduce the need for lazy property initialization?

RATIONALE:

COST TO IMPLEMENTORS:

COST TO USERS:

PERFORMANCE IMPACT:

DOCUMENTATION IMPACT:

IMPLEMENTATION NOTES:

FUTURE FEATURES: