Scheme Quick Review

Scheme is a functional programming language, where every functional line of code (basically any line that does anything) is structured as a list and placed in parentheses. The first thing after the open parenthesis MUST ALWAYS be a function/operation.

Some Important Functions

(cons x y) - Creates a two element list with x as the first element and y as the second element

(car lst) - Gives the car, or the first element of lst

(cdr lst) - Gives the cdr, or the second element of lst

(list x y z) - Creates a well-formed list out of x, y, and z

(if condition true-result false-result) - If the condition is true, returns true-result, otherwise returns false result

(cond (condition1 result1) (condition2 result2) (else result3)) - Evaluates each condition until it finds a true one or reaches else, then returns that result

(or expression1 expression2 expression3) - Evaluates each expression until it reaches one that evaluates true or the last one and returns its value

(and expression1 expression2 expression3) - Evaluates each expression until it finds one that evaluates false or the last one and returns that value

(define name value) - Sets name equal to value (kind of like an assignment statement)

(define (function-name parameter) body) - Creates a function with name, parameter, and body (kind of like a def statement)

((lambda (parameter1 parameter2) body) value1 value2) - Creates a lambda function with parameters and body and calls it on values

(= num1 num2) - Checks to see if num1 and num2 are equal (can only be used for numbers)

(eq? x y) - Checks to see if x and y are equal in the same way that the is keyword does in python (returns a boolean value)

(equal? x y) - Checks to see if x and y are equal in the same way that the == does in python (returns a boolean value)

(null? lst) - Checks to see if list is null (returns a boolean value)

(quote expression) or ‘expression - Returns expression exactly as is (sort of like a print)

(eval expression) - Evaluates expression and returns the evaluated expression

There are more of course, but these are the ones you will see most of the time.