R7RS Scheme Flashcards

Table of Contents

1. Scheme Basics

1.1. Define   drill r7rs_scheme

1.1.1. Front

(define x 5)

1.1.2. Back

Defines a variable x with the value 5

1.2. Lambda   drill r7rs_scheme

1.2.1. Front

(lambda (x) (* x x))

1.2.2. Back

An anonymous function that squares its argument

1.3. Car   drill r7rs_scheme

1.3.1. Front

(car '(a b c))

1.3.2. Back

Returns a (the first element of the list)

1.4. Cdr   drill r7rs_scheme

1.4.1. Front

(cdr '(a b c))

1.4.2. Back

Returns (b c) (the rest of the list after the first element)

1.5. Cons   drill r7rs_scheme

1.5.1. Front

(cons 'a '(b c))

1.5.2. Back

Returns (a b c) (constructs a new list)

2. Control Structures

2.1. If   drill r7rs_scheme

2.1.1. Front

(if (> x 0) "positive" "non-positive")

2.1.2. Back

Conditional expression, returns "positive" if x > 0, "non-positive" otherwise

2.2. Let   drill r7rs_scheme

2.2.1. Front

(let ((x 1) (y 2)) (+ x y))

2.2.2. Back

Creates local bindings, evaluates to 3

2.3. Map   drill r7rs_scheme

2.3.1. Front

(map (lambda (x) (* x 2)) '(1 2 3))

2.3.2. Back

Returns (2 4 6) (applies the function to each list element)

2.4. Apply   drill r7rs_scheme

2.4.1. Front

(apply + '(1 2 3 4))

2.4.2. Back

Returns 10 (applies + to the list of arguments)

2.5. Filter   drill r7rs_scheme

2.5.1. Front

(filter even? '(1 2 3 4 5 6))

2.5.2. Back

Returns (2 4 6) (keeps only elements satisfying the predicate)