
-----------------------------------
Zren
Sun Jan 06, 2008 6:21 pm

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.


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:

procedure assignData (object, a, b, c)
[object] . a := a
[object] . b := b
[object] . c := c
end assignData

assignData (thing,1,2,3)


-----------------------------------
Nick
Sun Jan 06, 2008 6:25 pm

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
Sun Jan 06, 2008 6:35 pm

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.

type DataType: 
    record 
        a : int 
    end record
var thing :^DataType
thing->a:=1 

-----------------------------------
Tony
Sun Jan 06, 2008 7:09 pm

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" :lol:

I think your procedure assignData (object, a, b, c) should work

-----------------------------------
Zren
Sun Jan 06, 2008 7:33 pm

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...
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
Sun Jan 06, 2008 7:56 pm

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.

-----------------------------------
Zren
Sun Jan 06, 2008 9:16 pm

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.  :P

-----------------------------------
ericfourfour
Mon Jan 07, 2008 5:12 pm

Re: Assigning to a Record
-----------------------------------
Initialization of records and unions is analogous to initializing arrays. Values are listed in the order in which they appear in the type.

Example:
type Foo :
    record
        i : int
        r : real
        s : string
    end record
    
var foo : Foo := init (42, 1.111, "foo")

-----------------------------------
Zren
Mon Jan 07, 2008 10:39 pm

Re: Assigning to a Record
-----------------------------------


Example:
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.
