Scheme Message Passing - Built-in Functions




CS152

Chris Pollett

Nov 15, 2021

Outline

Introduction

Message Passing in Scheme

Quiz

Which of the following statements is true?

  1. Type inference is the process of determining if a program has any type inconsistencies.
  2. The Curry Howard correspondence is a mapping between the types: `a times b -> r` and `a -> b -> r`.
  3. It is possible to have a dotted pair that is not a list in Scheme.

Evaluation Order

Evaluation Order - A Second Example

Expression Types

Converting Arguments for Normal Order Evaluation

Infinite Lists

Some Built-in Functions

We will talk some more about evaluation order on Wednesday, for the rest of today I will talk about various built-in functions in Scheme:

Vectors

Symbols

More Advanced Bindings - let*, letrec

Iteration - do, named let

Using Named Let to Split a String

(define (tokenize l delim)
  (let loop ((t '())
             (l l))
    (if (pair? l) ; checks if dotted pair
        (let ((c (car l)))
          (if (char=? c delim)
              (cons (reverse t) (loop '() (cdr l)))
              (loop (cons (car l) t) (cdr l))))
        (if (null? t)
            '()
            (list (reverse t))))))

(define (string-split s delim)
  (map list->string (tokenize (string->list s) delim))) 
  ; map takes a function f and a list (e1 e2 ... en) and computes 
  ; ((f e1) (f e2) ... (f en))

(string-split "hi there" #\space) ; returns ("hi" "there")

Input

Output