| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
1.1.1 Running GOOPS
Examples of some basic GOOPS functionality.
1.1.2 Methods 1.1.3 User-defined types 1.1.4 Types
See further in the GOOPS tutorial available in this distribution in
info (goops.info) and texinfo format.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
guile-oops |
You should now be at the Guile prompt ("guile> ").
(use-modules (oop goops)) |
to load GOOPS. (If your system supports dynamic loading, you should be able to do this not only from `guile-oops' but from an arbitrary Guile interpreter.)
We're now ready to try some basic GOOPS functionality.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
(define-method (+ (x <string>) (y <string>)) (string-append x y)) (+ 1 2) --> 3 (+ "abc" "de") --> "abcde" |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
(define-class <2D-vector> ()
(x #:init-value 0 #:accessor x-component #:init-keyword #:x)
(y #:init-value 0 #:accessor y-component #:init-keyword #:y))
(use-modules (ice-9 format))
(define-method (write (obj <2D-vector>) port)
(display (format #f "<~S, ~S>" (x-component obj) (y-component obj))
port))
(define v (make <2D-vector> #:x 3 #:y 4))
v --> <3, 4>
(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))))
(+ v v) --> <6, 8>
|
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
(class-of v) --> #<<class> <2D-vector> 40241ac0> <2D-vector> --> #<<class> <2D-vector> 40241ac0> (class-of 1) --> #<<class> <integer> 401b2a98> <integer> --> #<<class> <integer> 401b2a98> (is-a? v <2D-vector>) --> #t |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This chapter is the GOOPS reference manual. It aims to describe all the syntax, procedures, options and associated concepts that a typical application author would need to understand in order to use GOOPS effectively in their application. It also describes what is meant by the GOOPS "metaobject protocol" (aka "MOP"), and indicates how authors can use the metaobject protocol to customize the behaviour of GOOPS itself.
For a detailed specification of the GOOPS metaobject protocol, see 3. MOP Specification.
| [ << ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |