Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007
subversion revision control with squeak
coweb assignment 3
coweb assignment 2
coweb assignment 1:
classes and instances are both objects, with the distinction that objects
are instances of classes, while classes are instances of Metaclass.
the two are related in that classes typically contain methods for creating
instances of that class.
instance variables and methods belong to instances of a class; class
variables and methods are also instance variables and methods – they just
belong to an instance of Metaclass.
message passing is the act of sending a message to an object, which fits
into the smalltalk style of programming in that nearly everything must be
expressed as a message passed to an object; there is very little syntactic
message passing works together with class-based inheritance in that if an
object doesn't understand a message, it is passed to its parent class for
interpretation, and so on up the inheritance hierarchy.
advantages: since messages are interpreted at runtime, one can write test
cases for objects that don't exist.
disadvantages: interpreting messages at runtime is insanely slow.
inspecting a morph: this opens a window which shows a list of instance
variables. by clicking on a variable, its value is displayed.
inspect model: same as above, but its target is the model associated with a
inspect owner chain: i have no idea what this does.
browse morph: similar to inspection, but a tree view is shown. unlike the
inspection view, the tree view allows one to expand and browse the objects
that a morph is composed of.
these tools are supposed to make up for the lack of documentation by
allowing one to "explore" the system – for instance, if a morph's behavior
isn't documented, just inspect it and watch its instance variables change
as messages are passed to it. hmm, i wonder if one could inspect the
virtual machine somehow and view all the messages being passed between
objects. if this could be done inside the VM, you'd need some intelligent
filtering to avoid a nasty positive feedback loop.
n < 2
^((fibonacci: (n-1)) + (fibonacci: (n-2)))
| data onlyPositiveNumbers |
this declares 'data' and 'onlyPositiveNumbers' as local variables.
data := OrderedCollection withAll: #(1 2 3 -4 -5 'error' 6 -7 999 2).
this creates an instance of OrderedCollection based on the array passed in
the message, then causes 'data' to point to that instance.
onlyPositiveNumbers := [:i | (i isKindOf: Number) and: [i positive]].
this causes 'onlyPositiveNumbers' to point to a block of code which, when
executed with an argument, returns whether the argument is an instance of
Number & whether the Number is positive.
data := data select: onlyPositiveNumbers.
this filters 'data' using the block of code known as 'onlyPositiveNumbers'
and causes 'data' to point to the results.
data := data copyUpTo: 999. "not including"
this apparently filters the numbers now contained in 'data' to only
including numbers less than 999. this is a pretty stupid thing to put in an
API. why isn't there a copyPositiveNumbers method?
Transcript show: data average
sends the results of passing the 'average' message to the 'data' object to
Link to this Page