The goal is to design and implement a mini-Scheme interpreter capable of handling LeetCode-level tasks. This means the interpreter should support essential features required for implementing data structures and algorithms, such as arithmetic operations, variables, conditionals, functions, recursion, and basic data structures like lists. We will choose a subset of Scheme that includes these features while keeping the interpreter manageable.
You can implement the interpreter in any programming language you are comfortable with.
See a Typescript implementation sample.
See through guide.
-
Arithmetic Operations:
+
,-
,*
,/
- Example:
(+ 1 2)
evaluates to3
- Example:
-
Variables and Assignments:
define
: Define a new variable- Example:
(define x 5)
- Example:
set!
: Update an existing variable- Example:
(set! x 10)
- Example:
-
Conditionals:
if
: Conditional expressions- Example:
(if (> x 0) x (- x))
- Example:
-
Functions:
lambda
: Anonymous functions- Example:
((lambda (x) (* x x)) 5)
evaluates to25
- Example:
define
: Define named functions- Example:
(define (square x) (* x x))
- Example:
-
Recursion:
- Functions that call themselves
- Example: Factorial function
- Functions that call themselves
-
Basic Data Structures:
cons
,car
,cdr
: Working with lists- Example:
(car (cons 1 '(2 3)))
evaluates to1
- Example:
By the end of this project, we'll have an interpreter that can parse and evaluate Scheme expressions involving these constructs, sufficient for solving algorithmic problems.