3
(require slideshow/code)
4
(require scheme/pretty)
5
(require (file "compile.rkt"))
10
(define (large-text txt)
11
(text txt (current-main-font) 62))
13
(define (pretty-syntax sexp . cols)
14
(let ((port (open-input-string (apply pretty-format (cons sexp cols)))))
15
(port-count-lines! port)
16
(read-syntax "<no-name>" port)))
18
(define-syntax code-reduce
22
(hb-append (code exp) (tt " => ") (code (unsyntax t)))))))
29
(else (* n (fact (- n 1))))))
38
(large-text "Introduction to Racket"))
42
(colorize (bt "University of Utah") "red")
43
(colorize (t "matt.might.net") "blue")))
47
#:title "Why learn Racket (or Lisp)?"
48
(para #:align 'center #:width 500
49
"A good FORTRAN programmer can write FORTRAN in any language.")
52
(para #:align 'center #:width 450 "A good Lisp programmer can write any language in Lisp.")
57
#:title "Why learn Racket (or Lisp)?"
58
(para #:align 'center #:width 400
59
"A good C programmer can write C in any language.")
61
(para #:align 'center #:width 450 "A good Racket programmer can write any language in Racket.")
67
#:title "What is Racket?"
69
(item "Lisp is λ-calculus done right.")
70
(item "Scheme is Lisp done right.")
71
(item "Racket is Scheme done right."))
76
#:title "Origins of Scheme: Lisp"
81
(scale (bitmap "jmcbw.jpg") 0.5)
85
(item #:width 200 (t "Lisp created in 1958"))
86
(item #:width 200 (t "Based on λ-calculus"))
87
(item #:width 200 (t "Based on list-processing"))
88
(item #:width 200 (t "S-Expression syntax"))
89
(item #:width 200 (t "Code acts as data"))
90
(item #:width 200 (t "Data acts as code"))
95
#:title "Core S-Expression syntax"
97
(tt "<s-exp> ::= <symbol> ")
98
(tt " | (<s-exp> ...)"))
102
#:title "S-Expressions: Benefits"
106
(item #:width 200 "Human-readable")
107
(item #:width 200 "Human-writable")
108
(item #:width 200 "Easy to parse")))
113
#:title "S-Expression example"
118
(tt " (ship (name Enterprise)")
121
(tt " (ship (name Galactica) ")
126
#:title "XML: High-calorie S-Expressions"
132
(tt " <name>Enterprise</name>")
138
(tt " <name>Galactica</name>")
148
#:title "S-Expressions: Universal syntax"
151
(tt "class Dog extends Pet {")
152
(tt " void bark() { ")
153
(tt " print(\"woof\") ; ")
160
(tt "(class Dog extends Pet")
161
(tt " (void (bark) ")
162
(tt " (print \"woof\")))")))
168
(tt " (extends Pet)")
173
(tt " (type (-> () void)) ")
174
(tt " (body (print \"woof\"))))))")))))
185
(bitmap "steele.jpg")
189
(item #:width 200 (t "Lisp done right, 1978"))
190
(item #:width 200 (t "Fixed scoping oversight"))
191
(item #:width 200 (t "Purified formal semantics"))
192
(item #:width 200 (t "Hygienic macro system"))
204
(bitmap "matthew.jpg")
208
(item #:width 200 (t "Scheme done right, 2010"))
209
(item #:width 200 (t "Added huge library system"))
210
(item #:width 200 (t "Adds modules, structs, etc."))
211
(item #:width 200 (t "Batteries included"))
217
#:title "Racket example: Factorial"
222
(else (* n (fact (- n 1))))))))
226
#:title "Racket programs"
227
(tt "<body> ::= <def> ... <exp> ..."))
230
#:title "Definitions"
233
(tt "<def> ::= (define (<id> <params>) <body>)")
234
(tt " | (define <id> <exp>)")))
238
(define (subset-scheme-slide show-core show-global show-basic show-sugar)
240
#:title "A subset of Scheme expressions"
242
(tt "<exp> ::= <var>")
243
(show-basic (tt " | <num>"))
244
(show-basic (tt " | <prim>"))
245
(show-basic (tt " | <bool>"))
247
(show-core (tt " | (<exp> <exp> ...)"))
248
(show-core (tt " | (λ (<params>) <body>)"))
250
(show-basic (tt " | (if <exp> <exp> <exp>)"))
251
(show-sugar (tt " | (cond (<exp> <exp>) ...)"))
253
(show-sugar (tt " | (let ((<var> <exp>) ...) <body>)"))
254
(show-sugar (tt " | (let* ((<var> <exp>) ...) <body>)"))
255
(show-sugar (tt " | (letrec ((<var> <exp>) ...) <body>)"))
257
(show-sugar (tt " | (quote <sexp>)"))
258
(show-sugar (tt " | (quasiquote <qq-sexp>)"))
260
(show-global (tt " | (begin <body>)"))
261
(show-global (tt " | (set! <var> <exp>)"))
264
;(subset-scheme-slide id id id id)
265
;(subset-scheme-slide id id id ghost)
266
;(subset-scheme-slide id id ghost ghost)
267
;(subset-scheme-slide id ghost ghost ghost)
273
(large-text "A tour of Racket"))
279
(item "Integers: " (code 1) "," (code -3))
281
(item "Rationals: " (code-reduce (/ 8 10)))
283
(item "\"Reals\": " (code-reduce (sqrt 2)))
285
(item "Imaginary: " (code-reduce (sqrt -1)))
287
(item "Complex: " (code-reduce (* 1+3i 1-22/7i)))
289
(item "Precise: " (code-reduce (fact 18))))
293
(item "Boolean literals " (code #t) ", " (code #f))
294
(item "Only " (code #f) " is false")
295
(item "Anything else is true")
303
(item (code cons) ", " (code car) ", " (code cdr) ", " (code '())
306
(item (code-reduce (cons 1 '())))
308
(item (code-reduce (cons 3 (cons 1 '()))))
310
(item (code-reduce '(3 1)))
312
(item (code-reduce (car (cons 3 (cons 1 '())))))
314
(item (code-reduce (cdr (cons 3 (cons 1 '())))))
316
(item (code-reduce (pair? (cons 3 4))))
318
(item (code-reduce (null? '())))
323
#:title "Quoted S-Expressions"
324
(item (code '<s-exp>) (tt " == ") (tt "(quote <s-exp>)"))
325
(item (code-reduce '<id>))
327
(item (code-reduce '3))
328
(item (code-reduce 'a))
329
(item (code-reduce '(1 2 3)))
330
(item (code-reduce (cdr '(1 2 3))))
331
(item (code-reduce '(f (g x))))
332
(item (code-reduce (car '(f (g x)))))
334
(item (code-reduce '())))
340
(item "Arithmetic: " (code +) ", " (code modulo) ", " (code quotient))
341
(item "Types: " (code null?) ", " (code pair?) ", " (code number?) ", " (code integer?))
342
(item "Lists: " (code list) comma (code cons) ", " (code car)", " (code cdr))
343
(item "Equality: " (code =)", " (code eq?)", " (code eqv?) comma (code equal?))
344
(item "Ex:" (code-reduce (gcd 248 184)))
345
(item "Ex:" (code-reduce (cons 3 (cons 4 '()))))
356
(item (para #:width 200 #:align 'left
357
(tt "<let-exp> ::= ")
358
(tt " (let ((<var> <exp>) ...) ")
360
(item (code let) " binds values to variable names")
362
(item (code-reduce (let ((π 3.14)
366
(item (code (let ((π 3.14)
368
2*π)) (colorize (tt " =/=> ") "red") (code 6.28)))
376
(item (para #:width 200 #:align 'left
377
(tt "<let*-exp> ::= ")
378
(tt " (let* ((<var> <exp>) ...) ")
380
(item (code let*) " binds values to variable names sequentially")
382
(item (code-reduce (let* ((π 3.14)
386
(item (code-reduce (let* ((π 3.14)
396
(item "Any symbol allowed")
398
(item "Roughly: " (tt "[^()'`,]+"))
400
(item "Ex:" (code foo))
402
(item "Ex:" (code foo-bar))
404
(item "Ex:" (code π) comma (code Δ) comma (code ∞) comma (code Σ) comma (code ⊑) comma (code ∅) comma (code →))
406
(item "Ex:" (code pair?))
408
(item "Ex:" (code call-with-current-continuation))
410
(item "Ex:" (code-reduce (let ((let 3)) let))))
417
(item "λ produces anonymous functions")
418
(item (tt "<lambda> ::= (λ (<var> ...) <body>)"))
419
; (item (tt "<params> ::= <var> ..."))
420
(item (code-reduce ((λ (x) (* x x)) 3)))
421
(item (code (let ((λ (λ (λ) (λ λ)))) (λ λ)))))
427
#:title "Lexical scope"
429
(t "To what does the following evaluate?")
443
#:title "Lexical scope"
444
(item "λ-terms capture bindings in scope")
445
(item "WYSIWYG for anonymous functions"))
452
#:title "Obligatory derivative example"
457
(define (D f) (λ (x) (/ (- (f (+ x ε)) (f x))
460
(define (g x) (* x x))
470
#:title "Conditionals"
471
(item (tt "<if-exp> ::= (if <exp> <exp> <exp>)"))
472
(item (tt "<cond-exp> ::= ") (tt " (cond (<exp> <exp>) ...)"))
473
(item (code-reduce (if 'a 'b 'c)))
474
(item (code-reduce (if #f 'b 'c)))
475
(item (code-reduce (cond
478
((> 3 0) 'positive)))))
483
#:title "Quasiquotes"
484
(item "Special syntax for constructing literals")
485
(item (tt "`<qq-sexp>") (tt " == ") (tt "(quasiquote <qq-sexp>)"))
486
(item (tt ",<exp>") (tt " == ") (tt "(unquote <exp>)"))
487
(item (code-reduce `(3 + 4 is ,(+ 3 4))))
489
(let ((new-ship (λ (name x y)
493
(new-ship 'Enterprise 42 1701)))
495
(code => (ship (name Enteprise)
501
#:title "Mutating variables"
503
(item (code begin) " sequences expressions, like " (tt "{}") " in C")
511
(item (code set!) " assigns to a variable, like " (tt "=") " in C")
523
#:title "Pattern-matching"
524
(item "Powerful tool for dissecting data like trees")
533
[(list 1 (? even?) ...)
535
[(list 1 (? odd?) ...)