R7RS Scheme Flashcards

Table of Contents

Scheme Basics

Define   drill r7rs_scheme

Front

(define x 5)

Back

Defines a variable x with the value 5

Lambda   drill r7rs_scheme

Front

(lambda (x) (* x x))

Back

An anonymous function that squares its argument

Car   drill r7rs_scheme

Front

(car '(a b c))

Back

Returns a (the first element of the list)

Cdr   drill r7rs_scheme

Front

(cdr '(a b c))

Back

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

Cons   drill r7rs_scheme

Front

(cons 'a '(b c))

Back

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

Control Structures

If   drill r7rs_scheme

Front

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

Back

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

Let   drill r7rs_scheme

Front

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

Back

Creates local bindings, evaluates to 3

Map   drill r7rs_scheme

Front

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

Back

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

Apply   drill r7rs_scheme

Front

(apply + '(1 2 3 4))

Back

Returns 10 (applies + to the list of arguments)

Filter   drill r7rs_scheme

Front

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

Back

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

Author: Jason Walsh

j@wal.sh

Last Updated: 2024-10-30 16:43:54