Catalog / Scheme Programming Language Cheatsheet
Scheme Programming Language Cheatsheet
A concise cheat sheet covering the core syntax, data types, procedures, and control structures of the Scheme programming language, useful for quick reference and learning.
Basic Syntax and Data Types
Core Syntax
|
All Scheme code is enclosed in parentheses. This signifies a function call or a special form. |
|
Used to define variables and procedures. Example: |
|
Creates anonymous functions (procedures). Example: |
Data Types
Numbers |
Integers, decimals, fractions. Example: |
Booleans |
|
Characters |
Represented with Example: |
Strings |
Sequences of characters enclosed in double quotes. Example: |
Symbols |
Unique identifiers, often used as keys. Example: |
Lists |
Ordered collections of data. Example: |
Basic Procedures
|
Arithmetic operators. Example: |
|
Numerical equality comparison. Example: |
|
Constructs a new list by adding an element to the beginning of an existing list. Example: |
|
Returns the first element of a list. Example: |
|
Returns the rest of the list after the first element. Example: |
Control Structures
Conditional Execution
|
Basic conditional statement. Example: |
|
Multi-way conditional. Example:
|
Iteration and Recursion
Recursion |
Scheme primarily uses recursion for iteration. A function calls itself until a base case is reached. Example:
|
|
The Example:
|
Boolean Operations
|
Returns Example: |
|
Returns Example: |
|
Negates a boolean value. Example: |
Working with Lists
List Manipulation
|
Creates a list from given elements. Example: |
|
Concatenates lists. Example: |
|
Reverses the order of elements in a list. Example: |
|
Returns the number of elements in a list. Example: |
Mapping and Filtering
|
Applies a function to each element of a list and returns a new list with the results. Example: |
|
Creates a new list containing only the elements that satisfy a given predicate (a function that returns Example: |
List Predicates
|
Checks if a list is empty. Example: |
|
Checks if a value is a list. Example: |
|
Checks if an element is a member of a list. Example: |
Input and Output
Basic I/O
|
Prints a value to the console. Example: |
|
Prints a newline character to the console. Example: |
|
Reads a Scheme expression from the input. Example: |
Formatted Output
|
Formatted output (implementation-dependent, check your Scheme system’s documentation). Example (Racket): |
File I/O
|
Opens a file for input. Example: |
|
Opens a file for output. Example: |
|
Reads a single character from an input port. Example: |
|
Writes a single character to an output port. Example: |
|
Closes an input port. Example: |
|
Closes an output port. Example: |