Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 How to access a member variable of a record type in a module
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
davidkazuhiro




PostPosted: Wed Sep 23, 2009 11:55 am   Post subject: How to access a member variable of a record type in a module

What is it you are trying to achieve?
My immediate goal is to figure out how to use my "value" record type in my "complex" module.

Ultimately I am trying to write a program which calculates the side lengths and angles of a triangle on the complex plane. If turing has libraries for complex arithmetic which I'm unaware of, please give me a heads up!


What is the problem you are having?
When I try to get x.realPt, I get a "'x' cannot be followed by a '.'" error.


Describe what you have tried to solve this problem
I tried all sorts of minor syntax changes and exporting value.realPt etc. This is my first time using Turing =P


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)


Turing:

/*
 Since I don't think complex exists in turing, we shall a module
 for doing complex arithmetic
 
 The following code was taken from
 Object Oriented Turing Reference Manual Seventh Edition Version 1.0
 by R.C. Holt and Tom West
 ISBN 0-921598-35-1
 http://compsci.ca/holtsoft/OOTRef.pdf
 Chapter 7 : Language Features, p 435
 */

module complex
    export opaque value, constant, add, subtract, modulus

    type value :
        record
            realPt, imagPt : real
        end record

    function constant (realPt, imagPt: real ) : value
        var answer : value
        answer . realPt := realPt
        answer . imagPt := imagPt
        result answer
    end constant

    function add (L, R : value ) : value
        var answer : value
        answer . realPt := L . realPt + R . realPt
        answer . imagPt := L . imagPt + R . imagPt
        result answer
    end add
% end of reused code

    function subtract ( L, R : value ) : value
        var answer : value
        answer . realPt := L . realPt - R . realPt
        answer . imagPt := L . imagPt - R . imagPt
        result answer
    end subtract
   
    function modulus ( cnum : value ) : real
        var answer : real
        answer := sqrt( cnum . realPt ** 2 + cnum . imagPt ** 2 )
        result answer
    end modulus
end complex

put "This program takes 3 complex numbers and calculates the angles and ",
    "side lengths of the triangle they constitute on the complex plane\n"
   
% Get complex numbers from user
var x : complex.value := complex.constant( 1.0, 1.0 )

put x.realPt



Please specify what version of Turing you are using
4.1.1a
Sponsor
Sponsor
Sponsor
sponsor
DemonWasp




PostPosted: Wed Sep 23, 2009 1:56 pm   Post subject: RE:How to access a member variable of a record type in a module

I can't explain why, but removing the "opaque" from your export line resolves the issue. I blame Turing's probably-buggy implementation, because as near as I can tell, your code should work fine as-is.
davidkazuhiro




PostPosted: Wed Sep 23, 2009 3:02 pm   Post subject: RE:How to access a member variable of a record type in a module

weird... you're right. thanks!
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: