Assigning to a Record
Author |
Message |
Zren

|
Posted: Sun Jan 06, 2008 6:21 pm Post subject: Assigning to a Record |
|
|
Is there a way to assign values to a variable that is a record like Init for Arrays? I just want to know if there's an easier way then the latter.
code: |
type STRUCTURE :
record
a : int
b : int
c : int
end record
var thing :STRUCTURE
thing := init (1, 2, 3)
% Instead of...
thing.a:=1
thing.b:=2
thing.c:=3
|
If not is there a way to make a procedure to assign the values accordingly for the specified record structure, to immitate init? Like:
code: | procedure assignData (object, a, b, c)
[object] . a := a
[object] . b := b
[object] . c := c
end assignData
assignData (thing,1,2,3)
|
|
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Nick

|
Posted: Sun Jan 06, 2008 6:25 pm Post subject: RE:Assigning to a Record |
|
|
just to point out there are errors in your code such as var thing:STRUCTURE it should be var thing:^STRUCTURE
also when calling an object in Turing we use -> instead of . so in your code it should be more like thing->a |
|
|
|
|
 |
Zren

|
Posted: Sun Jan 06, 2008 6:35 pm Post subject: Re: Assigning to a Record |
|
|
Eh? Pointers. I through in the typeset and structure since it's closer to what I had for my use since it's being used as a datatype. Though I don't quite comprehend the entirety of how pointers are useful. Nor does this work.
code: | type DataType:
record
a : int
end record
var thing :^DataType
thing->a:=1 |
|
|
|
|
|
 |
Tony

|
Posted: Sun Jan 06, 2008 7:09 pm Post subject: RE:Assigning to a Record |
|
|
pointers are for objects, records work fine without them.
I think the confusion came from the fact that you've named your record as an "object"
I think your procedure assignData (object, a, b, c) should work |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
 |
Zren

|
Posted: Sun Jan 06, 2008 7:33 pm Post subject: Re: Assigning to a Record |
|
|
So I take it there's no predefined way then eh.
Sorry I'm used object since this is for Vectors wich leads to Polygones wich leads to Objects...kinda. I ment variable.
But this came out of Init in the help files...
Quote: Initialization of records and unions is analogous to initializing arrays. Values are listed in the order in which they appear in the type. See array, record, and union types.
Wich makes me wonder if there really is a way to use init for records...
Though I'm getting by with assignData (i, a, b, c) where i is the number in a big array so it works for my purpose. ^^ |
|
|
|
|
 |
Tony

|
Posted: Sun Jan 06, 2008 7:56 pm Post subject: RE:Assigning to a Record |
|
|
ah, interesting. Have you tried using init on a record?
Look through the record documentation, maybe they have an example somewhere. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
 |
Zren

|
Posted: Sun Jan 06, 2008 9:16 pm Post subject: Re: Assigning to a Record |
|
|
It doesn't say anything about init in the record help file, let alone an example. Oh well, thanks Tony and momop. Even if momop confused me more than anything else.  |
|
|
|
|
 |
ericfourfour
|
Posted: Mon Jan 07, 2008 5:12 pm Post subject: Re: Assigning to a Record |
|
|
Turing Documentation:init wrote: Initialization of records and unions is analogous to initializing arrays. Values are listed in the order in which they appear in the type.
Example:
Turing: | type Foo :
record
i : int
r : real
s : string
end record
var foo : Foo := init (42, 1.111, "foo") |
|
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Zren

|
Posted: Mon Jan 07, 2008 10:39 pm Post subject: Re: Assigning to a Record |
|
|
ericfourfour @ Mon Jan 07, 2008 5:12 pm wrote:
Example:
Turing: | type Foo :
record
i : int
r : real
s : string
end record
var foo : Foo := init (42, 1.111, "foo") |
Oh I see, so you can only assign values to it when declaring the Data type apparently, no wonder it never worked for me. Thanks ericfourfour. |
|
|
|
|
 |
|
|