GOOPS Notes and Conventions

G-Golf extensively uses GOOPS, the Guile Object Oriented System (see GOOPS in The GNU Guile Reference Manual), in a way that is largely inspired by Guile-Gnome.

Here are some notes and the GOOPS conventions used by G-Golf.

  _ Slots are not Immutable

Except for virtual slots, there is currently no way to effectively prohibit (block) a user to mutate a goops class instance (one can always use slot-set! instance slot-name value)7.

However, you will find a few places in this manual using phrase excerpts like ‘instances of this <class> are immutable’, or ‘this <slot> is immutable’. In these contexts, what is actually meant is that these (insances or slots) are not meant to be mutated. Doing so is not only at your own risks, but likely to cause a crash.

  _ Merging Generics

In G-Golf, generic functions are always merged (see Merging Generics in The GNU Guile Reference Manual).

Users are (highly) recommended to do the same, in their repl, application/library modules and script(s). In its modules - those that import (oop goops) - G-Golf uses the following duplicate binding handler set:

  #:duplicates (merge-generics
		replace
		warn-override-core
		warn
		last)

In a repl or in scripts, these maybe set - after importing (oop goops) - by calling default-duplicate-binding-handler:

(use-modules (oop goops))

(default-duplicate-binding-handler
    '(merge-generics replace warn-override-core warn last))

G-Golf regular users should consider adding the above lines to their $HOME/.guile or, when working in a multi-user environmet, should consider adding those lines the file named init.scm in the so-called Guile global site directory8, here (evaluate the following expression in a terminal): guile -c "(display (%global-site-dir))(newline)".

  _ Accessors Naming Convention

In G-Golf, all slots define an accessor (and no getter, no setter), the name of which is the slot-name prefixed using !. For example:

(define-class <gtype-class> (<class>)
  (info #:accessor !info
        #:init-keyword #:info)
  ...)

The principal reasons are (not in any particular order):


Footnotes

(7)

Actually, to be complete, there is a way, which is to define the slot using #:class <read-only-slot>, but (a) it is undocumented and (b), it requires the use use of libguile to initialize the slot value, something that I don’t wan’t to do in G-Golf. If you are interested by this (undocumented) feature for your own project though, I suggest you look for some exmples in the Guile-Gnome, source tree, where it is extensively used.

(8)

You need write privileges to add or modify this file, contact your system administrator if you’re not in charge of the system you are working on.

(9)

Slot names tends to be extremelly common, like name, color, … and naming their respective accessor using the slot name would very likely provoque numerous name clashes with user variables, procedures and methods names.