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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Received: by 2002:a5d:8d81:: with SMTP id b1mr7249324ioj.27.1548374171274; Thu, 24 Jan 2019 15:56:11 -0800 (PST) X-Received: by 2002:a9d:da3:: with SMTP id 32mr137867ots.3.1548374171019; Thu, 24 Jan 2019 15:56:11 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!news.gegeweb.eu!gegeweb.org!usenet-fr.net!proxad.net!feeder1-2.proxad.net!209.85.166.215.MISMATCH!k10no198290itk.0!news-out.google.com!v141ni256ita.0!nntp.google.com!k10no198288itk.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Thu, 24 Jan 2019 15:56:10 -0800 (PST) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=2804:14c:4c1:939b:fc5a:5773:4940:f55; posting-account=wgmHdgoAAAA-F7JItPEZjeXqFc0KdzEQ NNTP-Posting-Host: 2804:14c:4c1:939b:fc5a:5773:4940:f55 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: ? Is ok return a type derived from ada.finalization.controlled from a "Pure_Function" ? thanks. From: danielcheagle@gmail.com Injection-Date: Thu, 24 Jan 2019 23:56:11 +0000 Content-Type: text/plain; charset="UTF-8" Xref: reader01.eternal-september.org comp.lang.ada:55366 Date: 2019-01-24T15:56:10-08:00 List-Id: Hi! Is ok return a type derived from ada.finalization.controlled from a function declared "Pure_Function" ? Or yet, is ok declare a fuction returning a controlled type as "pure_function" ? Thanks in Advance!!! []'s Dani. :-) note1 : the type has a access value. note2 : initialize, adjust and finalize overrided and working :-) fragment example code: --------------------------------- pragma Ada_2012; pragma Detect_Blocking; with Ada.Finalization; package Arbitrary with preelaborate is type Arbitrary_Type (size : Positive) is new Ada.Finalization.Controlled with private; function To_Arbitrary (value : Integer; precision : Integer) return Arbitrary_Type with inline; -- Can I add "pure_function" ? private type Mantissa_Type is array (Positive range <>) of Integer; type Mantissa_Pointer is access Mantissa_Type; type Arbitrary_Type (size : Positive) is new Ada.Finalization.Controlled with record mantissa : Mantissa_Pointer; exponent : Integer; sign : Integer range -1 .. 1; precision : Positive := size; end record; end arbitrary; ----------------------------------------------- pragma Ada_2012; pragma Detect_Blocking; with Ada.Unchecked_Deallocation; package body Arbitrary is procedure Delete is new Ada.Unchecked_Deallocation (Mantissa_Type, Mantissa_Pointer); ----------------------------------------------------------------------- -- Initialize an Arbitrary_Type ----------------------------------------------------------------------- procedure Initialize (Object : in out Arbitrary_Type) is begin Object.mantissa := new Mantissa_Type (1 .. Object.precision); Object.exponent := 0; Object.sign := 1; -- "here" for diminish race condition from OS' s Object.mantissa.all := (others => 0); end Initialize; ----------------------------------------------------------------------- -- Fix an Arbitrary_Type after being assigned a value ----------------------------------------------------------------------- procedure Adjust (Object : in out Arbitrary_Type) is begin Object.mantissa := new Mantissa_Type'(Object.mantissa.all); end Adjust; ----------------------------------------------------------------------- -- Release an Arbitrary_Type; ----------------------------------------------------------------------- procedure Finalize (Object : in out Arbitrary_Type) is begin if Object.mantissa /= null then Delete (Object.mantissa); end if; Object.mantissa := null; end Finalize; ----------------------------------------------------------------------- -- Convert an Integer type to an Arbitrary_Type ----------------------------------------------------------------------- function To_Arbitrary (value : Integer; precision : Integer) return Arbitrary_Type is result : Arbitrary_Type (precision); begin result.mantissa (result.exponent + 1) := value; Normalize (result); return result; end To_Arbitrary; end arbitrary; ------------------------------------------------------------------- Really Thanks! :-) []'s Dani. :-)