DEV Community

Red Nose Hacker
Red Nose Hacker

Posted on

1 1

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!

Billboard image

Monitor more than uptime.

With Checkly, you can use Playwright tests and Javascript to monitor end-to-end scenarios in your NextJS, Astro, Remix, or other application.

Get started now!

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

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay