Suggested Extension to Euphoria language

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

Hello Jef,

I think that your proposed extension of the Euphoria language is
unnecessary, since what you want can easily be done by a small global
function.

My automagic proposal is:

function extract(sequence from, sequence index)
-- returns indexed elements from a sequence
sequence into
        into = repeat(0, length(index))
        if index[length(index)] > length(from) then     -- test for bad
indexing
                puts(1, "BAD INDEX!\n")
                return 0
        end if
        for magic = 1 to length(into) do        -- or to length(index),
that's the same
                into[magic] = from[index[magic]]
        end for
        return into
end function    -- extract

-- test it
---------------------------------------------------------------------------
------------------------

sequence a, index_seq
object b

a = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100}
index_seq = {3, 5, 7, 6, 9}     -- the order is unimportant

b = extract(a, index_seq)       -- instead of b = a[index_seq]
? b
while get_key() = -1 do
end while
---------------------------------------------------------------------------
------------------------------------

The only problem is maybe somewhat less speed then an inbuild function, but
there are so many things that we probably wanted to have build-in, like for
instance pause(), wait(), input(), prompt(), round() etc. I think that
small functions and procedures you write and then put to use as global in
an include file, can contribute a lot to the use of the language.

This ends my automagic soulution proposal,

Bye,

Ad.

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

Search



Quick Links

User menu

Not signed in.

Misc Menu