Guile Scheme


Simply Importing modules

(use-modules (srfi srfi-19))


Reverse String

(string-reverse str [start [end]])

Reverse String in Place

(string-reverse! str [start [end]])

Regular expressions

Loading module

(use-modules (ice-9 regex))

Basic match

(string-match "[A-Za-z]" "foo") ; matches all alphabetic letters

Time and Date


File tree walk

(use-modules (ice-9 ftw))
    (open-file filename
        (if binary "wb" "w")
            #:encoding encoding)


Http requests

(use-modules (web client))
(http-get url #:streaming? #t)

Displaying text

(display "Guile Cookbook")


Using SLIB

(use-modules (ice-9 slib))

The C Side

Loading a Scheme source file

scm_c_primitive_load ("source.scm");

Calling a Scheme function

/* Declare SCM types for calling a function and reading its output */
SCM func_symbol;
SCM fun;
SCM ret_val;

/* Look up the symbol */
func_symbol = scm_c_lookup("function-name");
func = scm_variable_ref(func_symbol);
/* Call a Scheme function taking one argument */
ret_val = scm_call_1(func, scm_from_locale_string("string argument"));

/* ret_val now holds the return value from the function */

Fork me on GitHub