Re: Euphoria

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

> There are really only three kinds of variable in Euphoria:
> integers (you know about them)
>    1, 57, 204003, -7.....
> atoms (called reals in Pascal, floats in C, I forget what in Basic)
>    1.99, 3.14159, -66

A side remark: an atom, which has a value of 5, has this value stored as an
integer.
Only when the value is out-of-range, the interpreter will decide to convert the
datatype
internally.

> You do math with these in the usual way, i = i * 4, x = x / 2.....

You can do math without having to worry about the datatype. There is no case
where math
using objects, as well as sequences, integers and atoms, will result in an
error, as long as the
container (where the value is stored) is capable. (objects always are, but if
you are sure you
are using a sequence, you can also use a sequence. If you are sure there are no
objects, nor
sequences in your calculation, you can store the value in an atom, if are sure
the value is
within reach of an integer. Store it in an integer.

If you think this all is too complicated ... just name everything object, and
discard the whole
concept of datatypes.

> coords = { {1,1}, {10,10}, {30,15}, {30,30} }  -- a list of coordinates
> coords += 10 -- move the coordinates to the right and down by  10
> now coords contains: { {11,11}, {20,20}, {40,25}, {40,40} }

Interesting: math between two sequences:
It may only occur when both sequences are of the same length.
This, how tempting, is (unfortunately ?) not allowed ..

coords += {10, 5}

But you could write a function for it ... example:

global function recurse_add (object l, object r)
    -- Note: am using short-circuiting!
    if sequence (l) and sequence (r) and length(l) != length(r) then
        for index = 1 to length(l) do
            l[index] = recurse_add (l[index], r)
        end for
        return l
    else
        return l + r    -- Otherwise Euphoria handles it alright
    end if
end function




Ralf Nieuwenhuijsen

[[ Email ]]
    nieuwen at xs4all.nl
    ralf_n at email.com

[[ I-Seek-You ]]
   UIN: 9389920

[[ The Elevator ]]
    http://www.xs4all.nl/~nieuwen



Download NeoPlanet at http://www.neoplanet.com

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

Search



Quick Links

User menu

Not signed in.

Misc Menu