comp.lang.ada
 help / color / mirror / Atom feed
* access function in strings.maps
@ 1997-04-25  0:00 Dennis W. Butler
  1997-04-26  0:00 ` Robert Dewar
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Dennis W. Butler @ 1997-04-25  0:00 UTC (permalink / raw)




I've been exploring the string handling capabilities of Ada95 and have
stumbled across a Thing I can't figure out. In the strings.maps package
(LRM section A.4.2), there is a type definition that reads:

type Character_Mapping_Function is access function (From : in character)
return character;

I would have thought a Character_Mapping_Function would be more like:

function Character_Mapping_Function (The_Map: in Character_Mapping;
Domain_Character: in Character) return Character; -- range character

Although I read LRM section 3.10, I couldn't figure out the access
function type definition. Where can I get an explanation of what the
type definition does and how I can use it? I did note that the LRM says
that the Character_mapping_Function is used for transformational
mappings in the Translate subprograms...does this mean I'm not supposed
to worry about it?

Thanks,

Dennis Butler
Computer Science Department
Cal Poly, San Luis Obispo




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

* Re: access function in strings.maps
  1997-04-25  0:00 access function in strings.maps Dennis W. Butler
  1997-04-26  0:00 ` Robert Dewar
@ 1997-04-26  0:00 ` Ben Brosgol
  1997-04-28  0:00 ` Stephen Leake
  2 siblings, 0 replies; 4+ messages in thread
From: Ben Brosgol @ 1997-04-26  0:00 UTC (permalink / raw)



Dennis W. Butler wrote:
> 
> I've been exploring the string handling capabilities of Ada95 and have
> stumbled across a Thing I can't figure out. In the strings.maps package
> (LRM section A.4.2), there is a type definition that reads:
> 
> type Character_Mapping_Function is access function (From : in character)
> return character;
> 
> I would have thought a Character_Mapping_Function would be more like:
> 
> function Character_Mapping_Function (The_Map: in Character_Mapping;
> Domain_Character: in Character) return Character; -- range character

The latter is in fact present as the Value function:
   function Value( Map : in Character_Mapping; Element : in Character )
      return Character;
 
> Although I read LRM section 3.10, I couldn't figure out the access
> function type definition. Where can I get an explanation of what the
> type definition does and how I can use it? I did note that the LRM says
> that the Character_mapping_Function is used for transformational
> mappings in the Translate subprograms...does this mean I'm not supposed
> to worry about it?

A good place to look is the Rationale; here's what it says in Part
Three, Section A.2.4:

"There is another possible representation for mappings [besides an array
whose index subtype and element subtype are both Character], namely an
access value denoting a function whose domain and range are the
character type in question.  This would be useful where the domain and
range are very large sets, and in fact is used in the string handling
packages for Wide_Character and Wide_String.  To avoid unnecessary
differences between the String and Wide_String packages, we have
supplied the analogous access-to-subprogram type in Strings.Maps:
   type Character_Mapping_Function is 
      access function( From : in Character ) return Character;
Each subprogram that takes a Character_Mapping parameter is overloaded
with a version that takes a Character_Mapping_Function."

For example, suppose you want to translate a string where each character
is to map to its successor, with wrap around.  You could compose a
Character_Mapping by calling To_Mapping, supplying domain and range
character sequences, but the notation is somewhat clumsy.  If you can
tolerate the additional run-time overhead, then use a
Character_Mapping_Function instead:
   function Successor( From : Character ) return Character is
   begin
      return Character'Val( 
        Interfaces.Unsigned_8( Character'Pos(From) ) + 1 );
   end Successor;
   ...
   Translate( My_String, Successor'Access );
> 
> Thanks,
> 
> Dennis Butler
> Computer Science Department
> Cal Poly, San Luis Obispo

You're welcome,

Ben Brosgol
Aonix
200 Wheeler Rd.
Burlington, MA 01803
brosgol@aonix.com




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

* Re: access function in strings.maps
  1997-04-25  0:00 access function in strings.maps Dennis W. Butler
@ 1997-04-26  0:00 ` Robert Dewar
  1997-04-26  0:00 ` Ben Brosgol
  1997-04-28  0:00 ` Stephen Leake
  2 siblings, 0 replies; 4+ messages in thread
From: Robert Dewar @ 1997-04-26  0:00 UTC (permalink / raw)



Dennis Butler says

<<Although I read LRM section 3.10, I couldn't figure out the access
function type definition. Where can I get an explanation of what the
type definition does and how I can use it? I did note that the LRM says
that the Character_mapping_Function is used for transformational
mappings in the Translate subprograms...does this mean I'm not supposed
to worry about it?>>

You only need to worry about it if you need to use this facility. If
you don't need to define specialized translation functions, you don't
need to worry, if you do need to define such functions, this is the
mechanism! 





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

* Re: access function in strings.maps
  1997-04-25  0:00 access function in strings.maps Dennis W. Butler
  1997-04-26  0:00 ` Robert Dewar
  1997-04-26  0:00 ` Ben Brosgol
@ 1997-04-28  0:00 ` Stephen Leake
  2 siblings, 0 replies; 4+ messages in thread
From: Stephen Leake @ 1997-04-28  0:00 UTC (permalink / raw)




Dennis W. Butler wrote:
> 
> I've been exploring the string handling capabilities of Ada95 and have
> stumbled across a Thing I can't figure out. In the strings.maps package
> (LRM section A.4.2), there is a type definition that reads:
> 
> type Character_Mapping_Function is access function (From : in character)
> return character;
> 
> I would have thought a Character_Mapping_Function would be more like:
> 
> function Character_Mapping_Function (The_Map: in Character_Mapping;
> Domain_Character: in Character) return Character; -- range character
> 
Nope, 'Character_Mapping_Function' is used for _encoding_ a complex map
as a function.

> Although I read LRM section 3.10, I couldn't figure out the access
> function type definition. Where can I get an explanation of what the
> type definition does and how I can use it? I did note that the LRM says
> that the Character_mapping_Function is used for transformational
> mappings in the Translate subprograms...does this mean I'm not supposed
> to worry about it?

Thus Translate takes a 'Character_Mapping_Function' as a parameter to
specify the map. I got this explanation from Cohen's "Ada as a Second
Language"; a very good and thorough book. For a list of other good
books, see:

http://www.adahome.com/Resources/Books/ada95reviews.html
 
> Thanks,
> 
> Dennis Butler
> Computer Science Department
> Cal Poly, San Luis Obispo

You're welcome.
-- 
- Stephe




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

end of thread, other threads:[~1997-04-28  0:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-04-25  0:00 access function in strings.maps Dennis W. Butler
1997-04-26  0:00 ` Robert Dewar
1997-04-26  0:00 ` Ben Brosgol
1997-04-28  0:00 ` Stephen Leake

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