DEV Community

Red Nose Hacker
Red Nose Hacker

Posted on

Learning Guile - Booleans

Guile Logo

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"
  #t
  #true)

(test-equal "Falsness"
  #f
  #false)

(test-equal "Numbers are true"
  #t
  (if 12547
      #t
      #f))

(test-equal "Strings are true"
  #t
  (if "I am not false"
      #t
      #f))

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

(test-equal "Symbols are not false"
  #f
  (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!

Top comments (3)

Collapse
 
epsi profile image
E.R. Nurwijayadi

I wonder if there is a community where I can ask about Guile.

Collapse
 
jeremykorwin profile image
Red Nose Hacker

Damn I haven't seen any notification about your comment !
There is a community !
You can find it on the Guile mailing list, or on the Scheme sub-Reddit, or on StackOverflow, or on Discord Scheme server, or you can send me e-mails !

Collapse
 
epsi profile image
E.R. Nurwijayadi

Thank you