Re: Pointer work around

new topic     » goto parent     » topic index » view thread      » older message » newer message

At 04:14 a.m. 11-01-99 , you wrote:
>it's still not using anything pointer oriented in Euphoria but its a step in
>the right direction.
>

The main problem with pointers in Euphoria is that we can't pass arguments
by reference. The only work around is to make variables globals (ugghh!) or
make it a function.

Example in unchecked C (I'm no C expert):

void square(long* a)
{
        *a *= *a;
}

int main(....)
{
        long x;
        ...
        square(&x);
}

[probably this C code is wrong, but some C guy may fix it, it only shows
the idea]

In Euphoria you have two choices:

A)
        global integer x

        procedure square()
                x = x*x
        end procedure
        ...
        square()

B)
        function square(integer a)
                return a*a
        end function

        integer x
        ...
        x = square(x)

Alternative A is quite un practicable. Alternative B is what we usually do.
The problems get's worst when you're working with sequences, you have to
use (most of the times) a temporary sequence.

What I would like to see in Euphoria:
1) Passing variables by reference
2) Sequence templates

Sequence templates would be like records, and would define the general
"morphology" of a sequence.

Example:

template MySeq
        MySeq = {{integer, sequence},{atom}}
end template

sequence x of MySeq

x = {{0,"Hello"},{1000}}        -- OK
x = {{"Hello",0},{1000}} -- Wrong! Compiler error expected



Regards,
        Daniel   Berstein
        daber at pair.com

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu