Published on

Introduction to Scheme/Racket Programming Part 1

Authors

Table of Contents

What is Scheme and Racket?

Scheme is a minimalist dialect of Lisp, emphasizing functional programming, created in the 1970s. It was designed to be simple, with a small set of core principles.

Racket is an evolution of Scheme, designed to be more powerful and flexible. Racket is not just a language but a platform for designing other languages.

  • Emphasis on functional programming and recursion.
  • Lightweight syntax with extensive use of parentheses.
  • Powerful macro system for code transformations.

Scheme was developed by Guy L. Steele and Gerald Jay Sussman in the 1970s. Racket began in the 1990s as PLT Scheme and has evolved with richer features to support various programming paradigms.

Differences between Scheme and Racket

  • Scheme is minimalist, focusing on a small number of core constructs.
  • Racket extends Scheme with more libraries, tools, and support for practical applications (GUI, web development, etc.).
  • Racket has a built-in IDE (DrRacket), richer syntax, and an expanded standard library, making it more user-friendly and versatile for modern applications.

Setting up the Development Environment

To get started with Racket programming, you need to install the Racket programming environment. Follow these steps:

  • DrRacket IDE
  • Visual Studio Code (VSCode) with the Racket extension is recommended for editing Racket code.
    • Install VSCode from the official website.
    • Install the Magic Racket from the VSCode marketplace.
    • Configure the Racket path C:\Program Files\Racket like this in the environment variable.

Basic Syntax in Scheme/Racket

Video Tutorial

#lang racket ; Specify the language

#lang racket tells DrRacket to use the Racket language. It is a directive that specifies the language for the code. There are other languages available in Racket, such as #lang scheme, which uses the Scheme dialect. Other languages are also available for specific purposes like .

Comments

Single-line comments use ;, and multi-line comments use #| ... |#. :

; This is a single-line comment
#| This is a
   multi-line comment |#

Hello World

(display "Hello, World!") ; Display a message
(newline) ; Move to the next line

Racket programs are made up of expressions enclosed in parentheses. The first element is usually a function or operator, and the remaining elements are its arguments. Since everything is an expression, they can be nested.

(+ 1 2) ; expression
(* 3 (+ 1 2)) ; nested expression

Variables

(define x 10) ; Define a variable x with value 10
(define y "Hello") ; Define a variable y with value "Hello"

Note: Proper indentation is important for readability since parentheses are so frequently used. DrRacket will help you with this by automatically indenting your code.

Resources and Further Reading