Table of ContentsThe SchemeProgramming Language Scheme philosophy Scheme Locally available versions C vs. Scheme expressions Prefix vs. infix Nested expressions 1 Nested expressions 2 Nested expressions 3 Nested expressions 4 Nested expressions 5 Evaluating arguments Types More types What’s in a symbol? Some “literals”evaluate to themselves Symbols evaluate byvariable lookup define special form Lists evaluate byprocedure application* Special forms List evaluation Creating a symbol’s value Suppressing evaluation quote special form Quoting Forcing evaluation with eval The Lambda Calculus Creating procedures withthe lambda special form A moment for syntax Naming a procedure Shorthand forprocedure definition Procedures vs. variables Conditionals:if special form C vs. Scheme C vs. Scheme eq? proceduretests for identity equality Recursion Linear recursive process Lists are made of cons cells cons cells and thecons procedure List syntax shorthand car, cdr, and friends Nested lists Do not try this at home our-list-ref procedure our-list-ref traceLinear iterative process Contrast theinductive steps Tail-recursion our-list-ref tail recursion Re-binding is NOT assignment Thinking recursively Recursion is aboutbeing a smart-aleck! Recursion templates Augmenting recursion examples More augumenting recursion Reducing functions Tail recursive version offactorial Tail recursive factorial trace Conditional augumentation Insertion sort Nested procedure defines Factoring outcommon sub-expressions let special form Scope is visibility let bindings happenin parallel Bad let bindings let* special form More about conditionals:cond special form cond example Short-circuiting and, orspecial forms Boolean values & and, or Procedures are first-class values map, a higher-order function Filter procedure Typechecking predicates Procedure factories Building procedures Dr. Scheme Graphics lambdas and closures lambdas andtheir environments Free variables andLexical Scoping Dynamic Scoping Lexical vs. Dynamic Scope Lexical scopeand variable hiding When the arguments don’t fit A more direct approach:the apply procedure Procedure arity Rest arguments Controlling evaluationinside of lists quasiquote and unquote Forcing and suppressingevaluation are fundamental Comparisons eq?, eqv?, equal? More eq?, eqv?, equal? Objects/values in theScheme Heap Do not use eq? for numbers Making new lists Sharing of list structure append mustduplicate the list List surgery set-cdr! and set-car! Assignment set! procedure Other side-effects Sequencing andthe begin special form Side effects and Scwm for-each procedure Commenting example Commenting style Memory management Scheme memory model A view of garbage Mark and sweepgarbage collection Reference counting Reference countingnever reclaims cycles Mark and sweep vs.Reference counting |
Author: Greg J. Badros & Alan Borning |