[erlang-questions] programming tip: a note on encapsulation

Richard O'Keefe ok@REDACTED
Wed Nov 18 23:08:58 CET 2009


On Nov 18, 2009, at 9:56 PM, Joe Armstrong wrote:

> Here's a little programming technique I discovered yesterday, which I
> rather like.

It looks a whole lot like the way people used to do "objects" in T.
    (define (make-my-object ....)
      (lambda (Selector)
        (case Selector
          (field ....)
          (method (lambda (....) ....))
          ....))))
with the equivalent of
     foo = new MyObject(...);
     foo.method(x, y)
     foo.field
being
     (let ((Foo (make-my-object ....)))
       ((Foo 'method) X Y)
       (Foo 'field)

It looks as though "Joe hates OO" may have to be rewritten!





More information about the erlang-questions mailing list