Previous: , Up: Categories of Typelib Bindings   [Contents][Index]


2.3.5 Procedures and Methods

When a library provides functions, they can either be standalone functions or methods. Methods are functions closely associated with a type.

When Guile-GI provides a binding for a stand-alone function, the function name is the kebab-case version of the native function name, with the namespace removed.

;; In C, the function g_unix_mount_at(mount_path, time_read)
(unix-mount-at mount-path)

When Guile-GI provides a binding for a method, it creates a GOOPS generic function. The function name is of the form type:method-name. It also provides an alias of the form method-name. Often, the generic functions using the shorter method names end up overloaded; however, as they are bound to classes they can usually be disambiguated based on their first arguments, which are the object instances.

;; In C, the GDate* method g_date_add_days
;; The type:method form
(date:add-days date 1)
;; The method-only form
(add-days date 1)

Caveat: When loading multiple typelibs, it may happen, that the two define classes with an identical name modulo namespace and a similar API. We have already seen such an example with Gio and Gtk, both of which have an application class. Usually, though not always, one inherits from the other.

Even in this case, most methods can be disambiguated based on the object instances. The exception to this rule are static methods – like constructors – which not only share the same name but often enough also have the same signature. Such conflicts require manual resolution.