EECS 111 Lecture Notes - Lecture 17: Dillo, Mutation

40 views4 pages
(require'cs111/define-struct)'---->'This'needs'to'be'at'the'top'of'your'file'in'Advanced'Student'
Language'when'working'with'mutation'
Now:'(set-type-name-field-name!)'--->'we'are'changing'something'
Before:'
Predicate:'album?'
Selectors:'album-title,'album-artist,'album'genre
NOW:
Mutators:'set-album-title!
Ex.'(set-album-title!'My-album'"Billy'Jean")'---->'This'changes'the'album'title'to'Billy'Jean
Ex.'Snake:'weight'(number)'and'food'(symbol)'
Example
Feed-snake!:'snake'->'void
Feeds'the'snake'a'5lb'meal'
Effect:'the'input'snake'weighs'5lb'more'(need'an'effect'statement)
(define'(feed-snake's)
…)
Begin'executes'a'sequence'of'expressions'and'returns'the'value'of'the'last'expression'
So'we'use'begin'when'we'need'to'do'multiple'things'
With'"when"'and'"unless"'you'can'ONLY'do'one'thing'in'some'situations'and'not'do'ANYTHING'in'
others
"when"'the'dillo'is'not'dead
"unless"'the'dillo'is'dead
SUBTYPING
We'want'to'be'able'to'say'
All'cats'are'animals
Not'all'animals'are'cats
Similarly,'all'dogs'are'animals
All'mice'are'animals
(define-struct'(type-name'parent-type)'(fields))
Type-name'is'a'new'subtype'of'parent'type'
Ex.'(define-struct'(cat'animal)'fields…))
The'parent'type'has'to'be'a'previously'defined'struct'("animal"'has'to'already'be'previously'defined)
Imperative*Programming:*Mutation
Wednesday,' February'28,'2018
11:56'AM
Unlock document

This preview shows page 1 of the document.
Unlock all 4 pages and 3 million more documents.

Already have an account? Log in

Get OneClass Notes+

Unlimited access to class notes and textbook notes.

YearlyBest Value
75% OFF
$8 USD/m
Monthly
$30 USD/m
You will be charged $96 USD upfront and auto renewed at the end of each cycle. You may cancel anytime under Payment Settings. For more information, see our Terms and Privacy.
Payments are encrypted using 256-bit SSL. Powered by Stripe.