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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,8276b2994037cd71 X-Google-Attributes: gid103376,public From: wayne lydecker Subject: Re: disjoint ranges ? Date: 2000/10/13 Message-ID: <39E7E7CE.F93454CD@pacbell.net>#1/1 X-Deja-AN: 681263256 Content-Transfer-Encoding: 7bit References: <39E612C9.9BF98CD3@laas.fr> <39E79F17.24DB0828@pacbell.net> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii X-Complaints-To: abuse@cts.com X-Trace: thoth.cts.com 971499425 15890 63.202.234.35 (14 Oct 2000 04:57:05 GMT) Organization: CTSnet Internet Services Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 2000-10-13T00:00:00+00:00 List-Id: > wayne lydecker wrote: > > >How about using a boolean array: > > > > with Text_IO; > > procedure lunch is > > type Hours is new Integer range 0 .. 23 ; > > Lunch_Hours : array (Hours) of Boolean := > > (7..9 => True, 12..14 => True, 19..21 => True, others => False); > > begin > > if Lunch_Hours(7) then > > text_io.put_line("Lunch time"); > > else > > text_io.put_Line("Get back to work"); > > end if; > > end; > > This is one of those, "I can find a way to do it in my language," examples. > We can ultimately solve any programming problem in any programming > language (Yes, I exaggerate slightly), but this returns us to the issue of > expressiveness versus expressibility. Certain languages are more expressive > of certain problems. They directly map the solution space to the problem > space. > > The original post, if I read it correctly, was not concerned with the question, > "Can such and such be accomplished," but rather, "Is there a syntax to > directly express the solution to the given problem?" Pat Rogers candidly > and succinctly answered, "No." That was a correct answer. > > Richard Riehle I see your point. Mine was a simple solution but did not employ sets. To mimic the union of homogenous sets is relatively simple, here is how I did it. There are many more operators other than "in" that could also be coded, but I suspect that that is the reason it's not part of the language. -- Wayne. package Sets is type Set_Type is array (1..2) of Integer; type Set_Array_Type is array (Positive range <>) of Set_Type; function Is_In (Value : Integer; Set_Array : Set_Array_Type) return Boolean; end; ---------- package body Sets is function Is_In (Value : Integer; Set_Array : Set_Array_Type) return Boolean is begin for SA in Set_Array'range loop if Value >= Set_Array(SA)(1) and Value <= Set_Array(SA)(2) then Return True; end if; end loop; Return False; end; end; ------------ with Sets; with Text_IO; procedure Lunch is Lunch_Hours : constant Sets.Set_Array_Type := ((7,9), (12,14), (19,21)); begin if Sets.Is_In (7, Lunch_Hours) then text_io.put_line("Lunch time"); else text_io.put_Line("Get back to work"); end if; end;