* + Operator
@ 1996-12-09 0:00 FREBOURG Fabrice
1996-12-10 0:00 ` Paul Chardon
0 siblings, 1 reply; 5+ messages in thread
From: FREBOURG Fabrice @ 1996-12-09 0:00 UTC (permalink / raw)
Hello,
I'm programming with Ada95 on Solaris 2 and I'm a beginner. I would like some information about using the "+" symbol like a pointer operator for string.
So I've created the following example.
s: string;
.
.
.
procedure new_String(s_ptr:String_Ptr) is
begin
.
.
.
end new_String;
.
.
.
s:="hello";
new_String(+s);
Could you explain me such a mecanism because I don't understand it. Do I need
to import a special librairy. Could tell me which one.
Thank you an advance for your help.
Fabrice (frebourg@cui.unige.ch)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: + Operator
1996-12-09 0:00 + Operator FREBOURG Fabrice
@ 1996-12-10 0:00 ` Paul Chardon
0 siblings, 0 replies; 5+ messages in thread
From: Paul Chardon @ 1996-12-10 0:00 UTC (permalink / raw)
To: frebourg
Hello Fabrice,
Two notes about your short program. String is a unconstrained type and
therefore you can't use it to declare a variable, you must declare a
constrained type built with the string type; secondly you can use the
predefined unary "+" operator with any other type parameter.
Here is a little example that can help you.
procedure Test is
subtype Str20 is String(1..20);
type String_Ptr is access all Str20;
function "+"(S : in Str20) return String_Ptr is
begin
return new Str20'(S);
end "+";
My_Str20 : Str20 := (others => ' ');
A_Str20_Ptr : String_Ptr;
begin
A_Str20_Ptr:= + My_Str20 ;
end Test;
Bye, Paul.
^ permalink raw reply [flat|nested] 5+ messages in thread
* "<" operator
@ 1997-10-07 0:00 dperez
1997-10-07 0:00 ` Matthew Heaney
0 siblings, 1 reply; 5+ messages in thread
From: dperez @ 1997-10-07 0:00 UTC (permalink / raw)
how can I write a recursive Ada Function "<" that does the less-than
comparison on linked lists of characters to do the obvious thing?
Thanks
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: "<" operator
1997-10-07 0:00 "<" operator dperez
@ 1997-10-07 0:00 ` Matthew Heaney
1997-10-09 0:00 ` Mats Weber
0 siblings, 1 reply; 5+ messages in thread
From: Matthew Heaney @ 1997-10-07 0:00 UTC (permalink / raw)
In article <343A7434.36AD@newtimes.com>, dperez <dperez@newtimes.com> wrote:
>how can I write a recursive Ada Function "<" that does the less-than
>comparison on linked lists of characters to do the obvious thing?
function "<"
(L, R : Character_List) return Boolean is
begin
if L = null then
if R = null then
return True;
else
raise <lists are not same length error>;
end if;
elsif R = null then
raise <lists are not same length error>;
else
return L.Item < R.Item and L.Next < R.Next;
end if;
end;
Won't that do it?
The type is
type Character_List_Node;
type Character_List is access Character_List_Node;
type Character_List_Node is
record
Item : Character;
Next : Character_List;
end record;
function "<" (L, R : Character_List) return Boolean;
--------------------------------------------------------------------
Matthew Heaney
Software Development Consultant
<mailto:matthew_heaney@acm.org>
(818) 985-1271
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: "<" operator
1997-10-07 0:00 ` Matthew Heaney
@ 1997-10-09 0:00 ` Mats Weber
0 siblings, 0 replies; 5+ messages in thread
From: Mats Weber @ 1997-10-09 0:00 UTC (permalink / raw)
Assuming the guy wants lexicographic order (and wants the function to work
with lists of different lengths), I think this should be corrected as follows:
> function "<"
> (L, R : Character_List) return Boolean is
> begin
> if L = null then
> if R = null then
> return True;
should be return False; -- because you probably want ("" < "") = False
> else
> raise <lists are not same length error>;
should be return True; -- because "" < anything
> end if;
>
> elsif R = null then
> raise <lists are not same length error>;
should be return False; -- because anything > ""
> else
> return L.Item < R.Item and L.Next < R.Next;
>
> end if;
> end;\x01
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~1997-10-09 0:00 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-12-09 0:00 + Operator FREBOURG Fabrice
1996-12-10 0:00 ` Paul Chardon
-- strict thread matches above, loose matches on Subject: below --
1997-10-07 0:00 "<" operator dperez
1997-10-07 0:00 ` Matthew Heaney
1997-10-09 0:00 ` Mats Weber
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox