Re: Fw: Distance between 2 points

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

On Thu, 1 Oct 1998, Ralf Nieuwenhuijsen wrote:

> And Hawke, I started to talk about sum ()
> Lets try an optimization thread on sum ()
> Here is the beginning function:
>
> function sum (object x)
> atom ret
>     if atom(x)
>         return x
>     elsis not length(x) then
>         return 0
>     end if
>
>     ret = sum (x[1])
>     for index = 2 to length(x) do
>         ret = ret + sum(x[index])
>     end for
>
>     return ret
> end function

Carl goes into overdrive:

function sum(object x)
--function product(object x)

    atom out

    out = 0
--  out = 1
    if atom(x) then
        return x
    elsif length(x) then
        for i = 1 to length(x) do
            out = out + sum(x[i])
--          out = out * product(x[i])
        end for
    end if

    return out
end function

1) Comments show changes for "product()" :)
2) This is best read in a syntax coloured environment ;)

However, that's a generic function.

For 1, 2 and 3d work it's simply (not much error checking though):

function sum(object x) -- x is 1, 2, or 3 in length() [or an atom]
    x = x & {0,0}
    return x[1] + x[2] + x[3]
end function

Happly codifilairingousness,
Carl

--
Carl R White
E-mail...: cyrek- at -bigfoot.com -- Remove the hyphens before mailing. Ta :)
Url......: http://www.bigfoot.com/~cyrek/
"Ykk rnyllaqur rgiokc cea nyemdok ymc giququezka caysgr." - B.Q.Vgesa

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

Search



Quick Links

User menu

Not signed in.

Misc Menu