comp.lang.ada
 help / color / mirror / Atom feed
From: adambeneschan@gmail.com
Subject: Re: need help learning Ada for a modula-2 programmer
Date: Mon, 27 Jan 2014 17:33:08 -0800 (PST)
Date: 2014-01-27T17:33:08-08:00	[thread overview]
Message-ID: <9c721578-f490-47bb-86a5-b5330828df06@googlegroups.com> (raw)
In-Reply-To: <l90ee99ngsun16ec498p60nm3s0ah29r47@4ax.com>

On Monday, January 27, 2014 5:06:43 PM UTC-8, ag...@drrob1.com wrote:
> The following code does not compile.  I don't understand why.
> 
> The string processing fails to compile, saying "prefix of image must
> be a type"
> 
> and 
> 
> "move is undefined"

The syntax of 'Image in Ada is Type'Image(Value), not Value'Image.  Since M0 is a Natural, instead of M0'Image you would say Natural'Image(M0).  (Some compilers accept M0'Img, but that is not part of the Ada standard.  Compilers are allowed to define their own attributes such as 'Img.)

There's no built-in Move procedure.  Also, you need to be aware that the "String" type is a fixed-length array of characters; it isn't suitable for variable-length strings unless you keep track of the length yourself.  If this is what you want, you should use the type Unbounded_String in the package Ada.Strings.Unbounded.  The way you've written it:

PROCEDURE MDY2STR(M,D,Y : Natural; MDYSTR : Out String255) is 

  IntermedStr    : String(1..10); 

  Move(IntermedStr,MDYSTR);

The way you'd copy a string, or part of it, is just to assign it with :=.  However, this won't work:

  MDYSTR := IntermedStr;

because the two Strings are different lengths.  To assign the first 10 characters of MDYSTR, you need to do something like

  MDYSTR(MDYSTR'First .. MDYSTR'First + IntermedStr'Length - 1) := IntermedStr;

where MDYSTR'First is the first index (which is always 1, because of how you defined String255, but it's still best not to hardwire values when you can avoid it); IntermedStr'Length is always 10, so this will assign to characters 1..10 of MDYSTR.  However, the remaining characters of MDYSTR will be unchanged and may be garbage.  Working with strings of differing lengths like this can get difficult, which is why you may want to look into Unbounded_String which will take care of a lot of that for you.

                                  -- Adam

  reply	other threads:[~2014-01-28  1:33 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-28  1:06 need help learning Ada for a modula-2 programmer agent
2014-01-28  1:33 ` adambeneschan [this message]
2014-01-28  1:52 ` Jeffrey Carter
2014-01-28 12:18 ` Brian Drummond
2014-02-02  2:47   ` agent
2014-02-02  6:09     ` Jeffrey Carter
2014-02-02 15:02       ` agent
2014-02-02 16:00         ` gautier_niouzes
2014-02-02 19:48         ` Jeffrey Carter
2014-02-03  8:24           ` Dmitry A. Kazakov
2014-02-02 17:18     ` Brian Drummond
2014-02-03  0:10       ` agent
2014-02-03  0:36         ` agent
2014-02-03 12:53         ` Brian Drummond
2014-01-28 22:51 ` Jerry
2014-01-29 12:15   ` Mike H
2014-01-29 20:41     ` Jacob Sparre Andersen
2014-01-29 23:52       ` Jeffrey Carter
2014-01-30  9:05         ` Jacob Sparre Andersen
2014-01-30 14:20       ` Mike H
2014-01-30 14:35         ` Bill Findlay
2014-01-30 15:40           ` Mike H
2014-01-30 23:39         ` Jeffrey Carter
2014-01-31 20:16           ` Mike H
2014-01-29 23:52     ` Jeffrey Carter
2014-01-30  1:44       ` Bill Findlay
2014-01-30  2:01         ` Jeffrey Carter
2014-01-30 12:24       ` Simon Wright
2014-01-30 23:38         ` Jeffrey Carter
2014-02-03 23:12     ` agent
2014-02-04  6:10       ` J-P. Rosen
2014-02-04 22:38   ` agent
2014-01-29 16:58 ` Dirk Heinrichs
2014-01-29 20:43   ` Randy Brukardt
2014-01-29 22:53     ` Georg Bauhaus
2014-01-30 12:13       ` Simon Wright
2014-01-30 17:05     ` Dirk Heinrichs
2014-01-30 23:21       ` Randy Brukardt
2014-01-30  4:29   ` Nasser M. Abbasi
2014-01-30  8:45     ` Where to put change descriptions (Was: need help learning Ada for a modula-2 programmer) Jacob Sparre Andersen
2014-01-30  9:53     ` need help learning Ada for a modula-2 programmer Georg Bauhaus
2014-01-30 21:58       ` Randy Brukardt
2014-01-30 16:28     ` Pascal Obry
2014-01-30 17:43       ` Marius Amado-Alves
2014-01-30 18:10       ` Simon Wright
2014-01-30 22:38       ` Randy Brukardt
replies disabled

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