comp.lang.ada
 help / color / mirror / Atom feed
From: wayne lydecker <wlydeckr@pacbell.net>
Subject: Re: disjoint ranges ?
Date: 2000/10/13
Date: 2000-10-13T00:00:00+00:00	[thread overview]
Message-ID: <39E7E7CE.F93454CD@pacbell.net> (raw)
In-Reply-To: 39E79F17.24DB0828@pacbell.net

> 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;




  reply	other threads:[~2000-10-13  0:00 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-10-12  0:00 disjoint ranges ? Philippe Torres
2000-10-12  0:00 ` Pat Rogers
2000-10-12  0:00   ` Ehud Lamm
2000-10-12  0:00     ` Pat Rogers
2000-10-13  0:00       ` Ehud Lamm
2000-10-13  0:34       ` Jeff Carter
2000-10-13  0:00         ` Philippe Torres
2000-10-14  3:12           ` Robert Dewar
2000-10-16  0:00             ` Robert A Duff
2000-10-16  0:00               ` Robert Dewar
2000-10-16  0:00               ` Lao Xiao Hai
2000-10-17  0:00                 ` Robert A Duff
2000-10-17  0:00                   ` Lao Xiao Hai
2000-10-18  0:00                   ` dmitry6243
2000-10-18  0:00                 ` Robert Dewar
2000-10-18  0:00                   ` Robert A Duff
2000-10-19  3:08                     ` Overloading "in" (was: disjoint ranges ?) Jeff Carter
2000-10-19  0:00                       ` Ehud Lamm
2000-10-21  0:00                       ` Robert Dewar
2000-10-21  0:00                         ` Jeff Carter
2000-10-13  0:00         ` disjoint ranges ? Marin David Condic
2000-10-14  3:14           ` Robert Dewar
2000-10-13  0:00     ` Philippe Torres
2000-10-13  0:00 ` Lao Xiao Hai
2000-10-14  3:17   ` Robert Dewar
2000-10-16  0:00   ` Robert A Duff
2000-10-13  0:00 ` wayne lydecker
2000-10-13  0:00   ` wayne lydecker [this message]
2000-10-13  0:00   ` Lao Xiao Hai
2000-10-23  0:00     ` Charles Hixson
2000-10-24  0:00       ` dmitry6243
2000-10-24  0:00 ` Andrew Cooke
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox