Project 11>Average--Array result

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Project 11>Average--Array result

kraftwerk1611
Hi

When evaluating an expression containing array like b[j] as a single term, do we expect the result to be an address of memory location or the actual value stored at that location?

thanks.
Reply | Threaded
Open this post in threaded view
|

Re: Project 11>Average--Array result

cadet1620
Administrator
kraftwerk1611 wrote
Hi

When evaluating an expression containing array like b[j] as a single term, do we expect the result to be an address of memory location or the actual value stored at that location?

thanks.
Setting b[j] puts the expression value in word j of array b. It the expression is an object, that value is the object's address.

Reading b[j] returns the value stored in word j of array b. This value will be an address if an object was stored in the array.
var Array b;
var MyClass me;
let b=Array.new(10);

let b[0] = 17;
do Output.printInt(b[0]);       // prints 17

let b[1] = "test";
do Output.printString(b[1]);    // prints "test"
do Output.printInt(b[1]);       // prints address of String object containing "test"

let b[2] = MyClass.new();       // rerurns a new MyClass object and stores it.
let me = b[2]
do me.myMethod();               // applies myMethod() to the object strored in b[2]

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: Project 11>Average--Array result

kraftwerk1611
okay, thanks

I had the situation in mind when you have a term of following type [page 209 of book]  and passing it to a method that compiles  a term.

term: varName '[' expression ']'