* array of strings in a function @ 2003-10-14 20:54 Antonio Martínez 2003-10-15 2:55 ` Robert I. Eachus ` (2 more replies) 0 siblings, 3 replies; 22+ messages in thread From: Antonio Martínez @ 2003-10-14 20:54 UTC (permalink / raw) Hello. I'm trying to pass to a function an argument. The argument is an array range <> of Strings (unbounded array). For example: my_fun("Hello", ", I'm", " the function"); number of string literals is unknown by the function. And the length of every string is unknown as well. It works if I choose a fixed length of the string, and every string is exactly the length I have forced. So, if I fixed 4, it works for me: my_fun("only", "four", "lette", "rs ", "are ", "allo", "ed "); How do I work with unbound strings? I want something like this: type Miarray is array (Positive range <>) of string; but it doen't compile !!! Thank you. -- Antonio Martï¿œnez, <pascal@eresmas.net> ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: array of strings in a function 2003-10-14 20:54 array of strings in a function Antonio Martínez @ 2003-10-15 2:55 ` Robert I. Eachus 2003-10-15 3:29 ` Jeff C, 2003-10-15 3:08 ` Jeffrey Carter 2003-10-15 11:49 ` Antonio Martínez Álvarez 2 siblings, 1 reply; 22+ messages in thread From: Robert I. Eachus @ 2003-10-15 2:55 UTC (permalink / raw) Antonio Martï¿œnez wrote: > I'm trying to pass to a function an argument. The argument is an > array range <> of Strings (unbounded array). > number of string literals is unknown by the function. And the > length of every string is unknown as well. > How do I work with unbound strings? You can create an array of Unbounded_String (found in Ada.Strings.Unbounded). Or you can use the package below. Note that in either case, you are going to have to create an array object, put the strings in it, and then pass that to the array. With the package below your example above: > my_fun("Hello", ", I'm", " the function"); Becomes: with Ada_Strings_Bounded_Array; use Ada_Strings_Bounded_Array; ... Foo: Bounded_Array(3,13); -- you could choose 20 instead of 13 or any -- number you felt like > 13. begin Set(1, "Hello"); Set(2, ", I'm"); Set(3, " the function"); Bar := my_fun(Foo); -- you didn't say what my_fun returned. ... alternatively: with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; ... type My_Array is array (Integer range <>) of Unbounded_String; Foo: My_Array(1..3); begin My_Array(1) := To_Unbounded_String("Hello"); My_Array(2) := To_Unbounded_String(", I'm"); My_Array(3) := To_Unbounded_String(" the function"); Bar := my_fun(Foo); ... This is not a normal Ada idiom, but it can be done. The normal Ada idiom would be: Bar := my_fun("Hello" & ", I'm" & " the function"); That way you can declare my_fun to take a single string parameter, and use catenation (&) to put the pieces together. The pieces you are putting together can be string literals, character literals, String and Character variables or constants, and functions returning Strings. In fact, you will often see: Ada.Text_IO.Put_Line(" X is " & Integer'Image(X) & '.' ); or something similar. ------------------------------------------------------------------------- package Ada_Strings_Bounded_Array is type Bounded_Array(Size, Max: Natural) is private; procedure Set(B: in out Bounded_Array; Row: in Positive; To: in String); procedure Append(B: in out Bounded_Array; Row: in Positive; Add: in String); function Get(From: Bounded_Array; Row: Positive) return String; function Get_Length(From: Bounded_Array; Row: Positive) return Natural; private type Element_Array is array (Natural range <>, Natural range <>) of Character; type Length_Array is array(Natural range <>) of Natural; type Bounded_Array(Size, Max: Natural) is record Lengths: Length_Array(1..Size) := (others => 0); Contents: Element_Array(1..Size, 1..Max); end record; end Ada_Strings_Bounded_Array; ---------------------------------------------------------------------- package body Ada_Strings_Bounded_Array is procedure Set(B: in out Bounded_Array; Row: in Positive; To: in String) is Temp: String(1..To'Length) := To; -- insure lower bound is 1. begin if To'Length > B.Max then raise Constraint_Error; end if; B.Lengths(Row) := Temp'Last; -- will raise C_E if Row out of bounds. for I in Temp'Range loop B.Contents(Row,I) := Temp(I); end loop; end Set; procedure Append(B: in out Bounded_Array; Row: in Positive; Add: in String) is Temp: String(B.Lengths(Row)+ 1..B.Lengths(Row)+Add'Length) := Add; begin if Temp'Last > B.Max then raise Constraint_Error; end if; B.Lengths(Row) := Temp'Last; for I in Temp'Range loop B.Contents(Row,I) := Temp(I); end loop; end Append; function Get(From: Bounded_Array; Row: Positive) return String is Temp: String(1..From.Lengths(Row)); begin for I in Temp'Range loop Temp(I) := From.Contents(Row,I); end loop; return Temp; end Get; function Get_Length(From: Bounded_Array; Row: Positive) return Natural is begin return From.Lengths(Row); end Get_Length; pragma Inline(Set, Append, Get, Get_Length); end Ada_Strings_Bounded_Array; ------------------------------------------------------------------------- with Ada.Text_IO; use Ada.Text_IO; with Ada_Strings_Bounded_Array; use Ada_Strings_Bounded_Array; procedure Bounded_Array_Test is BA1: Bounded_Array(5, 30); BA2: Bounded_Array(2, 10); begin Set(BA1,1, "Robert I. Eachus"); Set(BA1,2, "Mortimer Q. Snerd"); Set(BA2,1, "foo"); Append(BA2,1, "bar"); Put_Line(Get(BA1,1)); Put_Line(Get(BA1,2)); Put_Line(Get(BA2,1)); if Get_Length(BA1,1) /= 16 then Put_Line("Oops! BA1,1"); end if; if Get_Length(BA2,1) /= 6 then Put_Line("Oops! BA2,1"); end if; if Get_Length(BA1,3) /= 0 then Put_Line("Oops! BA1,3"); end if; end Bounded_Array_Test; -- Robert I. Eachus "Quality is the Buddha. Quality is scientific reality. Quality is the goal of Art. It remains to work these concepts into a practical, down-to-earth context, and for this there is nothing more practical or down-to-earth than what I have been talking about all along...the repair of an old motorcycle." -- from Zen and the Art of Motorcycle Maintenance by Robert Pirsig ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: array of strings in a function 2003-10-15 2:55 ` Robert I. Eachus @ 2003-10-15 3:29 ` Jeff C, 0 siblings, 0 replies; 22+ messages in thread From: Jeff C, @ 2003-10-15 3:29 UTC (permalink / raw) [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #1: Type: text/plain, Size: 2081 bytes --] "Robert I. Eachus" <rieachus@comcast.net> wrote in message news:3F8CB712.2070808@comcast.net... > Antonio Mart�nez wrote: > > > I'm trying to pass to a function an argument. The argument is an > > array range <> of Strings (unbounded array). > > > number of string literals is unknown by the function. And the > > length of every string is unknown as well. > > > How do I work with unbound strings? > > You can create an array of Unbounded_String (found in > Ada.Strings.Unbounded). Or you can use the package below. Note that in > either case, you are going to have to create an array object, put the > strings in it, and then pass that to the array. With the package below > your example above: > Hmm.. Robert, I am not sure why you would have to create the array and then put the strings in it then pass the array (ok, I agree that is what is really going to happen...but you can hide it) with Ada.Strings.Unbounded; with Text_IO; procedure AnotherWay is function "-"(Item : in String) return Ada.Strings.Unbounded.Unbounded_String renames Ada.Strings.Unbounded.To_Unbounded_String; function "-"(Item : in Ada.Strings.Unbounded.Unbounded_String) return String renames Ada.Strings.Unbounded.To_String; type Unbounded_String_Array is array (Integer range <>) of Ada.Strings.Unbounded.Unbounded_String; procedure Something (Data : in Unbounded_String_Array) is begin for I in Data'range loop Text_IO.Put_Line(-Data(I)); end loop; end Something; begin Something((-"Hello", -", I'm", -" the function")); end AnotherWay; Now, having said and done this....I agree with Robert that this is not a normal Ada idiom so the original poster should really think about whether or not you want to do this. While the code I provided above will actually work, it is really a bad idea so if you can look at your problem space in a different manner, I would really recommend against doing this. Also one more note, the original post talked about writing a function to do something but the example (in the original post) was actually a procedure. ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: array of strings in a function 2003-10-14 20:54 array of strings in a function Antonio Martínez 2003-10-15 2:55 ` Robert I. Eachus @ 2003-10-15 3:08 ` Jeffrey Carter 2003-10-16 6:40 ` tmoran 2003-10-15 11:49 ` Antonio Martínez Álvarez 2 siblings, 1 reply; 22+ messages in thread From: Jeffrey Carter @ 2003-10-15 3:08 UTC (permalink / raw) Antonio Martï¿œnez wrote: > I'm trying to pass to a function an argument. The argument is an > array range <> of Strings (unbounded array). > > For example: > > my_fun("Hello", ", I'm", " the function"); This looks like a procedure, not a function. > number of string literals is unknown by the function. And the > length of every string is unknown as well. > > It works if I choose a fixed length of the string, and every string > is exactly the length I have forced. > > So, if I fixed 4, it works for me: > my_fun("only", "four", "lette", "rs ", "are ", "allo", "ed "); You can't have a subprogram with an unknown number of parameters, which is what you've been trying to write. > How do I work with unbound strings? > > I want something like this: > > type Miarray is array (Positive range <>) of string; > > but it doen't compile !!! Of course not. String is an indefinite type, and the components of an array type must be definite. You say you want unbounded strings, so use unbounded strings: use Ada.Strings.Unbounded; type Mine is array (Positive range <>) of Unbounded_String; Then you can write procedure Proc (Arg : in Mine); and call it Proc (Arg => (To_Unbounded_String ("Hello") , To_Unbounded_String (", I am"), To_Unbounded_String (" Ada!") ); -- Jeff Carter "Death awaits you all, with nasty, big, pointy teeth!" Monty Python & the Holy Grail 20 ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: array of strings in a function 2003-10-15 3:08 ` Jeffrey Carter @ 2003-10-16 6:40 ` tmoran 2003-10-16 9:31 ` Craig Carey 2003-10-16 17:58 ` Jeffrey Carter 0 siblings, 2 replies; 22+ messages in thread From: tmoran @ 2003-10-16 6:40 UTC (permalink / raw) > > my_fun("only", "four", "lette", "rs ", "are ", "allo", "ed "); > > You can't have a subprogram with an unknown number of parameters, which > is what you've been trying to write. But you can certainly have a set of subprograms with the same name but differing number of parameters: procedure my_fun(s1 : in string) is ... procedure my_fun(s1,s2 : in string) is ... procedure my_fun(s1,s2,s3 : in string) is ... procedure my_fun(s1,s2,s3,s4 : in string) is ... or you could use default values procedure my_fun(s1 : string; -- require at least one parameter s2 : string := ""; s3 : string := ""; s4 : string := "") is .. ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: array of strings in a function 2003-10-16 6:40 ` tmoran @ 2003-10-16 9:31 ` Craig Carey 2003-10-16 18:13 ` Craig Carey 2003-10-16 17:58 ` Jeffrey Carter 1 sibling, 1 reply; 22+ messages in thread From: Craig Carey @ 2003-10-16 9:31 UTC (permalink / raw) Functions with varying numbers of arguments are handled by Ada 95: construct an array of pointers at the place the procedure is called: ----- with Text_IO; with Ada.Unchecked_Deallocation; procedure Main is type String_Ptr is access all String; type SPA is array (Positive range <>) of String_Ptr; procedure Deallocate is new Ada.Unchecked_Deallocation ( Object => String, Name => String_Ptr); function "+" (X : String) return String_Ptr is begin return new String'(X); end "+"; procedure Varargs (U : SPA) is Tmp : String_Ptr; begin Text_IO.Put ("Got : "); for K in U'Range loop Text_IO.Put ("""" & String (U (K).all) & """"); if K /= U'Last then Text_IO.Put (", "); end if; Tmp := U (K); Deallocate (Tmp); -- No memory leak end loop; Text_IO.Put_Line ("."); end Varargs; G : String := "Efgh"; begin Varargs (SPA'(1 => +"Abc", 2 => +G, 3 => +"Last")); end Main ----- The output: | Got : "Abc", "Efgh", "Last". Syntax errors are a problm when the heap is not used (a GNAT pointer to a string is 64 bits and twice the size of a pointer to a record). On Thu, 16 Oct 2003 06:40:26 GMT, tmoran@acm.org wrote: ... > But you can certainly have a set of subprograms with the same name >but differing number of parameters: ... At Wed, 15 Oct 2003 13:49:42 +0200, Antonio Mart�nez wrote: Subject: Re: array of strings in a function [from comp.lang.ada-@-ada-france.org ] >What I want to do is a procedure (sorry, not a function) to do something >like this: > >my_AND("Entrada_1", "P2", "Output"); > >and with this argument, this function have to write this: > > >entity my_AND is port( > Entrada_1 : in std_logic; > P2 : in std_logic; > Output : out std:logic; >); > >(This is VHDL code, very similar to Ada95). > > In general, I don't know the number of string arguments. ... Is that a parser project?. Adagoop and Ayacc are options: ftp://ftp.usafa.af.mil/pub/dfcs/carlisle/usafa/adagoop/index.html http://www.mysunrise.ch/users/gdm/gsoft.htm -- Craig Carey ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: array of strings in a function 2003-10-16 9:31 ` Craig Carey @ 2003-10-16 18:13 ` Craig Carey 2003-10-16 21:44 ` Marius Amado Alves 0 siblings, 1 reply; 22+ messages in thread From: Craig Carey @ 2003-10-16 18:13 UTC (permalink / raw) On Thu, 16 Oct 2003 22:31:23 +1300, Craig Carey <research@ijs.co.nz> wrote: >Functions with varying numbers of arguments are handled by Ada 95: Here a package that allows an array of pointers to Ada 95 Strings, to be constructed and read, with no use of the heap. The pointers now point to the first characters of the Strings. --------- with Ada.Text_IO, Ada.Unchecked_Conversion, System; -- pragma Style_Checks ("3abcefhiklM79noprst"); procedure Main is package Varargs is type Char_Const_Ptr is access constant Character; type R_Rec is record Len : Natural; Char1 : Char_Const_Ptr; end record; type SPA is array (Positive range <>) of R_Rec; function "+" (S : String) return R_Rec; function Value (R : R_Rec) return String; end Varargs; package body Varargs is Nil : aliased Character; function Addr_To_Char_Ptr is new Ada.Unchecked_Conversion ( Source => System.Address, Target => Char_Const_Ptr); function "+" (S : String) return R_Rec is begin if S = "" then return R_Rec'(Len => 0, Char1 => Nil'Access); else return R_Rec'(Len => S'Length, Char1 => Addr_To_Char_Ptr (S (1)'Address)); end if; end "+"; function Value (R : R_Rec) return String is Overwrite : String (1 .. 100); -- <- Has no effect begin if R.Len <= 0 then return ""; end if; declare subtype String_1 is String (1 .. R.Len); type String_1_Ptr is access String_1; function To_S1_Ptr is new Ada.Unchecked_Conversion ( Source => Char_Const_Ptr, -- 32 bits Target => String_1_Ptr); begin return To_S1_Ptr (R.Char1).all; end; end Value; end Varargs; use Varargs; procedure Demo (U : SPA) is package Io renames Ada.Text_IO; begin Io.Put ("Got : "); for K in U'Range loop Io.Put ('"' & Value (U (K)) & '"'); if K /= U'Last then Io.Put (", "); end if; end loop; Io.Put_Line ("."); end Demo; G : String := "00275"; begin Demo ((1 => +"PQR", 2 => +G, 3 => +"")); end Main; --------- The output produced in GNAT 3.15 and ObjectAda 7.2.2, shows that the pointers to the strings were packaged and unpackaged correctly: | Got : "PQR", "00275", "". Some of the other solutions seem worse. On Thu, 16 Oct 2003 14:30:51 GMT, "Robert I. Eachus" wrote: ... >Of course, this would mean that users couldn't have "+" in their name >strings. >On Thu, 16 Oct 2003 06:40:26 GMT, tmoran@acm.org wrote: >... >> But you can certainly have a set of subprograms with the same name ... > > > >At Wed, 15 Oct 2003 13:49:42 +0200, Antonio Mart�nez wrote: > Subject: Re: array of strings in a function > [from comp.lang.ada-@-ada-france.org ] > >>What I want to do is a procedure (sorry, not a function) to do something >>like this: >> >>my_AND("Entrada_1", "P2", "Output"); ... >> In general, I don't know the number of string arguments. ... -- Craig Carey ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: array of strings in a function 2003-10-16 18:13 ` Craig Carey @ 2003-10-16 21:44 ` Marius Amado Alves 2003-10-17 19:48 ` Craig Carey 0 siblings, 1 reply; 22+ messages in thread From: Marius Amado Alves @ 2003-10-16 21:44 UTC (permalink / raw) To: comp.lang.ada Craig Carey wrote: "Some of the other solutions seem worse." Your array solution is probably the most "Adaist". But I liked Robert Eachus's. I wrote a variant which allows a list of size 1 (something Robert's doesn't), e.g. Show (+ "one"); Show (+ "one" + "two"); Show (+ "one" + "two" + "three"); Full source below. Vararg_Test outputs, as expected: 1=>one 1=>one 2=>two 1=>one 2=>two 3=>three (Too much free time in our hands uh? :-) with Vararg; use Vararg; with Ada.Text_IO; procedure Vararg_Test is L : List; procedure Show (L : List) is use Ada.Text_IO; begin for I in 1 .. Length (L) loop Put_Line (Integer'Image (I) & "=>" & Get (L, I)); end loop; New_Line; end; begin Show (+ "one"); Show (+ "one" + "two"); Show (+ "one" + "two" + "three"); end; with Ada.Strings.Unbounded; package Vararg is type List is private; function Length (L : List) return Natural; function Get (L : List; I : Positive) return String; function "+" (R : String) return List; function "+" (L : List; R : String) return List; private type Store is array (1 ..1000) of Ada.Strings.Unbounded.Unbounded_String; type List is record S : Store; N : Natural range 0 .. Store'Last := 0; end record; end; package body Vararg is function Length (L : List) return Natural is begin return L.N; end; use Ada.Strings.Unbounded; function Get (L : List; I : Positive) return String is begin return To_String (L.S (I)); end; function "+" (R : String) return List is Y : List; begin Y.S (1) := To_Unbounded_String (R); Y.N := 1; return Y; end; function "+" (L : List; R : String) return List is Y : List; begin Y.S (1 .. Length (L)) := L.S (1 .. Length (L)); Y.S (Length (L) + 1) := To_Unbounded_String (R); Y.N := Length (L) + 1; return Y; end; end; ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: array of strings in a function 2003-10-16 21:44 ` Marius Amado Alves @ 2003-10-17 19:48 ` Craig Carey 2003-10-18 10:05 ` Marius Amado Alves 0 siblings, 1 reply; 22+ messages in thread From: Craig Carey @ 2003-10-17 19:48 UTC (permalink / raw) On Thu, 16 Oct 2003 21:44:16 +0000, Marius Amado Alves <amado.alves@netcabo.pt> wrote: ... >I wrote a variant which allows a list of size 1 (something >Robert's doesn't), e.g. ... >with Ada.Strings.Unbounded; ... I timed some Ada 95 Strings packages. Ada 95 vendors are guided by the design of Ada and then their customers get faster code from the Internet. Here are the results of the test. SP Speed/Hz = 171560 1/12.5 : my no-strings array of pointers scheme SV Speed/Hz = 13760 1 : MAA with my Striunli strings MH Speed/Hz = 7750 1.77 : MAA with the Charles Container U. Strs SU Speed/Hz = 5880 2.3 : MAA with Ada 95's Unbounded Strings HR Speed/Hz = 1560 8.8 : MAA with the Adalog strings of Mr Rosen SB Speed/Hz = 1130 12 : MAA with Ada 95's Bounded Strings. "MAA" means the Ada code of the last message except that the max length for bounded strings is 4096 (which pulls down the ranking of Mr Rosen's Adalog strings package. Also the array of strings had 6 string components and not 1000 (that does not apply to SP). Bounded strings packages get slow fast as the max size increases. To change the max length from 4096 to 255 bytes, increased the speed of HR and SB to about 31500 Hz. In both cases the real data is 3 to 6 bytes long. The line of code being timed in loops, was like this: AV_Show (+"one" + "two" + "three" + "four" + "five" + "six"); (For the Charles (MH) test, pointer swapping was used. A function "in" mode parameter was changed using an unchecked conversion on an X'Address value.) For SB, Move and the Assign procedure, and for Striunli and Charles, the ":=" operator was properly avoided. More realistic tests can make GNAT's Unbounded Strings rank worse for the alternative package could be swapping pointers a lot. Another speed up for assigning is to have strings point to each other; and the package makes a minor attempt to catch some instances where the target unexpectedly changed. though it is supposed to be constant. It sounds like it could be a lot faster and it is up to the user to prove the correctness of the program. The strings package doesn't check fully. Craig Carey ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: array of strings in a function 2003-10-17 19:48 ` Craig Carey @ 2003-10-18 10:05 ` Marius Amado Alves 2003-10-18 20:05 ` Craig Carey 0 siblings, 1 reply; 22+ messages in thread From: Marius Amado Alves @ 2003-10-18 10:05 UTC (permalink / raw) To: comp.lang.ada On Sat, 2003-10-18 at 08:48, Craig Carey wrote: > I timed some Ada 95 Strings packages. Ada 95 vendors are guided by the > design of Ada and then their customers get faster code from the > Internet. > > Here are the results of the test. > SP Speed/Hz = 171560 1/12.5 : my no-strings array of pointers scheme > SV Speed/Hz = 13760 1 : MAA with my Striunli strings ... Nice work! Could you explain the speed units tho? ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: array of strings in a function 2003-10-18 10:05 ` Marius Amado Alves @ 2003-10-18 20:05 ` Craig Carey 2003-10-30 9:42 ` Craig Carey 0 siblings, 1 reply; 22+ messages in thread From: Craig Carey @ 2003-10-18 20:05 UTC (permalink / raw) On Sat, 18 Oct 2003 10:05:30 +0000, Marius Amado Alves <amado.alves@netcabo.pt> wrote: >On Sat, 2003-10-18 at 08:48, Craig Carey wrote: >> I timed some Ada 95 Strings packages. Ada 95 vendors are guided by the >> design of Ada and then their customers get faster code from the >> Internet. >> >> Here are the results of the test. >> SP Speed/Hz = 171560 1/12.5 : my no-strings array of pointers scheme >> SV Speed/Hz = 13760 1 : MAA with my Striunli strings >... > >Nice work! Could you explain the speed units tho? That 13,760 is the number of loop iterations divided by the number of seconds. Timing was done in a 900 MHz Windows 200x PC running -O2 Gnat 3.15p, and the loop contained just this line: AV_Show (+"one" + "two" + "three" + "four" + "five" + "six"); The numbers record that your solution is 29 times slower than that solution I e-mailed that had an array aggregate of records containing a length and a pointer to the 1st character of the string. (29 approx equals "12.5" times "2.3".) So far only one Ada free strings package mentioned here is designed to be fastest. Then when tested it is found to be fastest. I can't comment on nearly invisble compilers such as the 1.1MSLOC IBM Ada compiler. Here are the URLs of the strings packages that were being promoted at comp.lang.ada: [1] My Striunli (was "Seafood") package: http://www.ijs.co.nz/code/ [2] Adalog strings package of Mr Rosen: http://www.adalog.fr/compo2.htm [3] The Charles Containers" routines of Mr Heaney http://home.earthlink.net/~matthewjheaney/charles/index.html Here is the code with the timed loops: http://www.ijs.co.nz/code/tmp-comp.lang,ada-18-oct-2003-string-speed [continued.] -test-program.ada ----- Can someone tell us if IBM is promoting its compiler ?. Hopefully the ARG will stone cold deny IBM a right to exercise a voting power at ARG decision making meetings with the reason being that the company public claims to an interest in Ada is that it is the first to make a public show of losing a 1.1E6 SLOC compiler. The SLOC size is mentioned by Mr P. Leroy of IBM (who votes at ARG meetings), here at an Ada-Comment message: http://www.ada-auth.org/cgi-bin/cvsweb.cgi/AIs/AI-00286.TXT Pehaps ACT would rush to disagree but I suppose they should have a greater influence in Ada's future. For the whole year I was expecting some newsletter from IBM conceding that they own an Ada compiler but I got nothing. One of the Rational staff seemed to try to get that to happen. Incredibly nothing on Ada at the website. ------------------------------------------------------------------------ At 2003-10-16 09:46 -0400 Thursday, Edge Subscriber wrote: > >Dear Rational Edge Subscriber, > >The October 2003 issue of our ezine, from IBM Rational software, >is ready for you at http://www.therationaledge.com > >This month, we focus on modeling and use cases -- especially for large > systems, integration projects, and systems engineering efforts. > >And please take our READER SURVEY! We want to know more about you and > your software development issues, in order to keep valuable content > coming your way. > >Sincerely, > >Mike Perrow >Editor-in-Chief >The Rational Edge ------------------------------------------------------------------------ I have not figured out the name of the city that IBM is making those decisions in. Craig Carey Mailing lists: http://www.ijs.co.nz/ada_95.htm ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: array of strings in a function 2003-10-18 20:05 ` Craig Carey @ 2003-10-30 9:42 ` Craig Carey 0 siblings, 0 replies; 22+ messages in thread From: Craig Carey @ 2003-10-30 9:42 UTC (permalink / raw) This message corrects unfortunate comments in my last message. Mr Leroy stated this in a private e-mail to me: > Not only do I vote at these meetings, but I happen to chair and organize > them, to choose the agenda, and to propose the member list; so it would > be curious to be denied a voting power. At any rate, the ARG has no > right whatsoever to deny voting power to anyone. Only WG9 can do this, > by selecting the membership of the ARG. of 27-Oct-2003. ---------------------- From the new APIWG mailing list: >Date: Wed, 8 Oct 2003 12:47:13 -0400 >Sender: ACM Ada Application Programming Interface Working Group List > <sigada-apiwg@acm.org> >From: "James W. Moore" <***@mitre.org> >Subject: Re: APIWG Inquiries ... >Now, it is possible that you might disagree with WG9 on the respective value of >stability versus change. If so, it would be important for you to participate in >the process by which your particular nation takes positions on these issues, so >that your opinion can be represented in the work of WG9. Most nations have >relatively open processes by which you might participate. In the case of the US >for example, a Technical Advisory Group (TAG) administered by the IEEE develops >US positions and selects US delegations to WG9 meetings; the US TAG is open to >membership by any US-domiciled organization. Other nations have similar >processes. ... >Convener, ISO/IEC JTC1/SC22/WG9 http://www.sigada.org/wg/apiwg/ | ADA APPLICATION PROGRAMMING INTERFACES (API) WORKING GROUP (APIWG) | | Stimulates member interactions with development efforts for Ada | Application Programming Interfaces (APIs), and may develop and | disseminate a general process for more effective approaches for | identifying and developing needed APIs. | | APIWG's mission is: | To identify and disseminate issues and recommendations for the | development and maintenance of Ada APIs. ... (APIWG has subgroups on XML, CGI) --------- ISO JTC1/SC22/WG9 website: http://std.dkuug.dk/JTC1/SC22/WG9/organize.htm#wg9 >ISO/IEC JTC1/SC22/WG9 > >In turn, SC22 subdivides its scope of work among several Working Groups. >WG9 is the one given responsibility for "development of ISO standards >for programming language Ada." WG9's projects must be approved by SC22 >and JTC1. The convener of WG9 is Jim Moore and the webmaster is Clyde >Roby. The position of secretary is filled by volunteers, most recently >by Clyde Roby. ... >ISO/IEC JTC1/SC22/WG9's Ada Rapporteur Group (ARG) > >Chair: Pascal Leroy, [IBM Rational, St Quentin (NE of Paris), France] >Duties: Language interpretations of Ada 95 comments and issues > >Minutes of all ARG meetings are available <http://www.ada-auth.org/> ---------------------- Here is the IBM webpage on the Ada 95 compiler of Rational: http://www-3.ibm.com/software/awdtools/developer/ada/ I quit the DeveloperWorks Java newsletter. Actually it suggests that Java is a great language. http://www-106.ibm.com/developerworks/forums/dw_thread.jsp?forum=176&thread=22447&cat=10 | JVM hangs after 2-3 days | Posted by: gsala, 2003 Aug. 28 03:04 PM | | After working 2-3 days , the JVM stops responding. | | Even kill -3 is not generating a Full thread dump. | | J2RE 1.3.1 IBM AIX build ca131-20030329 | (latest available for AIX) | | Additional info: | | I realized that one of the threads is consuming a lot of CPU | | I have the ps output with thread list, but I don't know how to map the | ps output thread numbers (same that pprof ) to a full thread dump | thread numbers . No one replied to gsala. Comment: An IBM JVM is both unnecessary and it might not last for more than 2-3 days and if it was a bug in user code then the kill -3 diagnostic would report that (unless occurring after the 520KB truncate point). --- There might be a PDF criticising Java later: http://www.acm.org/sigada/conf/sigada2003/ Sigada Dec 2003 "Ada and Real-Time Java: Cooperation, Competition, or Cohabitation? [presented by Brosgol of] Ada Core Technologies" 4 PDFs carefully comparing Java with Ada 95: ftp://ftp.cs.nyu.edu/pub/gnat/jgnat/papers/ Craig Carey ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: array of strings in a function 2003-10-16 6:40 ` tmoran 2003-10-16 9:31 ` Craig Carey @ 2003-10-16 17:58 ` Jeffrey Carter 2003-10-16 20:00 ` tmoran 1 sibling, 1 reply; 22+ messages in thread From: Jeffrey Carter @ 2003-10-16 17:58 UTC (permalink / raw) tmoran@acm.org wrote: >>You can't have a subprogram with an unknown number of parameters, which >>is what you've been trying to write. > > But you can certainly have a set of subprograms with the same name > but differing number of parameters: > procedure my_fun(s1 : in string) is ... > procedure my_fun(s1,s2 : in string) is ... > procedure my_fun(s1,s2,s3 : in string) is ... > procedure my_fun(s1,s2,s3,s4 : in string) is ... > or you could use default values > procedure my_fun(s1 : string; -- require at least one parameter > s2 : string := ""; > s3 : string := ""; > s4 : string := "") is .. Certainly. But to handle an arbitrary number of parameters, you have to write an arbitrary number of something (subprograms or parameters with defaults), which is impossible. An unconstrained array type allows you to handle an unbounded number of items with a single parameter (unbounded in the same sense as Unbounded_String). -- Jeff Carter "Perfidious English mouse-dropping hoarders." Monty Python & the Holy Grail 10 ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: array of strings in a function 2003-10-16 17:58 ` Jeffrey Carter @ 2003-10-16 20:00 ` tmoran 2003-10-17 0:51 ` Jeffrey Carter 0 siblings, 1 reply; 22+ messages in thread From: tmoran @ 2003-10-16 20:00 UTC (permalink / raw) >Certainly. But to handle an arbitrary number of parameters, you have to I think you mean "large" rather than "arbitrary". The latter, of course, is impossible using any finite technique. So the relevant question is how big "large" must be, and whether that number of procedures is a less or more desirable implementation than the various other techniques proposed. ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: array of strings in a function 2003-10-16 20:00 ` tmoran @ 2003-10-17 0:51 ` Jeffrey Carter 0 siblings, 0 replies; 22+ messages in thread From: Jeffrey Carter @ 2003-10-17 0:51 UTC (permalink / raw) tmoran@acm.org wrote: >>Certainly. But to handle an arbitrary number of parameters, you have to > > I think you mean "large" rather than "arbitrary". The latter, of > course, is impossible using any finite technique. So the relevant > question is how big "large" must be, and whether that number of > procedures is a less or more desirable implementation than the various > other techniques proposed. No, I mean arbitrary. The OP has not indicated any limits on the number of possible parameters. For this example, there may well be a fairly small upper limit to the number of parameters. Even then, though, modifying the system to increase that limit is harder when using multiple procedures than when using an unbounded array parameter. -- Jeff Carter "Perfidious English mouse-dropping hoarders." Monty Python & the Holy Grail 10 ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: array of strings in a function 2003-10-14 20:54 array of strings in a function Antonio Martínez 2003-10-15 2:55 ` Robert I. Eachus 2003-10-15 3:08 ` Jeffrey Carter @ 2003-10-15 11:49 ` Antonio Martínez Álvarez 2003-10-15 12:29 ` Preben Randhol ` (2 more replies) 2 siblings, 3 replies; 22+ messages in thread From: Antonio Martínez Álvarez @ 2003-10-15 11:49 UTC (permalink / raw) Hello again. I'm the original poster. What I want to do is a procedure (sorry, not a function) to do something like this: my_AND("Entrada_1", "P2", "Output"); and with this argument, this function have to write this: entity my_AND is port( Entrada_1 : in std_logic; P2 : in std_logic; Output : out std:logic; ); (This is VHDL code, very similar to Ada95). In general, I don't know the number of string arguments. An these strings can be any length. I have tried to do this with unbounded... but without any nice results ... Maybe I must use access variables, like in C. I know how to do this in C, but I'm really interested in do this job into Ada95. I'm writting a generator of VHDL (parsing, etc ...). I'll send the answer when it works. But till this moment, and havig read your posts I haven't found the answer. Thank you so much. -- Antonio Martï¿œnez ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: array of strings in a function 2003-10-15 11:49 ` Antonio Martínez Álvarez @ 2003-10-15 12:29 ` Preben Randhol 2003-10-15 14:19 ` Ole-Hjalmar Kristensen 2003-10-16 14:30 ` Robert I. Eachus 2 siblings, 0 replies; 22+ messages in thread From: Preben Randhol @ 2003-10-15 12:29 UTC (permalink / raw) On 2003-10-15, Antonio Mart�nez �lvarez <amartinez@atc.ugr.es> wrote: > Hello again. I'm the original poster. > > What I want to do is a procedure (sorry, not a function) to do something > like this: > > my_AND("Entrada_1", "P2", "Output"); > > and with this argument, this function have to write this: > > entity my_AND is port( > Entrada_1 : in std_logic; > P2 : in std_logic; > Output : out std:logic; > ); > > In general, I don't know the number of string arguments. An these > strings can be any length. I have tried to do this with unbounded... So what you are saying is that it could also be: my_AND("Entrada_1", "P2", "P3", "Output"); which should give: entity my_AND is port( Entrada_1 ���: in std_logic; P2�����: in std_logic; P3�����: in std_logic; Output�: out std:logic; ); or am I misundstanding you? > but without any nice results ... Maybe I must use access variables, > like in C. I know how to do this in C, but I'm really interested in do > this job into Ada95. You shouldn't need to use access variables, but I really don't understand what you are trying to do. > I'm writting a generator of VHDL (parsing, etc ...). I don't know, but is this of interest: http://www.telepath.com/~dennison/Ted/OpenToken/OpenToken.html Preben ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: array of strings in a function 2003-10-15 11:49 ` Antonio Martínez Álvarez 2003-10-15 12:29 ` Preben Randhol @ 2003-10-15 14:19 ` Ole-Hjalmar Kristensen 2003-10-16 14:30 ` Robert I. Eachus 2 siblings, 0 replies; 22+ messages in thread From: Ole-Hjalmar Kristensen @ 2003-10-15 14:19 UTC (permalink / raw) You could have an unconstrained array of Unbounded_String as the parameter to your procedure, like this: with Ada.Text_Io; use Ada.Text_Io; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; procedure U is type U_S_A is array(Integer range <>) of Unbounded_String; procedure Print(S : U_S_A) is begin for I in S'Range loop Put_Line(To_String(S(I))); end loop; end Print; X : U_S_A := (To_Unbounded_String("foo"), To_Unbounded_String("bar")); begin Print(X); end U; >>>>> "AM�" == Antonio Mart�nez �lvarez <amartinez@atc.ugr.es> writes: AM�> Hello again. I'm the original poster. AM�> What I want to do is a procedure (sorry, not a function) to do AM�> something like this: AM�> my_AND("Entrada_1", "P2", "Output"); AM�> and with this argument, this function have to write this: AM�> entity my_AND is port( AM�> Entrada_1 : in std_logic; AM�> P2 : in std_logic; AM�> Output : out std:logic; AM�> ); AM�> (This is VHDL code, very similar to Ada95). AM�> In general, I don't know the number of string arguments. An these AM�> strings can be any length. I have tried to do this with AM�> unbounded... but without any nice results ... AM�> Maybe I must use access variables, like in C. I know how to do this in AM�> C, but I'm really interested in do this job into Ada95. I'm writting a AM�> generator of VHDL (parsing, etc ...). AM�> I'll send the answer when it works. But till this moment, and havig AM�> read your posts I haven't found the answer. AM�> Thank you so much. AM�> -- AM�> Antonio Mart�nez -- This page intentionally left blank ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: array of strings in a function 2003-10-15 11:49 ` Antonio Martínez Álvarez 2003-10-15 12:29 ` Preben Randhol 2003-10-15 14:19 ` Ole-Hjalmar Kristensen @ 2003-10-16 14:30 ` Robert I. Eachus 2003-10-16 17:53 ` Jeffrey Carter 2 siblings, 1 reply; 22+ messages in thread From: Robert I. Eachus @ 2003-10-16 14:30 UTC (permalink / raw) Antonio Martï¿œnez ï¿œlvarez wrote: > Hello again. I'm the original poster. > > What I want to do is a procedure (sorry, not a function) to do something > like this: > > my_AND("Entrada_1", "P2", "Output"); > > and with this argument, this function have to write this: > > entity my_AND is port( > Entrada_1 : in std_logic; > P2 : in std_logic; > Output : out std:logic; > ); > > (This is VHDL code, very similar to Ada95). Now it becomes clear. You need a way to "wrap-up" names passed as strings and unwrap them into the original strings inside the procedure. The idea of declaring a procedure with a lot of String parameters all with default values denoting that the parameter is not used can work. But it is conceptually ugly. A better way is to define a type: type Parameter_List is private; the operations to create a parameter list: function "+"(Left, Right: String) return Parameter_List; function "+"(Left: Parameter_List; Right: String) return Parameter_List; and the operations to access the contents of objects of the type: function Length(P: Parameter_List) return Integer; function Contents(P: Parameter_List; Row: Integer) return String; Now any of the techniques suggested for implementing the Parameter_List type will work. Let me, in case it isn't obvious say how you should use the ADT: procedure my_AND(P: Parameter_List); begin my_AND("Entrada_1" + "P2" + "Output"); This call will create Parameter_List with three entries that can be "unwrapped" inside my_AND. So how to implement the ADT? You could make Parameter_List an array of Unbounded_String. Or you could choose a String with markers: type Parameter_List is String; function "+"(Left, Right: String) return Parameter_List is Temp: String(1..Left'Length) := Left -- slide Left if necessary; begin return Temp & '+' & Right; end "+"; function "+"(Left: Parameter_List; Right: String) return Parameter_List; begin return Left & '+' & Right; end "+"; function Length(P: Parameter_List) return Integer is Count: Integer := 0; begin for I in P'Range loop if P(I) = '+' then Count := Count + 1; end loop; return Count; end Length; function Contents(P: Parameter_List; Row: Integer) is First: Integer := P'First; Last: Integer := P'Last; Count: Integer := 0; begin for I in P'Range loop if P(I) = '+' then Count := Count + 1; if Count = Row - 1 then First := I+1; elsif Count = Row then Last := I-1; return P(First..Last); end if; end if; end loop; if Count = Row - 1 then return P(First..Last); -- last entry not followed by "+" else raise Constraint_Error; -- Row number incorrect end if; end Contents; Of course, this would mean that users couldn't have "+" in their name strings. So you might want to use a marker such as Ada.Characters.Latin_1.Reserved_128. That can't accidently appear in a string literal. Or Ada.Characters.Latin1.No_Break_Space. ;-) -- Robert I. Eachus "Quality is the Buddha. Quality is scientific reality. Quality is the goal of Art. It remains to work these concepts into a practical, down-to-earth context, and for this there is nothing more practical or down-to-earth than what I have been talking about all along...the repair of an old motorcycle." -- from Zen and the Art of Motorcycle Maintenance by Robert Pirsig ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: array of strings in a function 2003-10-16 14:30 ` Robert I. Eachus @ 2003-10-16 17:53 ` Jeffrey Carter 2003-10-17 0:48 ` Robert I. Eachus 0 siblings, 1 reply; 22+ messages in thread From: Jeffrey Carter @ 2003-10-16 17:53 UTC (permalink / raw) Robert I. Eachus wrote: This is good. We've all been dealing with the implementation, and you're talking about the abstraction, which is what was missing. However, we should inspect your proposal. > type Parameter_List is private; > > the operations to create a parameter list: > > function "+"(Left, Right: String) return Parameter_List; > function "+"(Left: Parameter_List; Right: String) return Parameter_List; > > and the operations to access the contents of objects of the type: > > function Length(P: Parameter_List) return Integer; > function Contents(P: Parameter_List; Row: Integer) return String; So a negative Length is possible? And Contents (P, -27) is meaningful? I think Length should return Natural, and Row should be Positive. > > Now any of the techniques suggested for implementing the Parameter_List > type will work. Let me, in case it isn't obvious say how you should use > the ADT: > > procedure my_AND(P: Parameter_List); > begin > my_AND("Entrada_1" + "P2" + "Output"); > > This call will create Parameter_List with three entries that can be > "unwrapped" inside my_AND. > > So how to implement the ADT? You could make Parameter_List an array of > Unbounded_String. Or you could choose a String with markers: > > type Parameter_List is String; This is not Ada. And making it "new String" won't work, either, since Parameter_List is definite. So this proposal needs some work. Perhaps "new Unbounded_String" is better. > function "+"(Left, Right: String) return Parameter_List is > Temp: String(1..Left'Length) := Left -- slide Left if necessary; > begin return Temp & '+' & Right; end "+"; This returns a String, not a Parameter_List (assuming you convert Left to String). > > function "+"(Left: Parameter_List; Right: String) return Parameter_List; > begin return Left & '+' & Right; end "+"; "&" (Left : Parameter_List; Right : Character) is undefined. > function Length(P: Parameter_List) return Integer is > Count: Integer := 0; > begin > for I in P'Range loop > if P(I) = '+' then Count := Count + 1; > end loop; > return Count; > end Length; This seems to return Length - 1, since a list with 2 parameters in it will contain one '+'. Since it's not clear what the value of P : Parameter_List; is, it's hard to tell what this should do for an empty list. > function Contents(P: Parameter_List; Row: Integer) is > First: Integer := P'First; > Last: Integer := P'Last; > Count: Integer := 0; > begin > for I in P'Range loop > if P(I) = '+' > then > Count := Count + 1; > if Count = Row - 1 > then First := I+1; > elsif Count = Row > then Last := I-1; > return P(First..Last); > end if; > end if; > end loop; > if Count = Row - 1 > then return P(First..Last); -- last entry not followed by "+" > else raise Constraint_Error; -- Row number incorrect > end if; > end Contents; Something along these lines could work, perhaps using Unbounded_String, but I wanted to point out to to the OP that this won't work as given, and needs some work. -- Jeff Carter "Perfidious English mouse-dropping hoarders." Monty Python & the Holy Grail 10 ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: array of strings in a function 2003-10-16 17:53 ` Jeffrey Carter @ 2003-10-17 0:48 ` Robert I. Eachus 2003-10-17 18:41 ` Jeffrey Carter 0 siblings, 1 reply; 22+ messages in thread From: Robert I. Eachus @ 2003-10-17 0:48 UTC (permalink / raw) Jeffrey Carter wrote: > So a negative Length is possible? And Contents (P, -27) is > meaningful? I think Length should return Natural, and Row should be > Positive. I'll buy that. The functions I supplied would raise Constraint_Error for a negative Row value. But not allowing a negative value is probably better. >> type Parameter_List is String; > > > This is not Ada. And making it "new String" won't work, either, since > Parameter_List is definite. So this proposal needs some work. > Perhaps "new Unbounded_String" is better. Oops! SUBtype Parameter_List is String; Or you can do "type Parameter_List is new String;" but that requires writing a lot of type conversions. > Something along these lines could work, perhaps using > Unbounded_String, but I wanted to point out to to the OP that this > won't work as given, and needs some work. Right, I didn't compile and test it, since I was just describing one way to approach the actual implementation. As I said, if I were doing it "for real" that way, I would probably use Reserved_128 or some such as a marker. -- Robert I. Eachus "Quality is the Buddha. Quality is scientific reality. Quality is the goal of Art. It remains to work these concepts into a practical, down-to-earth context, and for this there is nothing more practical or down-to-earth than what I have been talking about all along...the repair of an old motorcycle." -- from Zen and the Art of Motorcycle Maintenance by Robert Pirsig ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: array of strings in a function 2003-10-17 0:48 ` Robert I. Eachus @ 2003-10-17 18:41 ` Jeffrey Carter 0 siblings, 0 replies; 22+ messages in thread From: Jeffrey Carter @ 2003-10-17 18:41 UTC (permalink / raw) Robert I. Eachus wrote: > Jeffrey Carter wrote: > > >> type Parameter_List is String; > > > > This is not Ada. And making it "new String" won't work, either, since > > Parameter_List is definite. So this proposal needs some work. > > Perhaps "new Unbounded_String" is better. > > Oops! SUBtype Parameter_List is String; > > Or you can do "type Parameter_List is new String;" but that requires > writing a lot of type conversions. No. This is the full type for type Parameter_List is private; so it can't be a subtype. Since a client may write P : Parameter_List; (Parameter_List is a definite type), "new String" won't work either. Perhaps you want type Parameter_List (<>) is private; in which case "new String" is legal, but does require conversions. -- Jeff Carter "We use a large, vibrating egg." Annie Hall 44 ^ permalink raw reply [flat|nested] 22+ messages in thread
end of thread, other threads:[~2003-10-30 9:42 UTC | newest] Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2003-10-14 20:54 array of strings in a function Antonio Martínez 2003-10-15 2:55 ` Robert I. Eachus 2003-10-15 3:29 ` Jeff C, 2003-10-15 3:08 ` Jeffrey Carter 2003-10-16 6:40 ` tmoran 2003-10-16 9:31 ` Craig Carey 2003-10-16 18:13 ` Craig Carey 2003-10-16 21:44 ` Marius Amado Alves 2003-10-17 19:48 ` Craig Carey 2003-10-18 10:05 ` Marius Amado Alves 2003-10-18 20:05 ` Craig Carey 2003-10-30 9:42 ` Craig Carey 2003-10-16 17:58 ` Jeffrey Carter 2003-10-16 20:00 ` tmoran 2003-10-17 0:51 ` Jeffrey Carter 2003-10-15 11:49 ` Antonio Martínez Álvarez 2003-10-15 12:29 ` Preben Randhol 2003-10-15 14:19 ` Ole-Hjalmar Kristensen 2003-10-16 14:30 ` Robert I. Eachus 2003-10-16 17:53 ` Jeffrey Carter 2003-10-17 0:48 ` Robert I. Eachus 2003-10-17 18:41 ` Jeffrey Carter
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox