comp.lang.ada
 help / color / mirror / Atom feed
* Newbie Generic Reg Exp Pattern Matching Question
@ 1994-10-03 14:54 Jimmy Fang
  1994-10-04 11:29 ` Robert I. Eachus
  0 siblings, 1 reply; 5+ messages in thread
From: Jimmy Fang @ 1994-10-03 14:54 UTC (permalink / raw)




I'm having trouble getting a generic Regular Expression Matching.
This code fragment is taken out of Booch's Software Components book.

       23  generic
       24     type ITEM is private;
       25     type INDEX is (<>);
       26     type ITEMS is array (INDEX range <>) of ITEM;
       27     Any_Item       : in ITEM;
       28     Escape_Item    : in ITEM;
       29     Not_Item       : in ITEM;
       30     Closure_Item   : in ITEM;
       31     Start_Class    : in ITEM;
       32     Stop_Class     : in ITEM;
       33     with function "=" (  Left  : in ITEM;
       34                          Right : in ITEM) return Boolean;
       **
    *****E equality parameters must be same limited type [LRM 6.7/4]
       **
       35

Now when I change "type ITEM is private" to  "... is limited private",
the compiler complains about Any_Items .. Stop_Class "cannot be
limited for in mode".

I've tried reading the LRM, but am confused by the reference.

I've gotten the other matching algorithms to run (debugging some typos
out of the book) but like the idea of using wildcards, etc.  Thanks for
any pointers.


- Jim
---------------------------------------------------------------------
Under-Gradual Student, Swinburne University of Technology, Australia





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Newbie Generic Reg Exp Pattern Matching Question
  1994-10-03 14:54 Newbie Generic Reg Exp Pattern Matching Question Jimmy Fang
@ 1994-10-04 11:29 ` Robert I. Eachus
  1994-10-04 22:03   ` Stef Van Vlierberghe
  1994-10-05  2:21   ` Tucker Taft
  0 siblings, 2 replies; 5+ messages in thread
From: Robert I. Eachus @ 1994-10-04 11:29 UTC (permalink / raw)


In article <36p5vsINNcjt@edna.cc.swin.edu.au> 944166@edna.swin.edu.au (Jimmy Fang) writes:

	  33     with function "=" (  Left  : in ITEM;
	  34                          Right : in ITEM) return Boolean;
	  **
       *****E equality parameters must be same limited type [LRM 6.7/4]
	  **
	  35

    This certainly looks like a compiler bug.  It is illegal to
explicitly declare an equality function for a private type, (except by
using the "Goodenough" workaround), but as a generic subprogram
parameter it is legitimate.

    First report the bug to your compiler vendor, then try one (or
more) of the following workarounds:

   1) It may be the case that if you provide a default the compiler
will let this through. Try:

	with function "=" (  Left  : in ITEM;
                             Right : in ITEM) return Boolean is <>;

   Can't hurt to try, and it really should be written this way anyway.

   2) Change the name of the equality subprogram in your generic formal
parameter list, and modify the body of the package to use the renamed
operation. (Ugh! Not very maintianable.)

   3) Declare a generic as follows:

    generic
      type LP is limited private;
      with function Equal(L,R: LP) return Boolean;
    function "="(L,R: LP) return Boolean;

    function "="(L,R: LP) return Boolean is
    begin return Equal(L,R); end "="
    
    Now modify your code to pass an equality function in under some
other name, then instantiate this function in the package
specification.  This is the Goodenough "trick."

  4) As in one above but hide the instantiation in the body of your
generic.



--

					Robert I. Eachus

with Standard_Disclaimer;
use  Standard_Disclaimer;
function Message (Text: in Clever_Ideas) return Better_Ideas is...



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Newbie Generic Reg Exp Pattern Matching Question
  1994-10-04 11:29 ` Robert I. Eachus
@ 1994-10-04 22:03   ` Stef Van Vlierberghe
  1994-10-05  2:21   ` Tucker Taft
  1 sibling, 0 replies; 5+ messages in thread
From: Stef Van Vlierberghe @ 1994-10-04 22:03 UTC (permalink / raw)


In article <EACHUS.94Oct4112939@spectre.mitre.org> eachus@spectre.mitre.org (Robert I. Eachus) writes:

       generic
         type LP is limited private;
         with function Equal(L,R: LP) return Boolean;
       function "="(L,R: LP) return Boolean;


The name of a generic must be an identifier, so if your compiler accepts
this, report a bug to the vendor ;-)

       generic
         type LP is limited private;
         with function Equal(L,R: LP) return Boolean;
       package GOODENOUGH_TRICK is
         function "="(L,R: LP) return Boolean;
       end;
--
Stef VAN VLIERBERGHE            Eurocontrol - Central Flow Management Unit
stef@cfmu.eurocontrol.be        Avenue des Arts 19H
Tel: +32 2 729 33 42            B-1040 BRUSSELS
Fax: +32 2 729 32 16            Belgium



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Newbie Generic Reg Exp Pattern Matching Question
  1994-10-04 11:29 ` Robert I. Eachus
  1994-10-04 22:03   ` Stef Van Vlierberghe
@ 1994-10-05  2:21   ` Tucker Taft
  1994-10-11 16:10     ` William Fang
  1 sibling, 1 reply; 5+ messages in thread
From: Tucker Taft @ 1994-10-05  2:21 UTC (permalink / raw)


In article <EACHUS.94Oct4112939@spectre.mitre.org>,
Robert I. Eachus <eachus@spectre.mitre.org> wrote:

>In article <36p5vsINNcjt@edna.cc.swin.edu.au> 
>944166@edna.swin.edu.au (Jimmy Fang) writes:
>
>	  33     with function "=" (  Left  : in ITEM;
>	  34                          Right : in ITEM) return Boolean;
>	  **
>       *****E equality parameters must be same limited type [LRM 6.7/4]
>	  **
>	  35
>
>    This certainly looks like a compiler bug.  It is illegal to
>explicitly declare an equality function for a private type, (except by
>using the "Goodenough" workaround), but as a generic subprogram
>parameter it is legitimate.

Sorry, I don't agree.  The compiler looks right.  The John Goodenough
"workaround" takes advantage of the fact that a formal limited type
can be instantiated with an actual non-limited type.  But the restriction
about "=" being defined only for limited types applies in generic
formal parts as well as outside.

>    First report the bug to your compiler vendor...

Don't bother.  The compiler is enforcing the Ada 83 rules.
By the way, in Ada 9X, there is no such limitation.

> ...
>					Robert I. Eachus

-Tucker Taft  stt@inmet.com
Intermetrics, Inc.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Newbie Generic Reg Exp Pattern Matching Question
  1994-10-05  2:21   ` Tucker Taft
@ 1994-10-11 16:10     ` William Fang
  0 siblings, 0 replies; 5+ messages in thread
From: William Fang @ 1994-10-11 16:10 UTC (permalink / raw)



Here's a message from my brother.  His site seems to have missed *all* the
followups.

--------------------------------------------------------------------------

--|	Thanks for the pointers.

--|	I have used the Goodenough "hack" to get the package going.
--|	Is John Goodenough a real person, or just a made up name?
--|	(ie Good Enough?)

--|	I don't think I'll ever be a competent Ada language-lawyer
--|	like Robert Eachus, Stef Van Vlierberghe or Tucker Taft.
--|	If I was a gambling man, I'll have to place an each way bet on
--|	the proper interpretation, as the code by Booch suggests he
--|	came to the same conclusion as Robert (assuming that Grady Booch
--|	did compile his code ;)  But the Meridian compiler seems to support
--|	Tucker and Stef.

--|	Jim

----------------------------------------------------------------------------



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~1994-10-11 16:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1994-10-03 14:54 Newbie Generic Reg Exp Pattern Matching Question Jimmy Fang
1994-10-04 11:29 ` Robert I. Eachus
1994-10-04 22:03   ` Stef Van Vlierberghe
1994-10-05  2:21   ` Tucker Taft
1994-10-11 16:10     ` William Fang

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