Gangmax Blog

Guile

Here are some code examples written in Guile from its official reference manual.

  1. Running Guile Scripts
test.guile
1
2
3
4
#!/usr/bin/env guile -s
!#
(display "Hello, world!")
(newline)
  1. Linking Guile into Programs
simple-guile.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
* Here is simple-guile.c, source code for a program that will produce a
* complete Guile interpreter. In addition to all usual functions provided
* by Guile, it will also offer the function my-hostname.
*
* Compile this file with the following command:
*
* gcc -o simple-guile simple-guile.c `pkg-config --cflags --libs guile-3.0`
*
*/
#include <stdlib.h>
#include <libguile.h>

static SCM
my_hostname (void)
{
char *s = getenv ("HOSTNAME");
if (s == NULL)
return SCM_BOOL_F;
else
return scm_from_locale_string (s);
}

static void
inner_main (void *data, int argc, char **argv)
{
scm_c_define_gsubr ("my-hostname", 0, 0, 0, my_hostname);
scm_shell (argc, argv);
}

int
main (int argc, char **argv)
{
scm_boot_guile (argc, argv, inner_main, 0);
return 0; /* never reached */
}

Comments