From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, T_FILL_THIS_FORM_SHORT autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,ce0900b60ca3f616 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-11-02 16:20:43 PST Path: archiver1.google.com!news1.google.com!sn-xit-02!sn-post-01!supernews.com!corp.supernews.com!not-for-mail From: "Matthew Heaney" Newsgroups: comp.lang.ada Subject: Re: List container strawman Date: Fri, 2 Nov 2001 19:24:01 -0500 Organization: Posted via Supernews, http://www.supernews.com Message-ID: References: <9rti6v$hcu$1@news.huji.ac.il> <1EyE7.10050$xS6.13527@www.newsranger.com> <9rue9f$j4t$1@nh.pace.co.uk> <9ruiet$kqg$1@nh.pace.co.uk> <3BE3235D.E292B890@boeing.com> X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4807.1700 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4807.1700 X-Complaints-To: newsabuse@supernews.com Xref: archiver1.google.com comp.lang.ada:15713 Date: 2001-11-02T19:24:01-05:00 List-Id: "Jeffrey Carter" wrote in message news:3BE3235D.E292B890@boeing.com... > Another place where some compiler writers use tricks is the interaction > between a random number Generator value and the Random function. The > generator holds the state data for the algorithm, which are supposed to > be updated when a number is generated. You can implement Generator as a > controlled type with a pointer to the state data, but again other tricks > are possible from within the compiler. Why would you need to implement type Generator as a Controlled type? Generator state is allocated on the stack, so Finalization is not required. Allocating state on the heap and using Controlled Finalization would be a horribly inefficient way to implement that type. No heap allocation or compiler magic is needed to implement Generator; just use the Rosen Trick: package P is type Generator is limited private; function Random (G : Generator) return Integer; private type Handle_Type (G : access Generator) is null record; type Generator is limited record Handle : Handle_Type (G'Access); State : State_Type; --whatever end record; end P; package body P is function Random (G : Generator) return Integer is State : State_Type renames G.Handle.G.all; begin -- modify State as necessary return X; end; end P; This is all perfectly legal.