Values in Racket
Racket has various value types including strings, integers, floats, booleans, etc. Here are a few basic examples.
To run the program, save it as values.rkt
and use the racket
command:
Let’s break down the Racket code:
We start with
#lang racket
to specify that we’re using the Racket language.For string concatenation, we use
string-append
instead of the+
operator.Racket uses prefix notation for arithmetic operations. So
1+1
becomes(+ 1 1)
.To convert numbers to strings for display, we use
number->string
.Booleans in Racket are represented as
#t
for true and#f
for false.The boolean operators
and
,or
, andnot
work similarly to other languages.We use
displayln
to print values with a newline, similar toprintln
in other languages.
Racket’s interactive nature allows for easy experimentation with these basic values and operations in the REPL (Read-Eval-Print Loop), which you can start by simply running racket
without any file argument.