Values in Scheme

Our first example will demonstrate various value types in Scheme, including strings, numbers, and booleans. Here’s the code:

; Strings, which can be concatenated with 'string-append'
(display (string-append "scheme" "lang"))
(newline)

; Integers and floats
(display "1+1 = ")
(display (+ 1 1))
(newline)
(display "7.0/3.0 = ")
(display (/ 7.0 3.0))
(newline)

; Booleans, with boolean operators as you'd expect
(display (and #t #f))
(newline)
(display (or #t #f))
(newline)
(display (not #t))
(newline)

To run this program, save it to a file (e.g., values.scm) and use your Scheme interpreter. For example, if you’re using Guile:

$ guile values.scm
schemelang
1+1 = 2
7.0/3.0 = 2.3333333333333335
#f
#t
#f

Let’s break down the example:

  1. Strings in Scheme are delimited by double quotes. We use string-append to concatenate strings.

  2. Numbers in Scheme can be integers or floating-point. Arithmetic operations like addition (+) and division (/) are performed using prefix notation.

  3. Booleans in Scheme are represented as #t for true and #f for false. The logical operators and, or, and not work as expected.

  4. We use display to print values and newline to print a new line character.

This example demonstrates basic value types and operations in Scheme. As you can see, Scheme uses prefix notation for all operations, which is a characteristic of Lisp-like languages.