CSC302 2006S, Class 12: Scheme Syntax Admin: * Homework 1 due at 5:00 p.m. * No non-reading (+question) homework next week to give you time to read carefully. Please take that time. * About the symbols after your name in readings. * What do you know about Runescape? * EC: Angeline, Dimitar Overview: * Quasiquotation * Your questions on the syntax * Preparing to read semantics /Quasiquotation/ * Quote: Don't evaluate, just give me the following verbatim * (quote .....) * '... * Quote works for list structures as well as for symbols * Problem: Sometimes you want to evaluate some parts of the quoted structures * Silly example: Build an association list of grades - Quote free attempt (define grades0 (lambda (samg samuelg alexg alexanderg) (list (list 'sam samg) (list 'samuel samuelg) (list 'alex alexg) (list 'alexander alexanderg)))) * Temptation: Remove all those inner quotes and lists and just use a quote (define grades1 (lambda (samg samuelg alexg alexanderg) '((sam samg) (samuel samuelg) (alex alexg) (alexander alexanderg)))) * Quasiquote permits us to mix the two (define grades2 (lambda (samg samuelg alexg alexanderg) `((sam ,samg) (samuel ,samuelg) (alex ,alexg) (alexander ,alexanderg)))) * The back quote means "Generally take verbatim" * The comma means "Evaluate this" * Complicating quasiquote: Nesting! * Some does not believe in quotes for beginning programmers '1 - What value? What type? * 1, integer (car '('1 'b)) - What value? What type * 1, symbol ; NOPE - 1 is an integer * (quote 1), symbol - Closer * (quote 1), list - Shorthand for (quote ((quote 1) (quote b))) (car '('a 'b)) - What value? What type * a, symbol /Other Syntax Questions/ * What are the optional # signs at the end of numbers? E.g. -> + #* * # means "I know there is some digit there, but I don't know what it is" * 3300000 vs. 33##### * Only available before the suffix - trailing digits * Why does it only support base 2, 8, 10, 16 * The are the only commonly-used bases in computing * There are signed reals, unsigned reals, unsigned integers, where are the signed integers? * I have no idea. * Given that commands are just expressions, why do they distinguish between the two? * Related: Why => * rather than + or +? * Subtle reason: Want to think about how they are used: * At this level, commands we evaluate and discard the result, expressions we evaluate and use the result * Sequences end with expressions so that they end with a result * Example (let ((x 5)) (display x) (newline) x) * Why does set! get special treatment (that is, why is it a reserved keyword)? * It changes something (nope, but good guess) * All of the reserved keywords are "functions" that do not use the normal scheme of evaluation * We write (set! a 10) Not (set! 'a 10)