ORIGIN '~beta/basiclib/betaenv'; INCLUDE '~beta/containers/list'; -- program: Descriptor -- (# textValue: (# value: ^text do INNER exit value[] #); printBase: (# name:< textValue; nl: (# do ','->putline #); show: (# name: ^text; unit:< textValue; enter name[] do name[]->puttext; ': '->puttext; INNER ; unit->puttext; nl; #); showBool: show (# value: @boolean enter value do (if value then 'yes'->puttext else 'no'->puttext if); #); showInt: show (# value: @integer enter value do value->putint #); showString: show (# value: ^text enter value[] do value[]->puttext #); do name->puttext; INNER ; newline; #); Person: (# init: (# enter (Name,Address,Age) do Kids.init exit THIS(Person)[] #); print: printBase (# name:: (# do THIS(Person).Name[]->value[] #); do nl; 'living at '->puttext; Address[]->puttext; nl; (if Age > 21 then 'already '->puttext else 'only '->puttext if); Age->putint; ' years old'->puttext; nl; (if not Kids.empty then 'and with '->puttext; Kids.size->putint; ' hungry kids to feed'->puttext; if); (* Add code to print their names here! *) #); Name: @text; Address: @text; Age: @integer; Kids: @list (# element:: Person #); #); Vehicle: (# init:< (# enter (Brand,Owner[],Payload) #); print:< printBase (# do ('Brand',Brand[])->showString; ('Payload',Payload) ->showInt (# unit:: (# do 'kg'->value #) #); INNER ; 'And owned by:\n\n'->puttext; Owner.print; #); Brand: @text; Payload: @integer; Owner: ^Person; #); RegisteredVehicle: Vehicle (# init::< (# enter RegistrationNo #); print::< (# do ('Reg. number',RegistrationNo[])->showString; INNER #); RegistrationNo: @text; #); UnregisteredVehicle: Vehicle (# init::< (# enter Insured #); print::< (# do ('Insured',Insured)->showBool; INNER #); Insured: @boolean; #); Motorcycle: RegisteredVehicle (# init:: (# enter WithSideCar #); print:: (# do ('With side car',WithSideCar)->showBool #); WithSideCar: @boolean; #); Car: RegisteredVehicle (# init:: (# enter Model #); print:: (# do ('Model',Model[])->showString #); Model: @text; #); Truck: RegisteredVehicle (# init:: (# enter WithTrailer #); print:: (# do ('With trailer',WithTrailer)->showBool #); WithTrailer: @boolean; #); Bicycle: UnregisteredVehicle (# init:: (# enter FrameNo #); print:: (# do ('Frame number',FrameNo[])->showString #); FrameNo: @text; #); HorseDrawnCarriage: UnregisteredVehicle (# init:: (# enter NoOfHorses #); print:: (# do ('Number of horses',NoOfHorses)->showInt #); NoOfHorses: @integer; #); Moped: UnregisteredVehicle (# init:: (# enter (FrameNo,EngineNo) #); print:: (# do ('Frame number',FrameNo[])->showString; ('Engine number',EngineNo[])->showString; #); FrameNo,EngineNo: @text; #); aPerson: @person; aVehicle: ^Vehicle; aCar: @Car; do ('Santa Claus','Qaqortoq, Greenland',937)->aPerson.init; ('Itty','her father' 's place',78)->(&Person[]).init->aPerson.Kids.append; ('Gritty','his father' 's place',114)->(&Person[]).init->aPerson.Kids.append; ('Bitty','her father' 's place',156)->(&Person[]).init->aPerson.Kids.append; ('Mercedes Benz' (* Brand *) ,aPerson[] (* Owner *) ,100000000 (* Payload (lots of presents) *) ,'-27/b' (* Registration number *) , 'special, reindeer-driven version') (* Model *) ->aCar.init; aCar[]->aVehicle[]; '\nWe have one person with 3 kids and 1 car. '->putline; newline; 'The car is:'->putline; newline; aVehicle.print; (* Try to trace what happens! *) #)