<< Prev | - Up - |
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% cell library function
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
<Test Cell Library>
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% cell objects
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
<Test Cell.oz>
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% bags
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
<Test Bag.oz>
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% dictionary
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
<Create Dictionary from Library>
<Test Dictionary from Library>
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% collection of object style data structures
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
declare Abstract =
<Abstract.oz>
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Oz object system: stacks and queues
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
<Test Object System Stack>
Here is the collection of all the programs:
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% cell library function
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
declare C = {Cell.new unit}
{Inspect {Access C}}
{Assign C hi}
{Inspect old#{Access C}}
{Inspect old#{Exchange C $ _}}
{Inspect new#{Access C}}
{Access C} = 'the new value of C was bound late'
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% cell objects
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
declare AuthorURL = 'http://www.ps.uni-sb.de/~niehren'
CourseDir = '/Web/Vorlesungen/Oz-NL-SS01'
CourseURL = AuthorURL#CourseDir
PickleVersion= 'Version.3.2'
DataDir = '/vorlesung/Functors/'#PickleVersion
URL = CourseURL#DataDir
declare CellURL = URL#'/Cell.ozf'
declare [CellMod] = {Module.link [CellURL]}
declare C={CellMod.new 2002}
{Inspect {C.get}}
{C.put 4711}
{Inspect {C.put}}
declare NewVal OldVal = {C.exchange NewVal}
{Inspect OldVal}
NewVal=OldVal-42
{Inspect {C.get}}
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% bags
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
declare BagURL= URL#'/Bag.ozf'
declare [Bag] = {Module.link [BagURL]}
declare B = {Bag.new}
{B.put hello}
{B.put world}
{Inspect {B.toList}}
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% dictionary
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
declare D={NewDictionary}
D.foo := baz
D.hello := world
D.42 := fourtytwo
{Inspect D.hello}
D.hello := universe(D)
{Inspect {CondSelect D foo fooNotFound}}
{Inspect {CondSelect D baz bazNotFound}}
{Inspect {HasFeature D foo}}
{Inspect {HasFeature D baz}}
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% collection of object style data structures
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
declare Abstract = functor
import
Cell( new:NewCell) at 'Cell.ozf'
Bag( new:NewBag fromList:ListToBag) at 'Bag.ozf'
Dictionary(new:NewDictionary) at 'Dictionary.ozf'
Stack( new:NewStack fromList:ListToStack) at 'Stack.ozf'
Queue( new:NewQueue fromList:ListToQueue) at 'Queue.ozf'
export
newStack : NewStack
listToStack : ListToStack
newQueue : NewQueue
listToQueue : ListToQueue
newAgenda : NewStack
listToAgenda : ListToStack
newBag : NewBag
listToBag : ListToBag
newCell : NewCell
newDictionary: NewDictionary
end
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Oz object system: stacks and queues
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
declare
local
class StackClass from BaseObject
attr stack:nil
meth init stack <- nil end
meth push(E) stack <- E|@stack end
meth pop($)
Stack = @stack
in
stack <- Stack.2
Stack.1
end
meth isEmpty($)
case @stack
of nil then true
else false
end
end
meth toList($) @stack end
end
in
fun{NewStack}
Stack = {New StackClass init}
in
unit(push :proc{$ X} {Stack push(X)} end
pop :fun{$} {Stack pop($)} end
init :proc{$} {Stack init} end
isEmpty:fun{$} {Stack isEmpty($)} end
toList :fun{$} {Stack toList($)} end)
end
end
Stack = {NewStack}
in
{Inspect Stack}
{Inspect {Stack.isEmpty}}
{ForAll [1 2 3 4 5] Stack.push}
{Inspect {Stack.toList}}
<< Prev | - Up - |