* Re: record question
2001-10-26 13:13 record question Alfred Hilscher
@ 2001-10-26 13:33 ` Petter Fryklund
2001-10-26 14:59 ` Ted Dennison
2001-10-26 13:42 ` Claude SIMON
` (2 subsequent siblings)
3 siblings, 1 reply; 8+ messages in thread
From: Petter Fryklund @ 2001-10-26 13:33 UTC (permalink / raw)
I'd try this:
y := (i => 99);
I bet someone else is going to tell why your code is not allowed, but I
don't know.
Alfred Hilscher wrote in message <3BD9618C.D154FE0C@icn.siemens.de>...
>Hi,
>
>assume that I have a record like the one below. I can assign aggregates
>in the case that I have subcomponents, but how do I assign if I don't
>have?
>
>procedure RT is
> type x (i : Integer := 0) is
> record
> case i is
> when 0 => null;
> when 1..10 => s : STRING (1..10);
> when others => null;
> end case;
> end record;
>
> y : x;
>begin
> y := (1, "ABC "); -- this is OK
>
> y := (99); -- but, how do that ?
>
> y.i := 99; -- do not work either, so how assign a value different to
>1..10 ?
>end RT;
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: record question
2001-10-26 13:13 record question Alfred Hilscher
2001-10-26 13:33 ` Petter Fryklund
@ 2001-10-26 13:42 ` Claude SIMON
2001-10-26 15:01 ` Ted Dennison
2001-10-26 21:22 ` Richard Pinkall-Pollei
2001-10-26 23:54 ` Jeffrey Carter
3 siblings, 1 reply; 8+ messages in thread
From: Claude SIMON @ 2001-10-26 13:42 UTC (permalink / raw)
I think
y := (i => 99);
is better : (99) is an integer expression, not an array nor a record
aggregate.
The same problem arise when you want to pass an array of one element, you
must
write (1=> X).
Claude Simon
Alfred Hilscher a �crit :
> Hi,
>
> assume that I have a record like the one below. I can assign aggregates
> in the case that I have subcomponents, but how do I assign if I don't
> have?
>
> procedure RT is
> type x (i : Integer := 0) is
> record
> case i is
> when 0 => null;
> when 1..10 => s : STRING (1..10);
> when others => null;
> end case;
> end record;
>
> y : x;
> begin
> y := (1, "ABC "); -- this is OK
>
> y := (99); -- but, how do that ?
>
> y.i := 99; -- do not work either, so how assign a value different to
> 1..10 ?
> end RT;
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: record question
2001-10-26 13:42 ` Claude SIMON
@ 2001-10-26 15:01 ` Ted Dennison
2001-10-26 15:50 ` Claude SIMON
0 siblings, 1 reply; 8+ messages in thread
From: Ted Dennison @ 2001-10-26 15:01 UTC (permalink / raw)
In article <3BD96844.699A15BC@setra.fr>, Claude SIMON says...
>The same problem arise when you want to pass an array of one element, you
>must
>write (1=> X).
..and for an array of 0 elements (yes, those can exist), it would be (others =>
Whatever) (replace "Whatever" with a placebo expression of the appropriate
type).
---
T.E.D. homepage - http://www.telepath.com/dennison/Ted/TED.html
No trees were killed in the sending of this message.
However a large number of electrons were terribly inconvenienced.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: record question
2001-10-26 15:01 ` Ted Dennison
@ 2001-10-26 15:50 ` Claude SIMON
0 siblings, 0 replies; 8+ messages in thread
From: Claude SIMON @ 2001-10-26 15:50 UTC (permalink / raw)
In general (when it make sense) when I declare an array, I declare a constant of
that array type with
an empty range of any (may be empty) value. That constant is used in place of a 0
elements aggregate.
Claude Simon
Ted Dennison a �crit :
> In article <3BD96844.699A15BC@setra.fr>, Claude SIMON says...
> >The same problem arise when you want to pass an array of one element, you
> >must
> >write (1=> X).
>
> ..and for an array of 0 elements (yes, those can exist), it would be (others =>
> Whatever) (replace "Whatever" with a placebo expression of the appropriate
> type).
>
> ---
> T.E.D. homepage - http://www.telepath.com/dennison/Ted/TED.html
>
> No trees were killed in the sending of this message.
> However a large number of electrons were terribly inconvenienced.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: record question
2001-10-26 13:13 record question Alfred Hilscher
2001-10-26 13:33 ` Petter Fryklund
2001-10-26 13:42 ` Claude SIMON
@ 2001-10-26 21:22 ` Richard Pinkall-Pollei
2001-10-26 23:54 ` Jeffrey Carter
3 siblings, 0 replies; 8+ messages in thread
From: Richard Pinkall-Pollei @ 2001-10-26 21:22 UTC (permalink / raw)
>assume that I have a record like the one below. I can assign aggregates
>in the case that I have subcomponents, but how do I assign if I don't
>have?
>
> [code example moved to end of message for reference]
The record type you are using is "mutable", since it has a default
discriminant. Thus, you can change the discriminant, but only if you
provide a complete record or aggregate in the assignment. Thus, you
would have to use "y := ( i => 99 ) ;" since it assigns a complete
aggregate (since "i" is the only component for this discriminant
value). You cannot use the "y.i" form, since that would technically
only assign a single component, even though the record has only one
component.
I ran your code fragment through the GNAT 3.13p compiler, just to see
if it was smart enough to realize that "y.i" was, in fact, the only
record component. The error message resulting from the "y.i"
assignment states that the left hand of the assignment must be a
variable. I would say that's not the real problem, but I'm not sure
why GNAT flags it this way.
>procedure RT is
> type x (i : Integer := 0) is
> record
> case i is
> when 0 => null;
> when 1..10 => s : STRING (1..10);
> when others => null;
> end case;
> end record;
>
> y : x;
>begin
> y := (1, "ABC "); -- this is OK
>
> y := (99); -- but, how do that ?
>
> y.i := 99; -- do not work either, so how assign a value different to
>1..10 ?
>end RT;
--
______________________________________________________________________________
Posted Via Binaries.net = SPEED+RETENTION+COMPLETION = http://www.binaries.net
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: record question
2001-10-26 13:13 record question Alfred Hilscher
` (2 preceding siblings ...)
2001-10-26 21:22 ` Richard Pinkall-Pollei
@ 2001-10-26 23:54 ` Jeffrey Carter
3 siblings, 0 replies; 8+ messages in thread
From: Jeffrey Carter @ 2001-10-26 23:54 UTC (permalink / raw)
Alfred Hilscher wrote:
>
> procedure RT is
> type x (i : Integer := 0) is
> record
> case i is
> when 0 => null;
> when 1..10 => s : STRING (1..10);
> when others => null;
> end case;
> end record;
>
> y : x;
> begin
> y := (1, "ABC "); -- this is OK
>
> y := (99); -- but, how do that ?
>
> y.i := 99; -- do not work either, so how assign a value different to
> 1..10 ?
> end RT;
(99) is a parenthesized expression, not an aggregate. An aggregate of
one value must use named notation:
(I => 99)
You may only change a discriminant of an unconstrained record variable
by assigning the entire record at once. Since I is a discriminant of
type X, "Y.I := ..." is illegal.
Thus, you must write:
Y := (I => 99);
--
Jeff Carter
"I wave my private parts at your aunties."
Monty Python & the Holy Grail
^ permalink raw reply [flat|nested] 8+ messages in thread