Add foreign object documentation
[bpt/guile.git] / doc / ref / libguile-smobs.texi
CommitLineData
3229f68b
MV
1@c -*-texinfo-*-
2@c This is part of the GNU Guile Reference Manual.
fa1a3072 3@c Copyright (C) 1996, 1997, 2000, 2001, 2002, 2003, 2004, 2005, 2010, 2011, 2013, 2014
3229f68b
MV
4@c Free Software Foundation, Inc.
5@c See the file guile.texi for copying conditions.
6
7@node Defining New Types (Smobs)
8@section Defining New Types (Smobs)
9
10@dfn{Smobs} are Guile's mechanism for adding new primitive types to
11the system. The term ``smob'' was coined by Aubrey Jaffer, who says
12it comes from ``small object'', referring to the fact that they are
13quite limited in size: they can hold just one pointer to a larger
14memory block plus 16 extra bits.
15
16To define a new smob type, the programmer provides Guile with some
17essential information about the type --- how to print it, how to
18garbage collect it, and so on --- and Guile allocates a fresh type tag
19for it. The programmer can then use @code{scm_c_define_gsubr} to make
20a set of C functions visible to Scheme code that create and operate on
21these objects.
22
23(You can find a complete version of the example code used in this
24section in the Guile distribution, in @file{doc/example-smob}. That
25directory includes a makefile and a suitable @code{main} function, so
26you can build a complete interactive Guile shell, extended with the
27datatypes described here.)
28
29@menu
30* Describing a New Type::
eb12b401 31* Creating Smob Instances::
3229f68b
MV
32* Type checking::
33* Garbage Collecting Smobs::
3229f68b
MV
34* Remembering During Operations::
35* Double Smobs::
36* The Complete Example::
37@end menu
38
39@node Describing a New Type
40@subsection Describing a New Type
41
aaa9ef33 42To define a new type, the programmer must write two functions to
3229f68b
MV
43manage instances of the type:
44
45@table @code
3229f68b
MV
46@item print
47Guile will apply this function to each instance of the new type to print
48the value, as for @code{display} or @code{write}. The default print
49function prints @code{#<NAME ADDRESS>} where @code{NAME} is the first
0f7e6c56 50argument passed to @code{scm_make_smob_type}.
3229f68b
MV
51
52@item equalp
53If Scheme code asks the @code{equal?} function to compare two instances
54of the same smob type, Guile calls this function. It should return
55@code{SCM_BOOL_T} if @var{a} and @var{b} should be considered
56@code{equal?}, or @code{SCM_BOOL_F} otherwise. If @code{equalp} is
57@code{NULL}, @code{equal?} will assume that two instances of this type are
58never @code{equal?} unless they are @code{eq?}.
59
60@end table
61
aaa9ef33
LC
62When the only resource associated with a smob is memory managed by the
63garbage collector---i.e., memory allocated with the @code{scm_gc_malloc}
64functions---this is sufficient. However, when a smob is associated with
65other kinds of resources, it may be necessary to define one of the
66following functions, or both:
67
68@table @code
69@item mark
70Guile will apply this function to each instance of the new type it
71encounters during garbage collection. This function is responsible for
72telling the collector about any other @code{SCM} values that the object
73has stored, and that are in memory regions not already scanned by the
74garbage collector. @xref{Garbage Collecting Smobs}, for more details.
75
76@item free
77Guile will apply this function to each instance of the new type that is
78to be deallocated. The function should release all resources held by
79the object. This is analogous to the Java finalization method---it is
80invoked at an unspecified time (when garbage collection occurs) after
81the object is dead. @xref{Garbage Collecting Smobs}, for more details.
82
83This function operates while the heap is in an inconsistent state and
84must therefore be careful. @xref{Smobs}, for details about what this
85function is allowed to do.
86@end table
87
3229f68b
MV
88To actually register the new smob type, call @code{scm_make_smob_type}.
89It returns a value of type @code{scm_t_bits} which identifies the new
90smob type.
91
818d24b5 92The four special functions described above are registered by calling
3229f68b
MV
93one of @code{scm_set_smob_mark}, @code{scm_set_smob_free},
94@code{scm_set_smob_print}, or @code{scm_set_smob_equalp}, as
95appropriate. Each function is intended to be used at most once per
96type, and the call should be placed immediately following the call to
97@code{scm_make_smob_type}.
98
99There can only be at most 256 different smob types in the system.
100Instead of registering a huge number of smob types (for example, one
101for each relevant C struct in your application), it is sometimes
8c3fa3e5 102better to register just one and implement a second layer of type
3229f68b 103dispatching on top of it. This second layer might use the 16 extra
8c3fa3e5 104bits to extend its type, for example.
3229f68b
MV
105
106Here is how one might declare and register a new type representing
107eight-bit gray-scale images:
108
109@example
110#include <libguile.h>
111
112struct image @{
113 int width, height;
114 char *pixels;
115
116 /* The name of this image */
117 SCM name;
118
119 /* A function to call when this image is
120 modified, e.g., to update the screen,
121 or SCM_BOOL_F if no action necessary */
122 SCM update_func;
123@};
124
125static scm_t_bits image_tag;
126
127void
128init_image_type (void)
129@{
130 image_tag = scm_make_smob_type ("image", sizeof (struct image));
131 scm_set_smob_mark (image_tag, mark_image);
132 scm_set_smob_free (image_tag, free_image);
133 scm_set_smob_print (image_tag, print_image);
134@}
135@end example
136
137
eb12b401
NJ
138@node Creating Smob Instances
139@subsection Creating Smob Instances
3229f68b 140
818d24b5
MV
141Normally, smobs can have one @emph{immediate} word of data. This word
142stores either a pointer to an additional memory block that holds the
143real data, or it might hold the data itself when it fits. The word is
144large enough for a @code{SCM} value, a pointer to @code{void}, or an
145integer that fits into a @code{size_t} or @code{ssize_t}.
3229f68b
MV
146
147You can also create smobs that have two or three immediate words, and
148when these words suffice to store all data, it is more efficient to use
149these super-sized smobs instead of using a normal smob plus a memory
150block. @xref{Double Smobs}, for their discussion.
151
fc038e5b
MV
152Guile provides functions for managing memory which are often helpful
153when implementing smobs. @xref{Memory Blocks}.
154
3229f68b
MV
155To retrieve the immediate word of a smob, you use the macro
156@code{SCM_SMOB_DATA}. It can be set with @code{SCM_SET_SMOB_DATA}.
157The 16 extra bits can be accessed with @code{SCM_SMOB_FLAGS} and
158@code{SCM_SET_SMOB_FLAGS}.
159
818d24b5 160The two macros @code{SCM_SMOB_DATA} and @code{SCM_SET_SMOB_DATA} treat
fc038e5b
MV
161the immediate word as if it were of type @code{scm_t_bits}, which is
162an unsigned integer type large enough to hold a pointer to
163@code{void}. Thus you can use these macros to store arbitrary
164pointers in the smob word.
165
166When you want to store a @code{SCM} value directly in the immediate
167word of a smob, you should use the macros @code{SCM_SMOB_OBJECT} and
168@code{SCM_SET_SMOB_OBJECT} to access it.
3229f68b
MV
169
170Creating a smob instance can be tricky when it consists of multiple
aaa9ef33
LC
171steps that allocate resources. Most of the time, this is mainly about
172allocating memory to hold associated data structures. Using memory
173managed by the garbage collector simplifies things: the garbage
174collector will automatically scan those data structures for pointers,
175and reclaim them when they are no longer referenced.
3229f68b
MV
176
177Continuing the example from above, if the global variable
178@code{image_tag} contains a tag returned by @code{scm_make_smob_type},
179here is how we could construct a smob whose immediate word contains a
180pointer to a freshly allocated @code{struct image}:
181
182@example
183SCM
184make_image (SCM name, SCM s_width, SCM s_height)
185@{
186 SCM smob;
187 struct image *image;
188 int width = scm_to_int (s_width);
189 int height = scm_to_int (s_height);
190
191 /* Step 1: Allocate the memory block.
192 */
45867c2a
NJ
193 image = (struct image *)
194 scm_gc_malloc (sizeof (struct image), "image");
3229f68b
MV
195
196 /* Step 2: Initialize it with straight code.
197 */
198 image->width = width;
199 image->height = height;
200 image->pixels = NULL;
201 image->name = SCM_BOOL_F;
202 image->update_func = SCM_BOOL_F;
203
204 /* Step 3: Create the smob.
205 */
5b70b4e2 206 smob = scm_new_smob (image_tag, image);
3229f68b
MV
207
208 /* Step 4: Finish the initialization.
209 */
210 image->name = name;
45867c2a 211 image->pixels =
aaa9ef33 212 scm_gc_malloc_pointerless (width * height, "image pixels");
3229f68b
MV
213
214 return smob;
215@}
216@end example
217
aaa9ef33
LC
218We use @code{scm_gc_malloc_pointerless} for the pixel buffer to tell the
219garbage collector not to scan it for pointers. Calls to
220@code{scm_gc_malloc}, @code{scm_new_smob}, and
221@code{scm_gc_malloc_pointerless} raise an exception in out-of-memory
222conditions; the garbage collector is able to reclaim previously
223allocated memory if that happens.
3229f68b 224
3229f68b
MV
225
226@node Type checking
227@subsection Type checking
228
818d24b5
MV
229Functions that operate on smobs should check that the passed
230@code{SCM} value indeed is a suitable smob before accessing its data.
231They can do this with @code{scm_assert_smob_type}.
3229f68b
MV
232
233For example, here is a simple function that operates on an image smob,
234and checks the type of its argument.
235
236@example
237SCM
238clear_image (SCM image_smob)
239@{
240 int area;
241 struct image *image;
242
818d24b5 243 scm_assert_smob_type (image_tag, image_smob);
3229f68b
MV
244
245 image = (struct image *) SCM_SMOB_DATA (image_smob);
246 area = image->width * image->height;
247 memset (image->pixels, 0, area);
248
249 /* Invoke the image's update function.
250 */
251 if (scm_is_true (image->update_func))
252 scm_call_0 (image->update_func);
253
254 scm_remember_upto_here_1 (image_smob);
255
256 return SCM_UNSPECIFIED;
257@}
258@end example
259
260See @ref{Remembering During Operations} for an explanation of the call
261to @code{scm_remember_upto_here_1}.
262
263
264@node Garbage Collecting Smobs
265@subsection Garbage Collecting Smobs
266
267Once a smob has been released to the tender mercies of the Scheme
aaa9ef33
LC
268system, it must be prepared to survive garbage collection. In the
269example above, all the memory associated with the smob is managed by the
270garbage collector because we used the @code{scm_gc_} allocation
271functions. Thus, no special care must be taken: the garbage collector
272automatically scans them and reclaims any unused memory.
273
274However, when data associated with a smob is managed in some other
275way---e.g., @code{malloc}'d memory or file descriptors---it is possible
276to specify a @emph{free} function to release those resources when the
277smob is reclaimed, and a @emph{mark} function to mark Scheme objects
278otherwise invisible to the garbage collector.
3229f68b
MV
279
280As described in more detail elsewhere (@pxref{Conservative GC}), every
281object in the Scheme system has a @dfn{mark bit}, which the garbage
282collector uses to tell live objects from dead ones. When collection
283starts, every object's mark bit is clear. The collector traces pointers
284through the heap, starting from objects known to be live, and sets the
285mark bit on each object it encounters. When it can find no more
286unmarked objects, the collector walks all objects, live and dead, frees
287those whose mark bits are still clear, and clears the mark bit on the
288others.
289
290The two main portions of the collection are called the @dfn{mark phase},
291during which the collector marks live objects, and the @dfn{sweep
292phase}, during which the collector frees all unmarked objects.
293
294The mark bit of a smob lives in a special memory region. When the
295collector encounters a smob, it sets the smob's mark bit, and uses the
296smob's type tag to find the appropriate @emph{mark} function for that
297smob. It then calls this @emph{mark} function, passing it the smob as
298its only argument.
299
300The @emph{mark} function is responsible for marking any other Scheme
301objects the smob refers to. If it does not do so, the objects' mark
302bits will still be clear when the collector begins to sweep, and the
303collector will free them. If this occurs, it will probably break, or at
304least confuse, any code operating on the smob; the smob's @code{SCM}
305values will have become dangling references.
306
307To mark an arbitrary Scheme object, the @emph{mark} function calls
308@code{scm_gc_mark}.
309
aaa9ef33
LC
310Thus, here is how we might write @code{mark_image}---again this is not
311needed in our example since we used the @code{scm_gc_} allocation
312routines, so this is just for the sake of illustration:
3229f68b
MV
313
314@example
315@group
316SCM
317mark_image (SCM image_smob)
318@{
319 /* Mark the image's name and update function. */
320 struct image *image = (struct image *) SCM_SMOB_DATA (image_smob);
321
322 scm_gc_mark (image->name);
323 scm_gc_mark (image->update_func);
324
325 return SCM_BOOL_F;
326@}
327@end group
328@end example
329
330Note that, even though the image's @code{update_func} could be an
331arbitrarily complex structure (representing a procedure and any values
332enclosed in its environment), @code{scm_gc_mark} will recurse as
333necessary to mark all its components. Because @code{scm_gc_mark} sets
334an object's mark bit before it recurses, it is not confused by
335circular structures.
336
337As an optimization, the collector will mark whatever value is returned
338by the @emph{mark} function; this helps limit depth of recursion during
339the mark phase. Thus, the code above should really be written as:
340@example
341@group
342SCM
343mark_image (SCM image_smob)
344@{
345 /* Mark the image's name and update function. */
346 struct image *image = (struct image *) SCM_SMOB_DATA (image_smob);
347
348 scm_gc_mark (image->name);
349 return image->update_func;
350@}
351@end group
352@end example
353
354
355Finally, when the collector encounters an unmarked smob during the sweep
356phase, it uses the smob's tag to find the appropriate @emph{free}
357function for the smob. It then calls that function, passing it the smob
358as its only argument.
359
360The @emph{free} function must release any resources used by the smob.
361However, it must not free objects managed by the collector; the
362collector will take care of them. For historical reasons, the return
363type of the @emph{free} function should be @code{size_t}, an unsigned
364integral type; the @emph{free} function should always return zero.
365
366Here is how we might write the @code{free_image} function for the image
aaa9ef33
LC
367smob type---again for the sake of illustration, since our example does
368not need it thanks to the use of the @code{scm_gc_} allocation routines:
3229f68b
MV
369@example
370size_t
371free_image (SCM image_smob)
372@{
373 struct image *image = (struct image *) SCM_SMOB_DATA (image_smob);
374
45867c2a
NJ
375 scm_gc_free (image->pixels,
376 image->width * image->height,
377 "image pixels");
3229f68b
MV
378 scm_gc_free (image, sizeof (struct image), "image");
379
380 return 0;
381@}
382@end example
383
384During the sweep phase, the garbage collector will clear the mark bits
385on all live objects. The code which implements a smob need not do this
386itself.
387
fa1a3072
AW
388@cindex finalizer
389@cindex finalization
390
391Note that the free function can be called in any context. In
392particular, if your Guile is built with support for threads, the
393finalizer may be called from any thread that is running Guile. In Guile
3942.0, finalizers are invoked via ``asyncs'', which interleaves them with
395running Scheme code; @pxref{System asyncs}. In Guile 2.2 there will be
396a dedicated finalization thread, to ensure that the finalization doesn't
397run within the critical section of any other thread known to Guile.
398
399In either case, finalizers (free functions) run concurrently with the
400main program, and so they need to be async-safe and thread-safe. If for
401some reason this is impossible, perhaps because you are embedding Guile
402in some application that is not itself thread-safe, you have a few
403options. One is to use guardians instead of free functions, and arrange
404to pump the guardians for finalizable objects. @xref{Guardians}, for
405more information. The other option is to disable automatic finalization
406entirely, and arrange to call @code{scm_run_finalizers ()} at
407appropriate points. @xref{Smobs}, for more on these interfaces.
408
3229f68b
MV
409There is no way for smob code to be notified when collection is
410complete.
411
412It is usually a good idea to minimize the amount of processing done
413during garbage collection; keep the @emph{mark} and @emph{free}
414functions very simple. Since collections occur at unpredictable times,
415it is easy for any unusual activity to interfere with normal code.
416
3229f68b
MV
417@node Remembering During Operations
418@subsection Remembering During Operations
1176df85 419@cindex remembering
3229f68b 420
aaa9ef33
LC
421@c FIXME: Remove this section?
422
3229f68b
MV
423It's important that a smob is visible to the garbage collector
424whenever its contents are being accessed. Otherwise it could be freed
425while code is still using it.
426
427For example, consider a procedure to convert image data to a list of
428pixel values.
429
430@example
431SCM
432image_to_list (SCM image_smob)
433@{
434 struct image *image;
435 SCM lst;
436 int i;
818d24b5
MV
437
438 scm_assert_smob_type (image_tag, image_smob);
3229f68b
MV
439
440 image = (struct image *) SCM_SMOB_DATA (image_smob);
441 lst = SCM_EOL;
442 for (i = image->width * image->height - 1; i >= 0; i--)
443 lst = scm_cons (scm_from_char (image->pixels[i]), lst);
444
445 scm_remember_upto_here_1 (image_smob);
446 return lst;
447@}
448@end example
449
450In the loop, only the @code{image} pointer is used and the C compiler
451has no reason to keep the @code{image_smob} value anywhere. If
452@code{scm_cons} results in a garbage collection, @code{image_smob} might
453not be on the stack or anywhere else and could be freed, leaving the
454loop accessing freed data. The use of @code{scm_remember_upto_here_1}
455prevents this, by creating a reference to @code{image_smob} after all
456data accesses.
457
458There's no need to do the same for @code{lst}, since that's the return
459value and the compiler will certainly keep it in a register or
460somewhere throughout the routine.
461
462The @code{clear_image} example previously shown (@pxref{Type checking})
463also used @code{scm_remember_upto_here_1} for this reason.
464
465It's only in quite rare circumstances that a missing
466@code{scm_remember_upto_here_1} will bite, but when it happens the
467consequences are serious. Fortunately the rule is simple: whenever
468calling a Guile library function or doing something that might, ensure
fc038e5b 469that the @code{SCM} of a smob is referenced past all accesses to its
3229f68b
MV
470insides. Do this by adding an @code{scm_remember_upto_here_1} if
471there are no other references.
472
473In a multi-threaded program, the rule is the same. As far as a given
474thread is concerned, a garbage collection still only occurs within a
475Guile library function, not at an arbitrary time. (Guile waits for all
476threads to reach one of its library functions, and holds them there
477while the collector runs.)
478
479@node Double Smobs
480@subsection Double Smobs
481
aaa9ef33
LC
482@c FIXME: Remove this section?
483
3229f68b 484Smobs are called smob because they are small: they normally have only
fc038e5b
MV
485room for one @code{void*} or @code{SCM} value plus 16 bits. The
486reason for this is that smobs are directly implemented by using the
487low-level, two-word cells of Guile that are also used to implement
0f7e6c56 488pairs, for example. (@pxref{Data Representation} for the
8680d53b
AW
489details.) One word of the two-word cells is used for
490@code{SCM_SMOB_DATA} (or @code{SCM_SMOB_OBJECT}), the other contains
491the 16-bit type tag and the 16 extra bits.
3229f68b
MV
492
493In addition to the fundamental two-word cells, Guile also has
494four-word cells, which are appropriately called @dfn{double cells}.
495You can use them for @dfn{double smobs} and get two more immediate
496words of type @code{scm_t_bits}.
497
5b70b4e2
AW
498A double smob is created with @code{scm_new_double_smob}. Its immediate
499words can be retrieved as @code{scm_t_bits} with @code{SCM_SMOB_DATA_2}
500and @code{SCM_SMOB_DATA_3} in addition to @code{SCM_SMOB_DATA}.
501Unsurprisingly, the words can be set to @code{scm_t_bits} values with
502@code{SCM_SET_SMOB_DATA_2} and @code{SCM_SET_SMOB_DATA_3}.
fc038e5b
MV
503
504Of course there are also @code{SCM_SMOB_OBJECT_2},
505@code{SCM_SMOB_OBJECT_3}, @code{SCM_SET_SMOB_OBJECT_2}, and
506@code{SCM_SET_SMOB_OBJECT_3}.
3229f68b
MV
507
508@node The Complete Example
509@subsection The Complete Example
510
511Here is the complete text of the implementation of the image datatype,
512as presented in the sections above. We also provide a definition for
513the smob's @emph{print} function, and make some objects and functions
514static, to clarify exactly what the surrounding code is using.
515
516As mentioned above, you can find this code in the Guile distribution, in
517@file{doc/example-smob}. That directory includes a makefile and a
518suitable @code{main} function, so you can build a complete interactive
519Guile shell, extended with the datatypes described here.)
520
521@example
522/* file "image-type.c" */
523
524#include <stdlib.h>
525#include <libguile.h>
526
527static scm_t_bits image_tag;
528
529struct image @{
530 int width, height;
531 char *pixels;
532
533 /* The name of this image */
534 SCM name;
535
536 /* A function to call when this image is
537 modified, e.g., to update the screen,
538 or SCM_BOOL_F if no action necessary */
539 SCM update_func;
540@};
541
542static SCM
543make_image (SCM name, SCM s_width, SCM s_height)
544@{
545 SCM smob;
546 struct image *image;
547 int width = scm_to_int (s_width);
548 int height = scm_to_int (s_height);
549
550 /* Step 1: Allocate the memory block.
551 */
45867c2a
NJ
552 image = (struct image *)
553 scm_gc_malloc (sizeof (struct image), "image");
3229f68b
MV
554
555 /* Step 2: Initialize it with straight code.
556 */
557 image->width = width;
558 image->height = height;
559 image->pixels = NULL;
560 image->name = SCM_BOOL_F;
561 image->update_func = SCM_BOOL_F;
562
563 /* Step 3: Create the smob.
564 */
5b70b4e2 565 smob = scm_new_smob (image_tag, image);
3229f68b
MV
566
567 /* Step 4: Finish the initialization.
568 */
569 image->name = name;
45867c2a
NJ
570 image->pixels =
571 scm_gc_malloc (width * height, "image pixels");
3229f68b
MV
572
573 return smob;
574@}
575
576SCM
577clear_image (SCM image_smob)
578@{
579 int area;
580 struct image *image;
581
818d24b5 582 scm_assert_smob_type (image_tag, image_smob);
3229f68b
MV
583
584 image = (struct image *) SCM_SMOB_DATA (image_smob);
585 area = image->width * image->height;
586 memset (image->pixels, 0, area);
587
588 /* Invoke the image's update function.
589 */
590 if (scm_is_true (image->update_func))
591 scm_call_0 (image->update_func);
592
593 scm_remember_upto_here_1 (image_smob);
594
595 return SCM_UNSPECIFIED;
596@}
597
598static SCM
599mark_image (SCM image_smob)
600@{
601 /* Mark the image's name and update function. */
602 struct image *image = (struct image *) SCM_SMOB_DATA (image_smob);
603
604 scm_gc_mark (image->name);
605 return image->update_func;
606@}
607
608static size_t
609free_image (SCM image_smob)
610@{
611 struct image *image = (struct image *) SCM_SMOB_DATA (image_smob);
612
45867c2a
NJ
613 scm_gc_free (image->pixels,
614 image->width * image->height,
615 "image pixels");
3229f68b
MV
616 scm_gc_free (image, sizeof (struct image), "image");
617
618 return 0;
619@}
620
621static int
622print_image (SCM image_smob, SCM port, scm_print_state *pstate)
623@{
624 struct image *image = (struct image *) SCM_SMOB_DATA (image_smob);
625
626 scm_puts ("#<image ", port);
627 scm_display (image->name, port);
628 scm_puts (">", port);
629
630 /* non-zero means success */
631 return 1;
632@}
633
634void
635init_image_type (void)
636@{
637 image_tag = scm_make_smob_type ("image", sizeof (struct image));
638 scm_set_smob_mark (image_tag, mark_image);
639 scm_set_smob_free (image_tag, free_image);
640 scm_set_smob_print (image_tag, print_image);
641
642 scm_c_define_gsubr ("clear-image", 1, 0, 0, clear_image);
643 scm_c_define_gsubr ("make-image", 3, 0, 0, make_image);
644@}
645@end example
646
647Here is a sample build and interaction with the code from the
648@file{example-smob} directory, on the author's machine:
649
650@example
651zwingli:example-smob$ make CC=gcc
097a793b
AW
652gcc `pkg-config --cflags guile-@value{EFFECTIVE-VERSION}` -c image-type.c -o image-type.o
653gcc `pkg-config --cflags guile-@value{EFFECTIVE-VERSION}` -c myguile.c -o myguile.o
654gcc image-type.o myguile.o `pkg-config --libs guile-@value{EFFECTIVE-VERSION}` -o myguile
3229f68b
MV
655zwingli:example-smob$ ./myguile
656guile> make-image
657#<primitive-procedure make-image>
658guile> (define i (make-image "Whistler's Mother" 100 100))
659guile> i
660#<image Whistler's Mother>
661guile> (clear-image i)
662guile> (clear-image 4)
663ERROR: In procedure clear-image in expression (clear-image 4):
48d8f659 664ERROR: Wrong type (expecting image): 4
3229f68b
MV
665ABORT: (wrong-type-arg)
666
667Type "(backtrace)" to get more information.
668guile>
669@end example