Fundamentals of Computer Science I (CS151 2003F)
[Skip to Body]
Primary:
[Front Door]
[Current]
[Glance]
-
[Honesty]
[Instructions]
[Links]
[Guidelines for Lab Writeups]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Readings]
[Reference]
Misc:
[Scheme Report]
[Glimmer Scheme Reference]
[CSC151.01 (Gum)]
[CSC151 2003S]
[CSC151 2002F]
[SamR]
Back to Records. On to Object Lab.
Held: Thursday, 4 December 2003
Summary: Today we consider how to make objects that encapsulate values and provide capabilities for manipulating those values.
Related Pages:
Notes:
Overview:
(define greeter
(lambda (message)
(cond
((eq? message ':enter) (display "Hello") (newline))
((eq? message ':leave) (display "Goodbye") (newline))
(else (error "Unknown Message")))))
> (greeter ':enter)Hello > (greeter ':leave)Goodbye > (greeter ':sleep)Unknown Message
let
outside the lambda for the procedure.
(define fixed-value
(let ((value 5))
(lambda (message)
(cond
((eq? message ':get) value)
(else (error "fixed-value:" "unknown message"))))))
(define incrementable-value
(let ((value (vector 0)))
(lambda (message)
(cond
((eq? message ':get) (vector-ref value 0))
((eq? message ':add1!)
(vector-set! value 0
(+ 1 (vector-ref value 0))))
(else (error "fixed-value:" "unknown message"))))))
> (incrementable-value ':get) 0 > (incrementable-value ':add1!) > (incrementable-value ':get) 1
Back to Records. On to Object Lab.
[Skip to Body]
Primary:
[Front Door]
[Current]
[Glance]
-
[Honesty]
[Instructions]
[Links]
[Guidelines for Lab Writeups]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Readings]
[Reference]
Misc:
[Scheme Report]
[Glimmer Scheme Reference]
[CSC151.01 (Gum)]
[CSC151 2003S]
[CSC151 2002F]
[SamR]
Disclaimer:
I usually create these pages on the fly
, which means that I rarely
proofread them and they may contain bad grammar and incorrect details.
It also means that I tend to update them regularly (see the history for
more details). Feel free to contact me with any suggestions for changes.
This document was generated by
Siteweaver on Tue Dec 9 14:00:02 2003.
The source to the document was last modified on Mon Sep 1 13:30:51 2003.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2003F/Outlines/outline.51.html.
You may wish to
validate this document's HTML
;
;
Check with Bobby