Guile Hacker Handbook: Booleans (new chapter)

Guile Logo

The Guile Hacker Notebook follows the style of Test Driven Learning to illustrate features of the Guile programming language. Asides on tools and techniques are provided to help the hacker become more productive.

In this chapter, the hacker manipulates booleans. He will take the opportunity to document his source code with what are called docstrings.

The chapter is accessible at the following address: .

Let's take advantage of this article to play a bit with all this!


The two boolean values are: “true” and “false”. Respectively #t or #true and #f or #false in Guile.

In a conditional test context, “true” means any expression other than #f or #false.

Here is a small test suite that illustrates all this:

(use-modules (srfi srfi-64))

(test-begin "test-suite")

(test-equal "Truth"

(test-equal "Falsness"

(test-equal "Numbers are true"
  (if 12547

(test-equal "Strings are true"
  (if "I am not false"

(test-equal "Lists - even empty - are true"
  (if '()

(test-equal "Symbols are not false"
  (not 'i-am-not-false))

(test-end "test-suite")

Create a /tmp/bool.scm file with the code below. Run the tests and if everything goes well, you should see the following result:

$ guile bool.scm 
;;;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
;;; or pass the --no-auto-compile argument to disable.
;;;; compiling /tmp/bool.scm
compiled /home/jeko/.cache/guile/ccache/3.0-LE-8-4.3/tmp/bool.scm.go
%%%% Starting test-suite (Writing full log to "test-suite.log")
# of expected passes 6

If you feel like it, you can tweak this file to experiment!

The docstrings

Create a /tmp/docstring.scm file and put the following code in it :

(define-module (docstrings))

(define-public (dummy-procedure)
  "See my docstring?!"
  (display "I am dummy"))

Then, open the REPL and execute the following commands to see an example of using docstrings :

$ guile
GNU Guile 3.0.4
Copyright (C) 1995-2020 Free Software Foundation, Inc.

Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
This program is free software, and you are welcome to redistribute it
under certain conditions; type `,show c' for details.

Enter `,help' for help.
scheme@(guile-user)> (load "docstring.scm")
scheme@(guile-user)> (use-modules (docstrings))
scheme@(guile-user)> ,describe dummy-procedure 
See my docstring?!
scheme@(guile-user)> (dummy-procedure )
I am dummyscheme@(guile-user)> 

Thank you so much for reading this article !

Don't hesitate to give me your opinion, leave a comment, or ask a question via :E-mail: jeremy AT korwin-zmijowski DOT frMastodon: @jeko@framapiaf.orgPeertube: @jeko@video.tedomum.netTwitter: @JeremyKorwin

Also, please subscribe so you don't miss the next ones :blog via Mastodon et RSSscreencast via Peertube et RSS

And most importantly, share the blog and tell your friends it's the best blog in the history of Free Software! No shit!

#english #guile #handbook