I. data types in Scheme A. Scheme universe of types do any not do that? What's the advantage? ------------------------------------------ THE SCHEME TYPE UNIVERSE (not to scale) datum !------------------!=================-! ! boolean ! null ! ! ! !-----------!------! list ! ! ! !_______________________! ! ! char ! pair ! !-----------!-------------------------! ! ! ! ! number ! procedure ! ! ! ! !--------!-----------------!----------! !string / ! \ port ! ! / ! \ ! ! / symbol ! vector \ ! !-------------------------------------! ------------------------------------------ B. characteristics What characterizes (specifies) an Abstract Data Type (ADT)? ------------------------------------------ CHARACTERISTICS OF DATA TYPES IN PROGRAMMING LANGUAGES Characteristics - Values + abstract + external (printed form) - Operations + procedures + syntax of literals + special forms ------------------------------------------ 1. booleans (quickly) ------------------------------------------ EXAMPLE, THE BOOLEANS - Values - Operations + procedures: not, eqv? + syntax of literals: #t, #f + special forms: if, cond, and, or ------------------------------------------ 2. numbers Can you write a procedure "mod7" that returns the result of taking its argument modulo 7? 3. strings ------------------------------------------ STRINGS Values + abstract: finite sequences of chars + printed: "a string", "\"hi\"" Operations + procedures: string, string-append, string-ref (0 based), string-length, string=?, ... string (eq? (cons 1 '()) (cons 1 '())) #f > (equal? (cons 1 '()) (cons 1 '())) #t > (equal? (vector 1 2 3) (vector 1 2 3)) #t > (eq? (vector 1 2 3) (vector 1 2 3)) #f > (eq? 9876543210 9876543210) #f > (equal? 9876543210 9876543210) #t --------------------------------------------------------- II. Expressions in Scheme (and other languages) A. fundamental expressions ------------------------------------------ SYNTACTIC PARTS OF A PROGRAMMING LANGUAGE program definition statements expressions literals (#t, #\c, "a str") variable references (x, ls) procedure calls ( (f x), (car ls) ) ------------------------------------------ What's the translation of 5 + 6 + 7 into Scheme? How would sqrt(cos(x + 5)) be translated into Scheme? What's the syntax of a procedure call in Scheme? What's a rule for forming the Scheme from the algebraic notation? B. definitions, programs, read-eval-print loop (quickly) 1. definitions ------------------------------------------ DEFINITIONS Scheme syntax examples (define pi ; TYPE: number 3.14159) Terminology: - special form - keyword ------------------------------------------ What is like this in C++? Pascal? 2. programs ------------------------------------------ PROGRAMS Scheme syntax: a series of definitions and expressions Example (define pi 3.14159) (define greeting "Welcome!") (define is-pi? (lambda (n) (= n pi))) (display greeting) (newline) (is-pi? pi) Semantics: Terminology - top level (pi vs. n) ------------------------------------------ ------------------------------------------ READ-EVAL-PRINT LOOP What the interpreter does (exit) ---> read ----> ^ \ / v print eval ^-----/ ------------------------------------------ C. if-expressions (1.1.3) ------------------------------------------ IF-EXPRESSIONS Transcript of Scheme examples > (if #t 3 4) > (define x 2) > (if (zero? x) (+ x 3) x) > (if (< x 0) (- x) x) ------------------------------------------ So what's the Scheme syntax? Is the else-part required? Why would it be? How does this differ from an if statement in C++ or Java? What's this like in C/C++/Java? Anything like this in Visual Basic?