[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
guile/guile-oops goops-tutorial.texi goops.texi
From: |
Mikael Djurfeldt |
Subject: |
guile/guile-oops goops-tutorial.texi goops.texi |
Date: |
Fri, 09 Mar 2001 17:27:04 -0800 |
CVSROOT: /cvs
Module name: guile
Changes by: Mikael Djurfeldt <address@hidden> 01/03/09 17:27:04
Modified files:
guile-oops : goops-tutorial.texi goops.texi
Log message:
* goops-tutorial.texi, goops.texi: Updated to reflext new
define-method syntax.
CVSWeb URLs:
http://subversions.gnu.org/cgi-bin/cvsweb/guile/guile-oops/goops-tutorial.texi.diff?r1=1.7&r2=1.8
http://subversions.gnu.org/cgi-bin/cvsweb/guile/guile-oops/goops.texi.diff?r1=1.12&r2=1.13
Patches:
Index: guile/guile-oops/goops-tutorial.texi
diff -u guile/guile-oops/goops-tutorial.texi:1.7
guile/guile-oops/goops-tutorial.texi:1.8
--- guile/guile-oops/goops-tutorial.texi:1.7 Tue Jan 4 07:12:39 2000
+++ guile/guile-oops/goops-tutorial.texi Fri Mar 9 17:27:04 2001
@@ -3,7 +3,7 @@
@c
@c STk Reference manual (Appendix: An Introduction to STklos)
@c
address@hidden Copyright © 1993-1999 Erick Gallesio - I3S-CNRS/ESSI
<address@hidden>
address@hidden Copyright © 1993-1999, 2001 Erick Gallesio - I3S-CNRS/ESSI
<address@hidden>
@c Permission to use, copy, modify, distribute,and license this
@c software and its documentation for any purpose is hereby granted,
@c provided that existing copyright notices are retained in all
@@ -633,9 +633,9 @@
@lisp
(define-generic G)
-(define-method G ((a <integer>) b) 'integer)
-(define-method G ((a <real>) b) 'real)
-(define-method G (a b) 'top)
+(define-method (G (a <integer>) b) 'integer)
+(define-method (G (a <real>) b) 'real)
+(define-method (G a b) 'top)
@end lisp
The @code{define-generic} call defines @var{G} as a generic
@@ -652,7 +652,7 @@
@cindex parameter specializers
@lisp
-(define-method G ((a <integer>) (b <top>)) 'integer)
+(define-method (G (a <integer>) (b <top>)) 'integer)
@end lisp
Now, let us look at some possible calls to generic function @var{G}:
@@ -672,10 +672,10 @@
applicability of a method. Suppose we declare now
@lisp
-(define-method G ((a <integer>) (b <number>)) 'integer-number)
-(define-method G ((a <integer>) (b <real>)) 'integer-real)
-(define-method G ((a <integer>) (b <integer>)) 'integer-integer)
-(define-method G (a (b <number>)) 'top-number)
+(define-method (G (a <integer>) (b <number>)) 'integer-number)
+(define-method (G (a <integer>) (b <real>)) 'integer-real)
+(define-method (G (a <integer>) (b <integer>)) 'integer-integer)
+(define-method (G a (b <number>)) 'top-number)
@end lisp
In this case,
@@ -697,9 +697,9 @@
the special form @code{next-method}. Consider the following definitions
@lisp
-(define-method Test ((a <integer>)) (cons 'integer (next-method)))
-(define-method Test ((a <number>)) (cons 'number (next-method)))
-(define-method Test (a) (list 'top))
+(define-method (Test (a <integer>)) (cons 'integer (next-method)))
+(define-method (Test (a <number>)) (cons 'number (next-method)))
+(define-method (Test a) (list 'top))
@end lisp
With those definitions,
@@ -719,7 +719,7 @@
two complexes could be
@lisp
-(define-method new-+ ((a <complex>) (b <complex>))
+(define-method (new-+ (a <complex>) (b <complex>))
(make-rectangular (+ (real-part a) (real-part b))
(+ (imag-part a) (imag-part b))))
@end lisp
@@ -731,7 +731,7 @@
(define-generic new-+)
(let ((+ +))
- (define-method new-+ ((a <complex>) (b <complex>))
+ (define-method (new-+ (a <complex>) (b <complex>))
(make-rectangular (+ (real-part a) (real-part b))
(+ (imag-part a) (imag-part b)))))
@end lisp
@@ -749,24 +749,25 @@
(let ((+ +))
- (define-method new-+ ((a <real>) (b <real>)) (+ a b))
+ (define-method (new-+ (a <real>) (b <real>)) (+ a b))
- (define-method new-+ ((a <real>) (b <complex>))
+ (define-method (new-+ (a <real>) (b <complex>))
(make-rectangular (+ a (real-part b)) (imag-part b)))
- (define-method new-+ ((a <complex>) (b <real>))
+ (define-method (new-+ (a <complex>) (b <real>))
(make-rectangular (+ (real-part a) b) (imag-part a)))
- (define-method new-+ ((a <complex>) (b <complex>))
+ (define-method (new-+ (a <complex>) (b <complex>))
(make-rectangular (+ (real-part a) (real-part b))
(+ (imag-part a) (imag-part b))))
- (define-method new-+ ((a <number>)) a)
+ (define-method (new-+ (a <number>)) a)
- (define-method new-+ () 0)
+ (define-method (new-+ ) 0)
- (define-method new-+ args (new-+ (car args)
- (apply new-+ (cdr args)))))
+ (define-method (new-+ . args)
+ (new-+ (car args)
+ (apply new-+ (cdr args)))))
(set! + new-+)
@end lisp
@@ -781,25 +782,25 @@
implement the dyadic addition. The fifth method says that the addition
of a single element is this element itself. The sixth method says that
using the addition with no parameter always return 0. The last method
-takes an arbitrary number of address@hidden third parameter of
-a @code{define-method} is a parameter list which follow the conventions
-used for lambda expressions. In particular it can use the dot notation
-or a symbol to denote an arbitrary number of parameters}. This method
-acts as a kind of @code{reduce}: it calls the dyadic addition on the
address@hidden of the list and on the result of applying it on its rest. To
-finish, the @code{set!} permits to redefine the @code{+} symbol to our
-extended addition.
+takes an arbitrary number of address@hidden parameter list for
+a @code{define-method} follows the conventions used for Scheme
+procedures. In particular it can use the dot notation or a symbol to
+denote an arbitrary number of parameters}. This method acts as a kind
+of @code{reduce}: it calls the dyadic addition on the @emph{car} of the
+list and on the result of applying it on its rest. To finish, the
address@hidden permits to redefine the @code{+} symbol to our extended
+addition.
@sp 3
To terminate our implementation (integration?) of complex numbers, we can
redefine standard Scheme predicates in the following manner:
@lisp
-(define-method complex? (c <complex>) #t)
-(define-method complex? (c) #f)
+(define-method (complex? c <complex>) #t)
+(define-method (complex? c) #f)
-(define-method number? (n <number>) #t)
-(define-method number? (n) #f)
+(define-method (number? n <number>) #t)
+(define-method (number? n) #f)
@dots{}
@dots{}
@end lisp
Index: guile/guile-oops/goops.texi
diff -u guile/guile-oops/goops.texi:1.12 guile/guile-oops/goops.texi:1.13
--- guile/guile-oops/goops.texi:1.12 Wed Mar 8 08:01:49 2000
+++ guile/guile-oops/goops.texi Fri Mar 9 17:27:04 2001
@@ -25,7 +25,7 @@
@ifinfo
This file documents GOOPS, an object oriented extension for Guile.
-Copyright (C) 1999, 2000 Free Software Foundation
+Copyright (C) 1999, 2000, 2001 Free Software Foundation
Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
@@ -157,7 +157,7 @@
@smalllisp
@group
-(define-method + ((x <string>) (y <string>))
+(define-method (+ (x <string>) (y <string>))
(string-append x y))
(+ 1 2) --> 3
@@ -176,7 +176,7 @@
@group
(use-modules (ice-9 format))
-(define-method write ((obj <2D-vector>) port)
+(define-method (write (obj <2D-vector>) port)
(display (format #f "<~S, ~S>" (x-component obj) (y-component obj))
port))
@@ -186,7 +186,7 @@
@end group
@group
-(define-method + ((x <2D-vector>) (y <2D-vector>))
+(define-method (+ (x <2D-vector>) (y <2D-vector>))
(make <2D-vector>
#:x (+ (x-component x) (x-component y))
#:y (+ (y-component x) (y-component y))))
@@ -557,7 +557,7 @@
function methods.
@example
-(define-method perimeter ((s <square>))
+(define-method (perimeter (s <square>))
(* 4 (side-length s)))
@end example
@@ -864,7 +864,7 @@
signature is
@example
-(define-method initialize ((object <object>) initargs) ...)
+(define-method (initialize (object <object>) initargs) ...)
@end example
The initialization of instances of any given class can be customized by
@@ -1086,7 +1086,7 @@
(let ((batch-allocation-count 0)
(batch-get-n-set #f))
- (define-method compute-get-n-set ((class <batched-allocation-metaclass>) s)
+ (define-method (compute-get-n-set (class <batched-allocation-metaclass>) s)
(case (slot-definition-allocation s)
((#:batched)
;; If we've already used the same slot storage for 10 instances,
@@ -1665,7 +1665,7 @@
To add a method to a generic function, use the @code{define-method} form.
address@hidden syntax define-method symbol (parameter @dots{}) . body
address@hidden syntax define-method (symbol parameter @dots{}) . body
Define a method for the generic function or accessor @var{symbol} with
parameters @var{parameter}s and body @var{body}.
@@ -1695,7 +1695,7 @@
procedure definitions of the form
@example
-(define name (lambda (formals @dots{}) . body))
+(define (name formals @dots{}) . body)
@end example
The most important difference is that each formal parameter, apart from the
@@ -1997,7 +1997,7 @@
@example
(define-class <can-be-nameless> (<class>))
-(define-method class-redefinition ((old <can-be-nameless>) (new <class>))
+(define-method (class-redefinition (old <can-be-nameless>) (new <class>))
new)
@end example
@@ -2304,7 +2304,7 @@
@example
(define-generic cube)
-(define-method cube ((n <number>))
+(define-method (cube (n <number>))
(* n n n))
(map method-source (generic-function-methods cube))
- guile/guile-oops goops-tutorial.texi goops.texi,
Mikael Djurfeldt <=