This is the mail archive of the
guile@sourceware.cygnus.com
mailing list for the Guile project.
Re: GOOPS questions
- To: Nicolas dot Neuss at IWR dot Uni-Heidelberg dot De
- Subject: Re: GOOPS questions
- From: Marius Vollmer <mvo at zagadka dot ping dot de>
- Date: 24 Nov 1999 22:57:11 +0100
- Cc: guile at sourceware dot cygnus dot com
- References: <199911241727.JAA23286@iris.ica3.uni-stuttgart.de>
niko@iris.ica3.uni-stuttgart.de (Niko Neuss) writes:
> Hello, all of you.
>
> Recently I've started to use GOOPS, and it works quite fine (I also
> switched from my old SGI to a Powerbook with LINUXPPC, and things work
> much smoother now). It is astonishing how much nicer things can be
> formulated using OO style, and Guile is much more fun now.
Yes, I agree. Goops is really great.
> 1) I have defined an object to administrate a list of data fields. The
> basic class looks as follows:
>
> (define-class <container> ()
> (sizes #:accessor my-sizes #:init-keyword #:sizes)
> (allocs #:accessor my-allocs #:init-keyword #:allocs))
>
> I would like to have an initialization of this object which looks
> like:
You can do this by defining a method on the "initialize" generic
function. This is somewhat like defining a constructor in C++, if you
allow me that comparison.
(define-method initialize ((c <container>) args)
;; first initializes the instance from the args
(next-method)
;; and then tweak it into shape
(set! (my-allocs c) (make-list (length (my-sizes c)) 0)))
[BTW, anyone knows why next-method doesn't take arguments?]
After that,
(define x (make <container> #:sizes '(10 5)))
will behave as you want it to.
> 3) And finally: why doesn't one use the simpler notation ":accessor",
> ... (as in CLOS) instead of "#:accessor", ...?
You can use the simpler notation after doing
(read-set! keywords 'prefix)
at the top-level.
This is actually a `reader' issue and has nothing to do with GOOPS.
It's a question of how keywords are recognized in the source code.
The form `#:keyword' is always recognized as a keyword, while
`:keyword' is normally interpreted as a symbol. This is because
`:keyword' is a legal R5RS symbol and we didn't want to deviate from
the standard in this regard. But you can switch back to the more
convenient form, so this is not a great loss. However, I think we
should have a more, ahem, disciplined way of controlling the
syntax-variants that the Guile reader accepts. I think the timing of
read-set! with respect to compilation, etc is not well defined.
> P.S.: My mail server in Heidelberg is blocked by ORBS and therefore
> also by MAILER-DAEMON@sourceware.cygnus.com. Please reply to
> <Nicolas.Neuss@IWR.Uni-Heidelberg.De>. I hope my sysadmins will fix
> the problem soon.
You could also force your From: header in the mean-time or set a
Reply-To: header.
- Marius
--
char p[]="~(sS\020d%\"\033t\f\026Of0|\nPy:*>h\020w76\030V[G3ZM\035[N"; main(){
int i,j,t;for(i=0;p[i++];){t=*p;for(j=1;p[j];)t=(t*i+p[j++])%127;putchar(t);}}