[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A couple of questions about goops method parameters

From: Carlos Pita
Subject: Re: A couple of questions about goops method parameters
Date: Wed, 3 Sep 2014 15:05:30 -0300


support the "make as implementation detail" view.

Some excerpts:

It's often a good idea to define your own constructor functions, rather than call make-instance directly, because you can hide implementation details and don't have to use keyword parameters for everything. For instance, if you wanted the name and age to be required, positional parameters, rather than keyword parameters, you could define

(defun make-person (name age)
  (make-instance 'person :name name :age age))

[Notice how more convolved implementing the same using initialize would be]

In addition to this, you'd use a factory function, rather than having
the client call make-instance, to hide the CLOS nature of the type.

On Sep 3, 2014 1:47 PM, "Marko Rauhamaa" <address@hidden> wrote:
Carlos Pita <address@hidden>:

> So, a question to the experienced lispers here, a question that's not
> specifically guile or goops or scheme related. Is the make (or
> make-instance) way of constructing a new instance usually exposed to
> the final user? Or a factory function, operating at a higher level of
> abstraction, is intended to wrap the lower level, slot-fillig
> oriented, call to make? In this case, a custom initialize method
> implementation should be seen more as a complement to make than as a
> proper constructor/factory.

I saw the light and left goops behind. I built a simple system:

 * Not slot-centric but method-centric.

 * No classes, only objects.

IMO, the end result is more schemey than Goops.

It contains:

    (make-object parentage . methods)


   parentage is #f, an object or a list of objects

   methods contains procedures, or name-procedure pairs


   (define (<point> .x .y)
     (define (x) .x)
     (define (y) .y)
     (make-object #f x y))

   (let ((point (<point> 7 8)))
     (point #:y))
   => 8


reply via email to

[Prev in Thread] Current Thread [Next in Thread]