Closure

G-Golf closure high level API.
The G-Golf integration with GObject Closures.

Classes

<closure>

Accessors and Methods

!g-closure
!function
!return-type
!param-types
invoke

Description

The GLib/GObject type system supports the creation and invocation of ‘Closures’, which represents a callback supplied by the programmer (see Closures if you are curious about the low-level description and API, though you don’t need to to understand and use the high level API described here).

Its infrastructure allows one to pass a Scheme function to C, and have C call into Scheme, and vice versa. In Scheme, a <closure> instance holds a pointer to a GClosure instance, a Scheme procedure, the type of its return value, and a list of the type of its arguments.

Closures can be invoked with invoke, for example:

,use (g-golf)

(make <closure>
      #:function (lambda (a b) (+ a b))
      #:return-type 'int
      #:param-types '(int int))
⇒ $2 = #<<closure> 55f24a0228d0>

(invoke $2 3 2)
⇒ $3 = 5

Classes

Class: <closure>

Its slots are:

g-closure

#:accessor !g-closure

function

#:accessor !function
#:init-keyword #:function

return-type

#:accessor !return-type
#:init-keyword #:return-type

param-types

#:accessor !param-types
#:init-keyword #:param-types

The #:return-type and #:param-types accept respectively one symbol and a list of symbols that are members of the %g-type-fundamental-types.

Instances of the <closure> class are immutable (to be precise, there are not meant to be mutated, see GOOPS Notes and Conventions, ’Slots are not Immutable’).

Accessors and Methods

Note: in this section, the closure argument is [must be] a <closure> instance.

Accessor: !g-closure closure
Accessor: !function closure
Accessor: !return-type closure
Accessor: !param-types closure

Returns the content of their respective slot for closure.

Method: invoke closure . args

Returns the result of the invocation of closure, using (the possibly empty list of) args.

This is a ‘low level’ method, not used internally, provided mainly for debugging (or demonstration) purposes, so you may test and verify your callbacks and signals procedures34.


Footnotes

(34)

From scheme, you would ‘immediately’ call the procedure instead of course.